-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathe2e.signals.spec.ts
590 lines (505 loc) · 21.2 KB
/
e2e.signals.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
import { test, expect } from "@playwright/test";
test.describe("signals", () => {
test.beforeEach(async ({ page }) => {
await page.goto("/e2e/signals");
page.on("pageerror", (err) => expect(err).toEqual(undefined));
page.on("console", (msg) => {
if (msg.type() === "error") {
expect(msg.text()).toEqual(undefined);
}
});
});
function tests() {
test("should do its thing", async ({ page }) => {
const incrementBtn = page.locator("#count");
const clickBtn = page.locator("#click");
const incrementIdBtn = page.locator("#increment-id");
const backgroundBtn = page.locator("#background");
const parentRender = page.locator("#parent-renders");
const childRender = page.locator("#child-renders");
const text = page.locator("#text");
const id = page.locator("#id");
const computed = page.locator("#computed");
const stuff = page.locator("#stuff");
const body = page.locator("body");
await expect(parentRender).toHaveText("Parent renders: 1");
await expect(childRender).toHaveText("Child renders: 1");
await expect(text).toHaveText("Text: Message");
await expect(text).toHaveAttribute("data-set", "ref");
await expect(id).toHaveText("Id: 0");
await expect(computed).toHaveText("computed: ");
await expect(stuff).toHaveText("Stuff: 10");
await expect(stuff).toHaveAttribute("data-set", "ref2");
await incrementBtn.click();
await expect(parentRender).toHaveText("Parent renders: 1");
await expect(childRender).toHaveText("Child renders: 1");
await expect(text).toHaveText("Text: Message");
await expect(text).toHaveAttribute("data-set", "ref");
await expect(id).toHaveText("Id: 0");
await expect(computed).toHaveText("computed: ");
await expect(stuff).toHaveText("Stuff: 11");
await expect(stuff).toHaveAttribute("data-set", "ref2");
await clickBtn.click();
await expect(parentRender).toHaveText("Parent renders: 1");
await expect(childRender).toHaveText("Child renders: 1");
await expect(text).toHaveText("Text: Message");
await expect(text).toHaveAttribute("data-set", "ref");
await expect(id).toHaveText("Id: 0");
await expect(computed).toHaveText("computed: clicked");
await expect(stuff).toHaveText("Stuff: 11");
await expect(stuff).toHaveAttribute("data-set", "ref2");
await incrementIdBtn.click();
await expect(parentRender).toHaveText("Parent renders: 1");
await expect(childRender).toHaveText("Child renders: 1");
await expect(text).toHaveText("Text: Message");
await expect(text).toHaveAttribute("data-set", "ref");
await expect(id).toHaveText("Id: 1");
await expect(computed).toHaveText("computed: clicked");
await expect(stuff).toHaveText("Stuff: 11");
await expect(stuff).toHaveAttribute("data-set", "ref2");
await expect(body).toHaveCSS("background-color", "rgb(255, 255, 255)");
await backgroundBtn.click();
await expect(parentRender).toHaveText("Parent renders: 1");
await expect(childRender).toHaveText("Child renders: 2");
await expect(text).toHaveText("Text: Message");
await expect(text).toHaveAttribute("data-set", "ref");
await expect(id).toHaveText("Id: 1");
await expect(computed).toHaveText("computed: clicked");
await expect(stuff).toHaveText("Stuff: 11");
await expect(stuff).toHaveAttribute("data-set", "ref2");
await expect(body).toHaveCSS("background-color", "rgb(0, 0, 0)");
});
test("issue 1681", async ({ page }) => {
const result = page.locator("#issue-1681-return");
const button = page.locator("#issue-1681-btn");
await expect(result).toHaveText("Count A is 0 Count B is 0");
await button.click();
await expect(result).toHaveText("Count A is 1 Count B is 1");
});
test("issue 1733", async ({ page }) => {
const button = page.locator("#issue1733-btn");
const spanSignal = page.locator("#issue1733-signal");
const spanTrue = page.locator("#issue1733-true");
const spanFalse = page.locator("#issue1733-false");
const h1 = page.locator("#issue1733-h1");
await expect(spanSignal).toHaveText("");
await expect(spanTrue).toHaveText("");
await expect(spanFalse).toHaveText("");
await expect(h1).not.toBeVisible();
await button.click();
await expect(spanSignal).toHaveText("");
await expect(spanTrue).toHaveText("");
await expect(spanFalse).toHaveText("");
await expect(h1).toBeVisible();
await expect(h1).toHaveText("Message");
});
test("issue 1884", async ({ page }) => {
const button = page.locator("#issue1884-btn");
const text0 = page.locator(".issue1884-text:nth-child(1)");
const text1 = page.locator(".issue1884-text:nth-child(2)");
const text2 = page.locator(".issue1884-text:nth-child(3)");
const text3 = page.locator(".issue1884-text:nth-child(4)");
await expect(text0).toHaveCSS("color", "rgb(0, 0, 0)");
await expect(text1).toHaveCSS("color", "rgb(0, 0, 0)");
await expect(text2).toHaveCSS("color", "rgb(0, 0, 0)");
await expect(text3).toHaveCSS("color", "rgb(0, 0, 0)");
await button.click();
await expect(text0).toHaveCSS("color", "rgb(255, 0, 0)");
await expect(text1).toHaveCSS("color", "rgb(255, 0, 0)");
await expect(text2).toHaveCSS("color", "rgb(255, 0, 0)");
await expect(text3).toHaveCSS("color", "rgb(255, 0, 0)");
});
test("issue 2000", async ({ page }) => {
const textArea = page.locator("#textarea");
await expect(textArea).toHaveValue("body { background: white}");
});
test("issue 2176", async ({ page }) => {
const btn = page.locator("#issue-2176-btn");
const results = page.locator(".issue-2176-result");
await expect(results).toHaveText([
"testing flag=F num=1",
"testing flag=F num=1",
"testing flag=F num=1",
"testing flag=F num=1",
"testing flag=F num=1",
"testing flag=F num=1",
"testing flag=F num=1",
"testing flag=F num=1",
"testing flag=F num=1",
"testing flag=F num=1",
"testing flag=F num=1",
"testing flag=F num=1",
]);
await btn.click();
await expect(results).toHaveText([
"testing2 flag=T num=2",
"testing2 flag=T num=2",
"testing2 flag=T num=2",
"testing2 flag=T num=2",
"testing2 flag=T num=2",
"testing2 flag=T num=2",
"testing2 flag=T num=2",
"testing2 flag=T num=2",
"testing2 flag=T num=2",
"testing2 flag=T num=2",
"testing2 flag=T num=2",
"testing2 flag=T num=2",
]);
await btn.click();
await expect(results).toHaveText([
"testing3 flag=F num=3",
"testing3 flag=F num=3",
"testing3 flag=F num=3",
"testing3 flag=F num=3",
"testing3 flag=F num=3",
"testing3 flag=F num=3",
"testing3 flag=F num=3",
"testing3 flag=F num=3",
"testing3 flag=F num=3",
"testing3 flag=F num=3",
"testing3 flag=F num=3",
"testing3 flag=F num=3",
]);
});
test("issue 2245", async ({ page }) => {
const btn = page.locator("#issue-2245-btn");
const results = page.locator(".issue-2245-results p");
expect(await results.count()).toBe(16);
for (let i = 0; i < 16; i++) {
await expect(results.nth(i)).toHaveCSS("color", "rgb(0, 0, 0)");
}
await btn.click();
for (let i = 0; i < 16; i++) {
await expect(results.nth(i)).toHaveCSS("color", "rgb(255, 0, 0)");
}
await btn.click();
for (let i = 0; i < 16; i++) {
await expect(results.nth(i)).toHaveCSS("color", "rgb(0, 0, 255)");
}
});
test("issue 2245-b", async ({ page }) => {
const btn = page.locator("#issue-2245-b-btn");
const results = page.locator(".issue-2245-b-results p");
await expect(results).toHaveCSS("color", "rgb(0, 0, 0)");
await btn.click();
await expect(results).toHaveCSS("color", "rgb(255, 0, 0)");
await btn.click();
await expect(results).toHaveCSS("color", "rgb(0, 0, 255)");
await btn.click();
await expect(results).toHaveCSS("color", "rgb(0, 128, 0)");
});
test("complex classes with signals", async ({ page }) => {
const btn = page.locator("#complex-classes-btn");
const results = page.locator("#complex-classes-results");
await expect(results).toHaveClass("initial visible");
await btn.click();
await expect(results).toHaveClass("change hidden");
});
test("issue 2311", async ({ page }) => {
const btn = page.locator("#issue-2311-btn");
const results = page.locator("#issue-2311-results > *");
await expect(results).toHaveText([
"This text should not change",
"Hello",
"This text should not change",
"Hello",
"This text should not change",
"Hello",
"This text should not change",
"Hello",
"This text should not change",
"Hello",
]);
await btn.click();
await expect(results).toHaveText([
"This text should not change",
"Done!",
"This text should not change",
"Done!",
"This text should not change",
"Done!",
"This text should not change",
"Done!",
"This text should not change",
"Done!",
]);
});
test("issue 2344", async ({ page }) => {
const btn = page.locator("#issue-2344-btn");
const results = page.locator("#issue-2344-results");
await expect(results).toHaveValue("Content");
await btn.click();
await expect(results).toHaveValue("Content");
});
test("issue 2930", async ({ page }) => {
const input = page.locator("#issue-2930-input");
const results = page.locator(".issue-2930-result");
await expect(results).toHaveText([
'{"controls":{"ctrl":{"value":""}}}',
'{"ctrl":{"value":""}}',
'{"value":""}',
'""',
]);
await page.waitForTimeout(100);
await input.fill("test");
await expect(results).toHaveText([
'{"controls":{"ctrl":{"value":"test"}}}',
'{"ctrl":{"value":"test"}}',
'{"value":"test"}',
'"test"',
]);
});
test("issue 3212", async ({ page }) => {
const result0 = page.locator("#issue-3212-result-0");
const result1 = page.locator("#issue-3212-result-1");
const result2 = page.locator("#issue-3212-result-2");
const result3 = page.locator("#issue-3212-result-3");
await expect(result0).toHaveText("1");
await expect(result1).toHaveText("1");
await expect(result2).toHaveText("1");
await expect(result3).toHaveText("1");
});
test("fine-grained-mutable", async ({ page }) => {
const mutable = page.locator("#fine-grained-mutable");
const signal = page.locator("#fine-grained-signal");
await expect(mutable).toHaveText("2");
await expect(signal).toHaveText("Increment 0");
await signal.click();
await expect(mutable).toHaveText("3");
await expect(signal).toHaveText("Increment 1");
await signal.click();
await expect(mutable).toHaveText("4");
await expect(signal).toHaveText("Increment 2");
});
test("issue 3415", async ({ page }) => {
const result = page.locator("#issue-3415-result");
const button = page.locator("#issue-3415-button");
await expect(result).toHaveText("foo");
await expect(await result.innerHTML()).toEqual("<b>foo</b>");
await button.click();
await expect(result).toHaveText("bar");
await expect(await result.innerHTML()).toEqual("<i>bar</i>");
});
test("bind value", async ({ page }) => {
const input = page.locator("#bind-input-1");
const textarea = page.locator("#bind-input-2");
const text1 = page.locator("#bind-text-1");
const text2 = page.locator("#bind-text-2");
const checkbox = page.locator("#bind-checkbox");
const checkbox2 = page.locator("#bind-checkbox-2");
await expect(input).toHaveValue("initial");
await expect(textarea).toHaveValue("initial");
await expect(text1).toHaveText("Value: initial");
await expect(text2).toHaveText("Value: initial");
await input.clear();
await input.fill("from1");
await expect(input).toHaveValue("from1");
await expect(textarea).toHaveValue("from1");
await expect(text1).toHaveText("Value: from1");
await expect(text2).toHaveText("Value: from1");
await input.clear();
await textarea.type("from2");
await expect(input).toHaveValue("from2");
await expect(textarea).toHaveValue("from2");
await expect(text1).toHaveText("Value: from2");
await expect(text2).toHaveText("Value: from2");
await input.clear();
await expect(input).toHaveValue("");
await expect(textarea).toHaveValue("");
await expect(text1).toHaveText("Value: ");
await expect(text2).toHaveText("Value: ");
await expect(checkbox).not.toBeChecked();
await expect(checkbox2).not.toBeChecked();
await expect(input).not.toBeDisabled();
await expect(textarea).not.toBeDisabled();
await checkbox.click();
await expect(checkbox).toBeChecked();
await expect(checkbox2).toBeChecked();
await expect(input).toBeDisabled();
await expect(textarea).toBeDisabled();
await checkbox2.click();
await expect(checkbox).not.toBeChecked();
await expect(checkbox2).not.toBeChecked();
await expect(input).not.toBeDisabled();
await expect(textarea).not.toBeDisabled();
await checkbox2.click();
await expect(checkbox).toBeChecked();
await expect(checkbox2).toBeChecked();
await expect(input).toBeDisabled();
await expect(textarea).toBeDisabled();
});
test("issue 3482", async ({ page }) => {
const button = page.locator("#issue-3482-button");
const result = page.locator("#issue-3482-result");
await expect(button).toHaveText("Increment 0");
await expect(button).toHaveAttribute("data-count", "0");
await expect(result).toHaveText("0");
await expect(result).toHaveAttribute("data-count", "0");
await button.click();
await expect(button).toHaveText("Increment 1");
await expect(button).toHaveAttribute("data-count", "1");
await expect(result).toHaveText("1");
await expect(result).toHaveAttribute("data-count", "1");
});
test("issue 3663", async ({ page }) => {
const button = page.locator("#issue-3663-button");
const result = page.locator(".issue-3663-result");
await expect(result).toHaveText(["0", "0", "0"]);
await button.click();
await expect(result).toHaveText(["1", "1", "1"]);
await button.click();
await expect(result).toHaveText(["2", "2", "2"]);
await button.click();
await expect(result).toHaveText(["3", "3", "3"]);
});
test("issue 3440", async ({ page }) => {
const results = page.locator(".issue-3440-results");
const remove = page.locator("#issue-3440-remove");
await expect(results).toHaveText([
"my first blog",
"my second blogs",
"my third blog",
]);
await remove.click();
await expect(results).toHaveText(["my first blog", "my second blogs"]);
await remove.click();
await expect(results).toHaveText(["my first blog"]);
await remove.click();
await expect(results).toHaveText([]);
});
test("issue 4174", async ({ page }) => {
const result = page.locator("#issue-4174-result");
await expect(result).toHaveText("Store: visible-task");
});
test("issue 4249", async ({ page }) => {
const first = page.locator("#issue-4249-first");
const second = page.locator("#issue-4249-second");
const result = page.locator("#issue-4249-result");
await expect(result).toHaveText("Status: No collision");
await expect(result).toHaveAttribute("data-value", "no-collision");
await second.fill("bar");
await first.fill("bar");
await expect(result).toHaveText("Status: Collision detected");
await expect(result).toHaveAttribute("data-value", "collision");
await first.fill("foo");
await second.fill("foo");
await expect(result).toHaveText("Status: Collision detected");
await expect(result).toHaveAttribute("data-value", "collision");
});
test("issue 4228", async ({ page }) => {
const buttonA = page.locator("#issue-4228-button-a");
const buttonB = page.locator("#issue-4228-button-b");
const buttonC = page.locator("#issue-4228-button-c");
const resultA = page.locator("#issue-4228-result-a");
const resultB = page.locator("#issue-4228-result-b");
const resultC = page.locator("#issue-4228-result-c");
const resultTotal = page.locator("#issue-4228-result-total");
await expect(resultA).toHaveText("0:0");
await expect(resultB).toHaveText("0:0");
await expect(resultC).toHaveText("0:0");
await expect(resultTotal).toHaveText("0:0");
await buttonA.click();
await expect(resultA).toHaveText("1:1");
await expect(resultB).toHaveText("0:0");
await expect(resultC).toHaveText("0:0");
await expect(resultTotal).toHaveText("1:1");
await buttonB.click();
await expect(resultA).toHaveText("1:1");
await expect(resultB).toHaveText("1:1");
await expect(resultC).toHaveText("0:0");
await expect(resultTotal).toHaveText("2:2");
await buttonC.click();
await expect(resultA).toHaveText("1:1");
await expect(resultB).toHaveText("1:1");
await expect(resultC).toHaveText("1:1");
await expect(resultTotal).toHaveText("3:3");
await buttonA.click();
await expect(resultA).toHaveText("2:2");
await expect(resultB).toHaveText("1:1");
await expect(resultC).toHaveText("1:1");
await expect(resultTotal).toHaveText("4:4");
await buttonB.click();
await expect(resultA).toHaveText("2:2");
await expect(resultB).toHaveText("2:2");
await expect(resultC).toHaveText("1:1");
await expect(resultTotal).toHaveText("5:5");
await buttonC.click();
await expect(resultA).toHaveText("2:2");
await expect(resultB).toHaveText("2:2");
await expect(resultC).toHaveText("2:2");
await expect(resultTotal).toHaveText("6:6");
});
test("issue 4368", async ({ page }) => {
const input = page.locator("#issue-4368-input");
const button = page.locator("#issue-4368-button");
await expect(button).toHaveText("Text is empty");
await expect(button).toBeDisabled();
await input.fill("foo");
await expect(button).toHaveText("Example button");
await expect(button).not.toBeDisabled();
});
test("issue 4868", async ({ page }) => {
const btn1 = page.locator("#issue-4868-btn-1");
const btn2 = page.locator("#issue-4868-btn-2");
const json = page.locator("#issue-4868-json");
const props = page.locator("#issue-4868-props");
const usecomputed = page.locator("#issue-4868-usecomputed");
await expect(json).toHaveText(
`{"src":"https://placehold.co/400x400?text=1","id":1}`,
);
await expect(props).toHaveText(
`Card props.src: https://placehold.co/400x400?text=1`,
);
await expect(usecomputed).toHaveText(
`Card useComputed$: https://placehold.co/400x400?text=1&useComputed$`,
);
await btn2.click();
await expect(json).toHaveText(
`{"src":"https://placehold.co/500x500?text=2","id":2}`,
);
await expect(props).toHaveText(
`Card props.src: https://placehold.co/500x500?text=2`,
);
await expect(usecomputed).toHaveText(
`Card useComputed$: https://placehold.co/500x500?text=2&useComputed$`,
);
await btn1.click();
await expect(json).toHaveText(
`{"src":"https://placehold.co/400x400?text=1","id":1}`,
);
await expect(props).toHaveText(
`Card props.src: https://placehold.co/400x400?text=1`,
);
await expect(usecomputed).toHaveText(
`Card useComputed$: https://placehold.co/400x400?text=1&useComputed$`,
);
});
test("createSignal/createComputed$", async ({ page }) => {
const button = page.locator("#many-signals-button");
const result = page.locator("#many-signals-result");
const doubles = page.locator("#many-doubles-result");
await expect(result).toHaveText("0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ");
await expect(doubles).toHaveText("0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ");
await button.click();
await expect(result).toHaveText("1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ");
await expect(doubles).toHaveText("2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ");
});
}
tests();
test.describe("client rerender", () => {
test.beforeEach(async ({ page }) => {
const toggleRender = page.locator("#rerender");
await toggleRender.click();
await page.waitForTimeout(200);
});
tests();
});
});
test.describe("regressions", () => {
test("issue 5001", async ({ page }) => {
await page.goto("/e2e/signals/issue-5001");
await expect(page.locator(".count")).toHaveText("0");
await page.locator("button").click();
await expect(page.locator(".count")).toHaveText("1");
});
});