forked from ember-fastboot/ember-cli-fastboot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshoebox-test.js
More file actions
88 lines (65 loc) · 2.31 KB
/
shoebox-test.js
File metadata and controls
88 lines (65 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { moduleFor, test } from 'ember-qunit';
import sinon from 'sinon';
let sandbox;
moduleFor('service:fastboot', 'Unit | Service | fastboot | shoebox', {
beforeEach() {
sandbox = sinon.sandbox.create();
},
afterEach() {
sandbox.restore();
}
});
test('retrieve returns value if isFastBoot false and key is cached', function(assert) {
let service = this.subject();
service.set('shoebox.foo', 'bar');
assert.strictEqual(service.get('shoebox').retrieve('foo'), 'bar');
});
test('retrieve returns undefined if isFastBoot false and shoebox is missing', function(assert) {
let service = this.subject();
let stub = sandbox.stub(document, 'querySelector').withArgs('#shoebox-foo');
assert.strictEqual(service.get('shoebox').retrieve('foo'), undefined);
sinon.assert.calledOnce(stub);
});
test('retrieve returns undefined if isFastBoot false and textContent is missing', function(assert) {
let service = this.subject();
let stub = sandbox.stub(document, 'querySelector').withArgs('#shoebox-foo').returns({});
assert.strictEqual(service.get('shoebox').retrieve('foo'), undefined);
sinon.assert.calledOnce(stub);
});
test('retrieve returns value if isFastBoot false and textContent is present', function(assert) {
let service = this.subject();
let stub = sandbox.stub(document, 'querySelector').withArgs('#shoebox-foo').returns({
textContent: '{"foo":"bar"}'
});
assert.deepEqual(service.get('shoebox').retrieve('foo'), {
foo: 'bar'
});
sinon.assert.calledOnce(stub);
});
test('retrieve returns undefined if isFastBoot true and shoebox is missing', function(assert) {
let service = this.subject({
isFastBoot: true,
_fastbootInfo: {}
});
assert.strictEqual(service.get('shoebox').retrieve('foo'), undefined);
});
test('retrieve returns undefined if isFastBoot true and key is missing', function(assert) {
let service = this.subject({
isFastBoot: true,
_fastbootInfo: {
shoebox: {}
}
});
assert.strictEqual(service.get('shoebox').retrieve('foo'), undefined);
});
test('retrieve returns value if isFastBoot true and key is present', function(assert) {
let service = this.subject({
isFastBoot: true,
_fastbootInfo: {
shoebox: {
foo: 'bar'
}
}
});
assert.strictEqual(service.get('shoebox').retrieve('foo'), 'bar');
});