-
Notifications
You must be signed in to change notification settings - Fork 794
/
karma.spec.ts
111 lines (89 loc) · 4.63 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
import { setupDomTests, waitForChanges } from '../util';
describe('lifecycle-unload', function () {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
const { setupDom, tearDownDom } = setupDomTests(document);
let app: HTMLElement;
beforeEach(async () => {
app = await setupDom('/lifecycle-unload/index.html');
});
afterEach(tearDownDom);
it('fire unload methods', async () => {
if ('shadowRoot' in HTMLElement.prototype) {
await testNativeShadowDom();
} else {
await testSlotPolyfill();
}
});
async function testNativeShadowDom() {
let main = app.querySelector('lifecycle-unload-a').shadowRoot.querySelector('main');
expect(main.children[0].textContent.trim()).toBe('cmp-a - top');
expect(main.children[1].textContent.trim()).toBe('cmp-a - middle');
expect(main.children[2].textContent.trim()).toBe('cmp-a - bottom');
expect(main.children[1].shadowRoot.children[0].textContent.trim()).toBe('cmp-b - top');
expect(main.children[1].shadowRoot.children[1].textContent.trim()).toBe('');
expect(main.children[1].shadowRoot.children[2].textContent.trim()).toBe('cmp-b - bottom');
let unload = app.querySelector('#lifecycle-unload-results');
expect(unload.children.length).toBe(0);
const button = app.querySelector('button');
button.click();
await waitForChanges();
const cmpA = app.querySelector('lifecycle-unload-a');
expect(cmpA).toBe(null);
unload = app.querySelector('#lifecycle-unload-results');
expect(unload.children[0].textContent.trim()).toBe('cmp-a unload');
expect(unload.children[1].textContent.trim()).toBe('cmp-b unload');
expect(unload.children.length).toBe(2);
button.click();
await waitForChanges();
main = app.querySelector('lifecycle-unload-a').shadowRoot.querySelector('main');
expect(main.children[0].textContent.trim()).toBe('cmp-a - top');
expect(main.children[1].textContent.trim()).toBe('cmp-a - middle');
expect(main.children[2].textContent.trim()).toBe('cmp-a - bottom');
expect(main.children[1].shadowRoot.children[0].textContent.trim()).toBe('cmp-b - top');
expect(main.children[1].shadowRoot.children[1].textContent.trim()).toBe('');
expect(main.children[1].shadowRoot.children[2].textContent.trim()).toBe('cmp-b - bottom');
button.click();
await waitForChanges();
unload = app.querySelector('#lifecycle-unload-results');
expect(unload.children[0].textContent.trim()).toBe('cmp-a unload');
expect(unload.children[1].textContent.trim()).toBe('cmp-b unload');
expect(unload.children[2].textContent.trim()).toBe('cmp-a unload');
expect(unload.children[3].textContent.trim()).toBe('cmp-b unload');
expect(unload.children.length).toBe(4);
}
async function testSlotPolyfill() {
let main = app.querySelector('lifecycle-unload-a main');
expect(main.children[0].textContent.trim()).toBe('cmp-a - top');
expect(main.children[1].children[0].textContent.trim()).toBe('cmp-b - top');
expect(main.children[1].children[1].textContent.trim()).toBe('cmp-a - middle');
expect(main.children[1].children[2].textContent.trim()).toBe('cmp-b - bottom');
expect(main.children[2].textContent.trim()).toBe('cmp-a - bottom');
let unload = app.querySelector('#lifecycle-unload-results');
expect(unload.children.length).toBe(0);
const button = app.querySelector('button');
button.click();
await waitForChanges();
const cmpA = app.querySelector('lifecycle-unload-a');
expect(cmpA).toBe(null);
unload = app.querySelector('#lifecycle-unload-results');
expect(unload.children[0].textContent.trim()).toBe('cmp-a unload');
expect(unload.children[1].textContent.trim()).toBe('cmp-b unload');
expect(unload.children.length).toBe(2);
button.click();
await waitForChanges();
main = app.querySelector('lifecycle-unload-a main');
expect(main.children[0].textContent.trim()).toBe('cmp-a - top');
expect(main.children[1].children[0].textContent.trim()).toBe('cmp-b - top');
expect(main.children[1].children[1].textContent.trim()).toBe('cmp-a - middle');
expect(main.children[1].children[2].textContent.trim()).toBe('cmp-b - bottom');
expect(main.children[2].textContent.trim()).toBe('cmp-a - bottom');
button.click();
await waitForChanges();
unload = app.querySelector('#lifecycle-unload-results');
expect(unload.children[0].textContent.trim()).toBe('cmp-a unload');
expect(unload.children[1].textContent.trim()).toBe('cmp-b unload');
expect(unload.children[2].textContent.trim()).toBe('cmp-a unload');
expect(unload.children[3].textContent.trim()).toBe('cmp-b unload');
expect(unload.children.length).toBe(4);
}
});