-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathPersistentComponent.test.js
More file actions
106 lines (91 loc) · 4.28 KB
/
PersistentComponent.test.js
File metadata and controls
106 lines (91 loc) · 4.28 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
describe('PersistentComponent instantiated', () => {
beforeAll(async () => {
await page.goto('http://localhost:6969/persistent-component/a')
await page.waitForSelector('[data-hydrated]')
})
test('components should create a new instance when matching a dynamic segment', async () => {
await page.waitForSelector('[data-key="PersistentComponent/0-0-33/persistent-component/a"]')
const element = await page.$('[data-key="PersistentComponent/0-0-33/persistent-component/a"]')
expect(element).toBeTruthy()
})
test('persistent components instance should have a property called persistent', async () => {
await page.waitForSelector('[data-persistent]')
const element = await page.$('[data-persistent]')
expect(element).toBeTruthy()
})
test('persistent components should only launch once when prerendered', async () => {
await page.waitForSelector('[data-launch-count="1"]')
const element = await page.$('[data-launch-count="1"]')
expect(element).toBeTruthy()
})
})
describe('PersistentComponent terminated', () => {
beforeAll(async () => {
await page.goto('http://localhost:6969/persistent-component/a')
await page.waitForSelector('[data-hydrated]')
await page.waitForSelector('[href="/persistent-component/b"]')
await page.click('[href="/persistent-component/b"]')
await page.waitForSelector('[data-key="PersistentComponent/0-0-33/persistent-component/b"]')
})
test('components should call terminate when leaving the dom', async () => {
await page.waitForSelector('[data-a-count="1"]')
const element = await page.$('[data-a-count="1"]')
expect(element).toBeTruthy()
})
test('persistent instanes should stay on instances context when leaving the dom', async () => {
await page.waitForSelector('[data-a-count="1"]')
const element = await page.$('[data-a-count="1"]')
expect(element).toBeTruthy()
})
test('persistent instanes instance terminated should be true when off dom', async () => {
await page.waitForSelector('[data-a-terminated]')
const element = await page.$('[data-a-terminated]')
expect(element).toBeTruthy()
})
})
describe('PersistentComponent reinstantiated', () => {
beforeAll(async () => {
await page.goto('http://localhost:6969/persistent-component/a')
await page.waitForSelector('[data-hydrated]')
await page.waitForSelector('[href="/persistent-component/b"]')
await page.click('[href="/persistent-component/b"]')
await page.waitForSelector('[data-key="PersistentComponent/0-0-33/persistent-component/b"]')
await page.click('[href="/persistent-component/a"]')
await page.waitForSelector('[data-key="PersistentComponent/0-0-33/persistent-component/a"]')
})
test('components should not be prepared a second time', async () => {
await page.waitForSelector('[data-count="2"]')
const element = await page.$('[data-count="2"]')
expect(element).toBeTruthy()
})
test('components should not be initiated a second time', async () => {
await page.waitForSelector('[data-count="2"]')
const element = await page.$('[data-count="2"]')
expect(element).toBeTruthy()
})
test('components should call hydrate when reinstantiated', async () => {
await page.waitForSelector('[data-count="2"]')
const element = await page.$('[data-count="2"]')
expect(element).toBeTruthy()
})
test('components should keep the old state', async () => {
await page.waitForSelector('[data-count="2"]')
const element = await page.$('[data-count="2"]')
expect(element).toBeTruthy()
})
test('persistent components should launch again when reinstantiated', async () => {
await page.waitForSelector('[data-launch-count="2"]')
const element = await page.$('[data-launch-count="2"]')
expect(element).toBeTruthy()
})
test('persistent components instance should have a property called persistent when reinstantiated', async () => {
await page.waitForSelector('[data-persistent]')
const element = await page.$('[data-persistent]')
expect(element).toBeTruthy()
})
test('persistent components instance should have a property called prerendered when prerendered then reinstantiated', async () => {
await page.waitForSelector('[data-prerendered]')
const element = await page.$('[data-prerendered]')
expect(element).toBeTruthy()
})
})