forked from NullVoxPopuli/limber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselection-test.gts
81 lines (65 loc) · 3.2 KB
/
selection-test.gts
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
import { render, select } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { Selection } from 'tutorial/components/selection';
import { setupRenderingTest } from 'tutorial/tests/helpers';
import { MockDocsService, MockRouterService } from '../../helpers/mocks';
module('Integration | Component | selection', function (hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(function () {
this.owner.register('service:docs', MockDocsService);
this.owner.register('service:router', MockRouterService);
});
test('it renders groups and options', async function (assert) {
const docsSvc = this.owner.lookup('service:docs') as unknown as MockDocsService;
docsSvc._setGroupsData([
[
'1-introduction',
['1-basics', '2-adding-data', '3-transforming-data', '4-multiple-transforms'],
],
['2-reactivity', ['1-values', '2-decorated-values', '3-derived-values']],
['3-event-handling', ['1-dom-events']],
]);
await render(<template><Selection /></template>);
assert.dom('select').hasAttribute('name', 'tutorial');
assert.dom('select > optgroup').exists({ count: 3 });
assert.dom('option').exists({ count: 8 });
// Check group labels
assert.dom('optgroup:nth-child(1)').hasAttribute('label', 'Introduction');
assert.dom('optgroup:nth-child(2)').hasAttribute('label', 'Reactivity');
assert.dom('optgroup:nth-child(3)').hasAttribute('label', 'Event Handling');
// Spot check some option values
assert
.dom('optgroup:nth-child(1) option:nth-child(4)')
.hasValue('/1-introduction/4-multiple-transforms');
assert.dom('optgroup:nth-child(1) option:nth-child(4)').hasText('Multiple Transforms');
assert
.dom('optgroup:nth-child(2) option:nth-child(2)')
.hasValue('/2-reactivity/2-decorated-values');
assert.dom('optgroup:nth-child(2) option:nth-child(2)').hasText('Decorated Values');
});
test('it handles selection', async function (assert) {
const routerSvc = this.owner.lookup('service:router') as unknown as MockRouterService;
routerSvc._setAssert(assert);
const docsSvc = this.owner.lookup('service:docs') as unknown as MockDocsService;
docsSvc._setGroupsData([
['english', ['one', 'two', 'three']],
['spanish', ['uno', 'dos', 'tres']],
['german', ['eins', 'zwei', 'drei']],
]);
docsSvc._setCurrentPath('/spanish/dos');
await render(<template><Selection /></template>);
assert.dom('select').hasAttribute('name', 'tutorial');
assert.dom('select > optgroup').exists({ count: 3 });
assert.dom('option').exists({ count: 9 });
assert.dom('select').hasValue('/spanish/dos');
// Not sure why, but `:checked` is how you get selected option
assert.dom('option:checked').hasValue('/spanish/dos').hasText('Dos');
await select('select', '/german/eins');
docsSvc._setCurrentPath('/german/eins');
assert.dom('option:checked').hasValue('/german/eins').hasText('Eins');
await select('select', '/english/three');
docsSvc._setCurrentPath('/english/three');
assert.dom('option:checked').hasValue('/english/three').hasText('Three');
assert.verifySteps(['transition to: /german/eins', 'transition to: /english/three']);
});
});