forked from QwikDev/qwik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe2e.context.spec.ts
188 lines (162 loc) · 6.18 KB
/
e2e.context.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import { test, expect } from "@playwright/test";
test.describe("context", () => {
function tests() {
test("should load", async ({ page }) => {
const level2State1 = page.locator(".level2-state1");
const level2State2 = page.locator(".level2-state2");
const level2SSlot = page.locator(".level2-slot");
const btnRootIncrement1 = page.locator(".root-increment1");
const btnRootIncrement2 = page.locator(".root-increment2");
const btnLevel2Increment = page.locator(".level2-increment3").nth(0);
const btnLevel2Increment2 = page.locator(".level2-increment3").nth(1);
expect(await level2State1.allTextContents()).toEqual([
"ROOT / state1 = 0",
"ROOT / state1 = 0",
]);
expect(await level2State2.allTextContents()).toEqual([
"ROOT / state2 = 0",
"ROOT / state2 = 0",
]);
expect(await level2SSlot.allTextContents()).toEqual([
"bar = 0",
"bar = 0",
]);
await btnRootIncrement1.click();
await expect(level2State1.first()).toHaveText("ROOT / state1 = 1");
expect(await level2State1.allTextContents()).toEqual([
"ROOT / state1 = 1",
"ROOT / state1 = 1",
]);
expect(await level2State2.allTextContents()).toEqual([
"ROOT / state2 = 0",
"ROOT / state2 = 0",
]);
expect(await level2SSlot.allTextContents()).toEqual([
"bar = 0",
"bar = 0",
]);
await btnRootIncrement2.click();
await expect(level2State2.first()).toHaveText("ROOT / state2 = 1");
expect(await level2State1.allTextContents()).toEqual([
"ROOT / state1 = 1",
"ROOT / state1 = 1",
]);
expect(await level2State2.allTextContents()).toEqual([
"ROOT / state2 = 1",
"ROOT / state2 = 1",
]);
expect(await level2SSlot.allTextContents()).toEqual([
"bar = 0",
"bar = 0",
]);
await btnLevel2Increment.click();
await btnLevel2Increment.click();
await btnLevel2Increment2.click();
const level3State1 = page.locator(".level3-state1");
const level3State2 = page.locator(".level3-state2");
const level3State3 = page.locator(".level3-state3");
const level3Slot = page.locator(".level3-slot");
await expect(level3State1.first()).toHaveText("Level2 / state1 = 0");
expect(await level2State1.allTextContents()).toEqual([
"ROOT / state1 = 1",
"ROOT / state1 = 1",
]);
expect(await level2State2.allTextContents()).toEqual([
"ROOT / state2 = 1",
"ROOT / state2 = 1",
]);
expect(await level2SSlot.allTextContents()).toEqual([
"bar = 0",
"bar = 0",
]);
expect(await level3State1.allTextContents()).toEqual([
"Level2 / state1 = 0",
"Level2 / state1 = 0",
"Level2 / state1 = 0",
]);
expect(await level3State2.allTextContents()).toEqual([
"ROOT / state2 = 1",
"ROOT / state2 = 1",
"ROOT / state2 = 1",
]);
expect(await level3State3.allTextContents()).toEqual([
"Level2 / state3 = 2",
"Level2 / state3 = 2",
"Level2 / state3 = 1",
]);
expect(await level3Slot.allTextContents()).toEqual([
"bar = 0",
"bar = 0",
"bar = 0",
]);
});
test("issue 1971", async ({ page }) => {
const value = page.locator("#issue1971-value");
await expect(value).toHaveText("Value: hello!");
});
test("issue 2087", async ({ page }) => {
const btn1 = page.locator("#issue2087_btn1");
const btn2 = page.locator("#issue2087_btn2");
const rootA = page.locator("#issue2087_symbol_RootA");
const rootB = page.locator("#issue2087_symbol_RootB");
const nestedA = page.locator("#issue2087_symbol_NestedA");
const nestedB = page.locator("#issue2087_symbol_NestedB");
// Initial state
await expect(rootA).toHaveText("Symbol RootA, context value: yes");
await expect(rootB).not.toBeVisible();
await expect(nestedA).toHaveText("Symbol NestedA, context value: yes");
await expect(nestedB).not.toBeVisible();
// Click a
await btn1.click();
await expect(rootB).toBeVisible();
await expect(rootA).toHaveText("Symbol RootA, context value: yes");
await expect(rootB).toHaveText("Symbol RootB, context value: yes");
// Click b
await btn2.click();
await expect(nestedB).toBeVisible();
await expect(nestedA).toHaveText("Symbol NestedA, context value: yes");
await expect(nestedB).toHaveText("Symbol NestedB, context value: yes");
});
test("issue 2894", async ({ page }) => {
const btn = page.locator("#issue2894-button");
const value = page.locator("#issue2894-value");
await expect(value).toHaveText("Value: bar");
await expect(value).not.toBeVisible();
await btn.click();
await expect(value).toHaveText("Value: bar");
await expect(value).toBeVisible();
});
test("issue 5356", async ({ page }) => {
const btn1 = page.locator("#issue5356-button-1");
const btn2 = page.locator("#issue5356-button-2");
const child1 = page.locator("#issue5356-child-1");
const child2 = page.locator("#issue5356-child-2");
await expect(child1).toContainText("Child 1, active: true");
await expect(child2).toContainText("Child 2, active: false");
await btn2.click();
await expect(child1).toContainText("Child 1, active: false");
await expect(child2).toContainText("Child 2, active: true");
await btn1.click();
await expect(child1).toContainText("Child 1, active: true");
await expect(child2).toContainText("Child 2, active: false");
});
}
test.beforeEach(async ({ page }) => {
await page.goto("/e2e/context");
page.on("pageerror", (err) => expect(err).toEqual(undefined));
page.on("console", (msg) => {
if (msg.type() === "error") {
expect(msg.text()).toEqual(undefined);
}
});
});
tests();
test.describe("client rerender", () => {
test.beforeEach(async ({ page }) => {
const rerender = page.locator("#btn-rerender");
await rerender.click();
await page.waitForTimeout(100);
});
tests();
});
});