-
Notifications
You must be signed in to change notification settings - Fork 794
/
karma.spec.ts
139 lines (121 loc) · 6.68 KB
/
karma.spec.ts
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import { setupDomTests, waitForChanges } from '../util';
describe('slot-reorder', () => {
const { setupDom, tearDownDom } = setupDomTests(document);
let app: HTMLElement;
beforeEach(async () => {
app = await setupDom('/slot-reorder/index.html');
});
afterEach(tearDownDom);
it('renders', async () => {
let r: HTMLElement;
const button = app.querySelector('button');
function ordered() {
r = app.querySelector('.results1 div');
expect(r.children[0].textContent.trim()).toBe('fallback default');
expect(r.children[0].hasAttribute('hidden')).toBe(false);
expect(r.children[0].getAttribute('name')).toBe(null);
expect(r.children[1].textContent.trim()).toBe('fallback slot-a');
expect(r.children[1].hasAttribute('hidden')).toBe(false);
expect(r.children[1].getAttribute('name')).toBe('slot-a');
expect(r.children[2].textContent.trim()).toBe('fallback slot-b');
expect(r.children[2].hasAttribute('hidden')).toBe(false);
expect(r.children[2].getAttribute('name')).toBe('slot-b');
r = app.querySelector('.results2 div');
expect(r.children[0].textContent.trim()).toBe('fallback default');
expect(r.children[0].hasAttribute('hidden')).toBe(true);
expect(r.children[0].getAttribute('name')).toBe(null);
expect(r.children[1].textContent.trim()).toBe('default content');
expect(r.children[2].textContent.trim()).toBe('fallback slot-a');
expect(r.children[2].hasAttribute('hidden')).toBe(false);
expect(r.children[2].getAttribute('name')).toBe('slot-a');
expect(r.children[3].textContent.trim()).toBe('fallback slot-b');
expect(r.children[3].hasAttribute('hidden')).toBe(false);
expect(r.children[3].getAttribute('name')).toBe('slot-b');
r = app.querySelector('.results3 div');
expect(r.children[0].textContent.trim()).toBe('fallback default');
expect(r.children[0].hasAttribute('hidden')).toBe(true);
expect(r.children[0].getAttribute('name')).toBe(null);
expect(r.children[1].textContent.trim()).toBe('default content');
expect(r.children[2].textContent.trim()).toBe('fallback slot-a');
expect(r.children[2].hasAttribute('hidden')).toBe(true);
expect(r.children[2].getAttribute('name')).toBe('slot-a');
expect(r.children[3].textContent.trim()).toBe('slot-a content');
expect(r.children[4].textContent.trim()).toBe('fallback slot-b');
expect(r.children[4].hasAttribute('hidden')).toBe(true);
expect(r.children[4].getAttribute('name')).toBe('slot-b');
expect(r.children[5].textContent.trim()).toBe('slot-b content');
r = app.querySelector('.results4 div');
expect(r.children[0].textContent.trim()).toBe('fallback default');
expect(r.children[0].hasAttribute('hidden')).toBe(true);
expect(r.children[0].getAttribute('name')).toBe(null);
expect(r.children[1].textContent.trim()).toBe('default content');
expect(r.children[2].textContent.trim()).toBe('fallback slot-a');
expect(r.children[2].hasAttribute('hidden')).toBe(true);
expect(r.children[2].getAttribute('name')).toBe('slot-a');
expect(r.children[3].textContent.trim()).toBe('slot-a content');
expect(r.children[4].textContent.trim()).toBe('fallback slot-b');
expect(r.children[4].hasAttribute('hidden')).toBe(true);
expect(r.children[4].getAttribute('name')).toBe('slot-b');
expect(r.children[5].textContent.trim()).toBe('slot-b content');
}
function reordered() {
r = app.querySelector('.results1 div');
expect(r.children[0].textContent.trim()).toBe('fallback slot-b');
expect(r.children[0].hasAttribute('hidden')).toBe(false);
expect(r.children[0].getAttribute('name')).toBe('slot-b');
expect(r.children[1].textContent.trim()).toBe('fallback default');
expect(r.children[1].hasAttribute('hidden')).toBe(false);
expect(r.children[1].getAttribute('name')).toBe(null);
expect(r.children[2].textContent.trim()).toBe('fallback slot-a');
expect(r.children[2].hasAttribute('hidden')).toBe(false);
expect(r.children[2].getAttribute('name')).toBe('slot-a');
r = app.querySelector('.results2 div');
expect(r.children[0].textContent.trim()).toBe('fallback slot-b');
expect(r.children[0].hasAttribute('hidden')).toBe(false);
expect(r.children[0].getAttribute('name')).toBe('slot-b');
expect(r.children[1].textContent.trim()).toBe('fallback default');
expect(r.children[1].hasAttribute('hidden')).toBe(true);
expect(r.children[1].getAttribute('name')).toBe(null);
expect(r.children[2].textContent.trim()).toBe('default content');
expect(r.children[3].textContent.trim()).toBe('fallback slot-a');
expect(r.children[3].hasAttribute('hidden')).toBe(false);
expect(r.children[3].getAttribute('name')).toBe('slot-a');
r = app.querySelector('.results3 div');
expect(r.children[0].textContent.trim()).toBe('fallback slot-b');
expect(r.children[0].hasAttribute('hidden')).toBe(true);
expect(r.children[0].getAttribute('name')).toBe('slot-b');
expect(r.children[1].textContent.trim()).toBe('slot-b content');
expect(r.children[2].textContent.trim()).toBe('fallback default');
expect(r.children[2].hasAttribute('hidden')).toBe(true);
expect(r.children[2].getAttribute('name')).toBe(null);
expect(r.children[3].textContent.trim()).toBe('default content');
expect(r.children[4].textContent.trim()).toBe('fallback slot-a');
expect(r.children[4].hasAttribute('hidden')).toBe(true);
expect(r.children[4].getAttribute('name')).toBe('slot-a');
expect(r.children[5].textContent.trim()).toBe('slot-a content');
r = app.querySelector('.results4 div');
expect(r.children[0].textContent.trim()).toBe('fallback slot-b');
expect(r.children[0].hasAttribute('hidden')).toBe(true);
expect(r.children[0].getAttribute('name')).toBe('slot-b');
expect(r.children[1].textContent.trim()).toBe('slot-b content');
expect(r.children[2].textContent.trim()).toBe('fallback default');
expect(r.children[2].hasAttribute('hidden')).toBe(true);
expect(r.children[2].getAttribute('name')).toBe(null);
expect(r.children[3].textContent.trim()).toBe('default content');
expect(r.children[4].textContent.trim()).toBe('fallback slot-a');
expect(r.children[4].hasAttribute('hidden')).toBe(true);
expect(r.children[4].getAttribute('name')).toBe('slot-a');
expect(r.children[5].textContent.trim()).toBe('slot-a content');
}
ordered();
button.click();
await waitForChanges();
reordered();
button.click();
await waitForChanges();
ordered();
button.click();
await waitForChanges();
reordered();
});
});