|
1 | | -import 'jest-playwright-preset'; |
| 1 | +/* eslint-disable unicorn/no-await-expression-member, jest/no-done-callback, playwright/missing-playwright-await */ |
2 | 2 |
|
| 3 | +import { expect, test } from '@playwright/test'; |
3 | 4 | import path from 'path'; |
4 | 5 |
|
5 | | -const waitForResize = () => page.waitForTimeout(100); |
6 | | - |
7 | | -test('resize', async () => { |
| 6 | +test('resize', async ({ page }) => { |
8 | 7 | await page.goto(`file:${path.join(__dirname, 'build/Bootstrap.html')}`); |
9 | 8 |
|
10 | 9 | const height = 768; |
11 | 10 |
|
12 | | - const firstPersonChildren = (await page.$('.people > .person:first-child > .wrap-children'))!; |
13 | | - const children = await firstPersonChildren.$$(':scope > div'); |
14 | | - expect(children.length).toEqual(5); |
15 | | - |
16 | | - { |
17 | | - await page.setViewportSize({ width: /*1114*/ 1111, height }); |
18 | | - await waitForResize(); |
19 | | - |
20 | | - const classNames = await Promise.all(children.map(div => div.evaluate(el => el.className))); |
21 | | - expect(classNames).toEqual([ |
22 | | - 'floating-label mb-3 me-2 flex-fill', |
23 | | - 'floating-label mb-3 me-2 flex-fill', |
24 | | - 'floating-label mb-3 me-2', |
25 | | - 'floating-label mb-3 me-2', |
26 | | - 'floating-label mb-3 me-2' |
27 | | - ]); |
28 | | - |
29 | | - expect(await page.screenshot()).toMatchImageSnapshot(); |
30 | | - } |
31 | | - |
32 | | - { |
33 | | - await page.setViewportSize({ width: /*1113*/ 1110, height }); |
34 | | - await waitForResize(); |
35 | | - |
36 | | - const classNames = await Promise.all(children.map(div => div.evaluate(el => el.className))); |
37 | | - expect(classNames).toEqual([ |
38 | | - 'floating-label mb-3 me-2 flex-fill', |
39 | | - 'floating-label mb-3 me-2 flex-fill', |
40 | | - 'floating-label mb-3 me-2', |
41 | | - 'floating-label mb-3 me-2 next-is-wrapped', |
42 | | - 'floating-label mb-3 me-2' |
43 | | - ]); |
44 | | - |
45 | | - expect(await page.screenshot()).toMatchImageSnapshot(); |
46 | | - } |
47 | | - |
48 | | - { |
49 | | - await page.setViewportSize({ width: /*814*/ 813, height }); |
50 | | - await waitForResize(); |
51 | | - |
52 | | - const classNames = await Promise.all(children.map(div => div.evaluate(el => el.className))); |
53 | | - expect(classNames).toEqual([ |
54 | | - 'floating-label mb-3 me-2 flex-fill', |
55 | | - 'floating-label mb-3 me-2 flex-fill', |
56 | | - 'floating-label mb-3 me-2 next-is-wrapped', |
57 | | - 'floating-label mb-3 me-2', |
58 | | - 'floating-label mb-3 me-2' |
59 | | - ]); |
60 | | - |
61 | | - expect(await page.screenshot()).toMatchImageSnapshot(); |
62 | | - } |
63 | | - |
64 | | - { |
65 | | - await page.setViewportSize({ width: /*610*/ 609, height }); |
66 | | - await waitForResize(); |
67 | | - |
68 | | - const classNames = await Promise.all(children.map(div => div.evaluate(el => el.className))); |
69 | | - expect(classNames).toEqual([ |
70 | | - 'floating-label mb-3 me-2 flex-fill', |
71 | | - 'floating-label mb-3 me-2 flex-fill next-is-wrapped', |
72 | | - 'floating-label mb-3 me-2', |
73 | | - 'floating-label mb-3 me-2 next-is-wrapped', |
74 | | - 'floating-label mb-3 me-2' |
75 | | - ]); |
76 | | - |
77 | | - expect(await page.screenshot()).toMatchImageSnapshot(); |
78 | | - } |
79 | | - |
80 | | - { |
81 | | - await page.setViewportSize({ width: /*485*/ 485, height }); |
82 | | - await waitForResize(); |
83 | | - |
84 | | - const classNames = await Promise.all(children.map(div => div.evaluate(el => el.className))); |
85 | | - expect(classNames).toEqual([ |
86 | | - 'floating-label mb-3 me-2 flex-fill next-is-wrapped', |
87 | | - 'floating-label mb-3 me-2 flex-fill', |
88 | | - 'floating-label mb-3 me-2 next-is-wrapped', |
89 | | - 'floating-label mb-3 me-2 next-is-wrapped', |
90 | | - 'floating-label mb-3 me-2' |
91 | | - ]); |
92 | | - |
93 | | - expect(await page.screenshot()).toMatchImageSnapshot(); |
94 | | - } |
95 | | - |
96 | | - { |
97 | | - await page.setViewportSize({ width: /*375*/ 374, height }); |
98 | | - await waitForResize(); |
99 | | - |
100 | | - const classNames = await Promise.all(children.map(div => div.evaluate(el => el.className))); |
101 | | - expect(classNames).toEqual([ |
102 | | - 'floating-label mb-3 me-2 flex-fill next-is-wrapped', |
103 | | - 'floating-label mb-3 me-2 flex-fill next-is-wrapped', |
104 | | - 'floating-label mb-3 me-2', |
105 | | - 'floating-label mb-3 me-2 next-is-wrapped', |
106 | | - 'floating-label mb-3 me-2' |
107 | | - ]); |
108 | | - |
109 | | - expect(await page.screenshot()).toMatchImageSnapshot(); |
110 | | - } |
111 | | - |
112 | | - { |
113 | | - await page.setViewportSize({ width: /*344*/ 341, height }); |
114 | | - await waitForResize(); |
115 | | - |
116 | | - const classNames = await Promise.all(children.map(div => div.evaluate(el => el.className))); |
117 | | - expect(classNames).toEqual([ |
118 | | - 'floating-label mb-3 me-2 flex-fill next-is-wrapped', |
119 | | - 'floating-label mb-3 me-2 flex-fill next-is-wrapped', |
120 | | - 'floating-label mb-3 me-2 next-is-wrapped', |
121 | | - 'floating-label mb-3 me-2 next-is-wrapped', |
122 | | - 'floating-label mb-3 me-2' |
123 | | - ]); |
124 | | - |
125 | | - expect(await page.screenshot()).toMatchImageSnapshot(); |
126 | | - } |
| 11 | + const firstBeatlesChildren = page |
| 12 | + .locator('.people > .person:first-child > .wrap-children') |
| 13 | + .first(); |
| 14 | + await expect(firstBeatlesChildren).toHaveCount(1); |
| 15 | + const inputs = firstBeatlesChildren.locator('> div'); |
| 16 | + await expect(inputs).toHaveCount(5); |
| 17 | + |
| 18 | + // 1 |
| 19 | + await page.setViewportSize({ width: 1068, height }); |
| 20 | + |
| 21 | + expect(await page.screenshot()).toMatchSnapshot('bootstrap-1.png'); |
| 22 | + |
| 23 | + await expect(inputs).toHaveClass([ |
| 24 | + 'floating-label mb-3 me-2 flex-fill', |
| 25 | + 'floating-label mb-3 me-2 flex-fill', |
| 26 | + 'floating-label mb-3 me-2', |
| 27 | + 'floating-label mb-3 me-2', |
| 28 | + 'floating-label mb-3 me-2' |
| 29 | + ]); |
| 30 | + |
| 31 | + // 2 |
| 32 | + await page.setViewportSize({ width: 1067, height }); |
| 33 | + |
| 34 | + expect(await page.screenshot()).toMatchSnapshot('bootstrap-2.png'); |
| 35 | + |
| 36 | + await expect(inputs).toHaveClass([ |
| 37 | + 'floating-label mb-3 me-2 flex-fill', |
| 38 | + 'floating-label mb-3 me-2 flex-fill', |
| 39 | + 'floating-label mb-3 me-2', |
| 40 | + 'floating-label mb-3 me-2 next-is-wrapped', |
| 41 | + 'floating-label mb-3 me-2' |
| 42 | + ]); |
| 43 | + |
| 44 | + // 3 |
| 45 | + await page.setViewportSize({ width: 761, height }); |
| 46 | + |
| 47 | + expect(await page.screenshot()).toMatchSnapshot('bootstrap-3.png'); |
| 48 | + |
| 49 | + await expect(inputs).toHaveClass([ |
| 50 | + 'floating-label mb-3 me-2 flex-fill', |
| 51 | + 'floating-label mb-3 me-2 flex-fill', |
| 52 | + 'floating-label mb-3 me-2 next-is-wrapped', |
| 53 | + 'floating-label mb-3 me-2', |
| 54 | + 'floating-label mb-3 me-2' |
| 55 | + ]); |
| 56 | + |
| 57 | + // 4 |
| 58 | + await page.setViewportSize({ width: 559, height }); |
| 59 | + |
| 60 | + expect(await page.screenshot()).toMatchSnapshot('bootstrap-4.png'); |
| 61 | + |
| 62 | + await expect(inputs).toHaveClass([ |
| 63 | + 'floating-label mb-3 me-2 flex-fill', |
| 64 | + 'floating-label mb-3 me-2 flex-fill next-is-wrapped', |
| 65 | + 'floating-label mb-3 me-2', |
| 66 | + 'floating-label mb-3 me-2 next-is-wrapped', |
| 67 | + 'floating-label mb-3 me-2' |
| 68 | + ]); |
| 69 | + |
| 70 | + // 5 |
| 71 | + await page.setViewportSize({ width: 433, height }); |
| 72 | + |
| 73 | + expect(await page.screenshot()).toMatchSnapshot('bootstrap-5.png'); |
| 74 | + |
| 75 | + await expect(inputs).toHaveClass([ |
| 76 | + 'floating-label mb-3 me-2 flex-fill next-is-wrapped', |
| 77 | + 'floating-label mb-3 me-2 flex-fill', |
| 78 | + 'floating-label mb-3 me-2 next-is-wrapped', |
| 79 | + 'floating-label mb-3 me-2 next-is-wrapped', |
| 80 | + 'floating-label mb-3 me-2' |
| 81 | + ]); |
| 82 | + |
| 83 | + // 6 |
| 84 | + await page.setViewportSize({ width: 350, height }); |
| 85 | + |
| 86 | + expect(await page.screenshot()).toMatchSnapshot('bootstrap-6.png'); |
| 87 | + |
| 88 | + await expect(inputs).toHaveClass([ |
| 89 | + 'floating-label mb-3 me-2 flex-fill next-is-wrapped', |
| 90 | + 'floating-label mb-3 me-2 flex-fill next-is-wrapped', |
| 91 | + 'floating-label mb-3 me-2 next-is-wrapped', |
| 92 | + 'floating-label mb-3 me-2 next-is-wrapped', |
| 93 | + 'floating-label mb-3 me-2' |
| 94 | + ]); |
| 95 | + |
| 96 | + // 7 |
| 97 | + await page.setViewportSize({ width: 343, height }); |
| 98 | + |
| 99 | + expect(await page.screenshot()).toMatchSnapshot('bootstrap-7.png'); |
| 100 | + |
| 101 | + await expect(inputs).toHaveClass([ |
| 102 | + 'floating-label mb-3 me-2 flex-fill next-is-wrapped', |
| 103 | + 'floating-label mb-3 me-2 flex-fill next-is-wrapped', |
| 104 | + 'floating-label mb-3 me-2 next-is-wrapped', |
| 105 | + 'floating-label mb-3 me-2 next-is-wrapped', |
| 106 | + 'floating-label mb-3 me-2' |
| 107 | + ]); |
127 | 108 | }); |
0 commit comments