|
| 1 | +import path from 'path'; |
| 2 | + |
| 3 | +import { nextIsWrappedClassName } from 'flex-wrap-layout'; |
| 4 | + |
| 5 | +const waitForResize = () => page.waitFor(100); |
| 6 | + |
| 7 | +test('resize 1024px => 296px => 183px', async () => { |
| 8 | + await page.goto(`file:${path.join(__dirname, 'build/Minimal.html')}`); |
| 9 | + |
| 10 | + const height = 768; |
| 11 | + |
| 12 | + const parent = (await page.$('.wrap-children'))!; |
| 13 | + const children = await parent.$$('div'); |
| 14 | + expect(children.length).toEqual(3); |
| 15 | + |
| 16 | + { |
| 17 | + await page.setViewportSize({ width: 1024, height }); |
| 18 | + await waitForResize(); |
| 19 | + |
| 20 | + const parentClassName = await parent.evaluate(el => el.className); |
| 21 | + const child0BoundingBox = await children[0].boundingBox(); |
| 22 | + const child0ClassName = await children[0].evaluate(el => el.className); |
| 23 | + const child1BoundingBox = await children[1].boundingBox(); |
| 24 | + const child1ClassName = await children[1].evaluate(el => el.className); |
| 25 | + const child2BoundingBox = await children[2].boundingBox(); |
| 26 | + const child2ClassName = await children[2].evaluate(el => el.className); |
| 27 | + |
| 28 | + expect((await page.$$('.next-is-wrapped')).length).toEqual(0); |
| 29 | + expect(parentClassName).toEqual('wrap-children'); |
| 30 | + expect(child0BoundingBox).toEqual({ x: 13, y: 13, width: 48.265625, height: 72 }); |
| 31 | + expect(child0ClassName).toEqual(''); |
| 32 | + expect(child1BoundingBox).toEqual({ x: 71.265625, y: 13, width: 826.78125, height: 72 }); |
| 33 | + expect(child1ClassName).toEqual(''); |
| 34 | + expect(child2BoundingBox).toEqual({ x: 908.046875, y: 13, width: 102.953125, height: 72 }); |
| 35 | + expect(child2ClassName).toEqual(''); |
| 36 | + } |
| 37 | + |
| 38 | + { |
| 39 | + await page.setViewportSize({ width: 296, height }); |
| 40 | + await waitForResize(); |
| 41 | + |
| 42 | + const parentClassName = await parent.evaluate(el => el.className); |
| 43 | + const child0BoundingBox = await children[0].boundingBox(); |
| 44 | + const child0ClassName = await children[0].evaluate(el => el.className); |
| 45 | + const child1BoundingBox = await children[1].boundingBox(); |
| 46 | + const child1ClassName = await children[1].evaluate(el => el.className); |
| 47 | + const child2BoundingBox = await children[2].boundingBox(); |
| 48 | + const child2ClassName = await children[2].evaluate(el => el.className); |
| 49 | + |
| 50 | + expect((await page.$$('.next-is-wrapped')).length).toEqual(1); |
| 51 | + expect(parentClassName).toEqual('wrap-children has-child-wrapped'); |
| 52 | + expect(child0BoundingBox).toEqual({ x: 13, y: 13, width: 48.265625, height: 72 }); |
| 53 | + expect(child0ClassName).toEqual(''); |
| 54 | + expect(child1BoundingBox).toEqual({ x: 71.265625, y: 13, width: 211.734375, height: 72 }); |
| 55 | + expect(child1ClassName).toEqual(nextIsWrappedClassName); |
| 56 | + expect(child2BoundingBox).toEqual({ x: 13, y: 95, width: 270, height: 72 }); |
| 57 | + expect(child2ClassName).toEqual(''); |
| 58 | + } |
| 59 | + |
| 60 | + { |
| 61 | + await page.setViewportSize({ width: 183, height }); |
| 62 | + await waitForResize(); |
| 63 | + |
| 64 | + const parentClassName = await parent.evaluate(el => el.className); |
| 65 | + const child0BoundingBox = await children[0].boundingBox(); |
| 66 | + const child0ClassName = await children[0].evaluate(el => el.className); |
| 67 | + const child1BoundingBox = await children[1].boundingBox(); |
| 68 | + const child1ClassName = await children[1].evaluate(el => el.className); |
| 69 | + const child2BoundingBox = await children[2].boundingBox(); |
| 70 | + const child2ClassName = await children[2].evaluate(el => el.className); |
| 71 | + |
| 72 | + expect((await page.$$('.next-is-wrapped')).length).toEqual(2); |
| 73 | + expect(parentClassName).toEqual('wrap-children has-child-wrapped'); |
| 74 | + expect(child0BoundingBox).toEqual({ x: 13, y: 13, width: 157, height: 72 }); |
| 75 | + expect(child0ClassName).toEqual(nextIsWrappedClassName); |
| 76 | + expect(child1BoundingBox).toEqual({ x: 13, y: 95, width: 157, height: 72 }); |
| 77 | + expect(child1ClassName).toEqual(nextIsWrappedClassName); |
| 78 | + expect(child2BoundingBox).toEqual({ x: 13, y: 177, width: 157, height: 72 }); |
| 79 | + expect(child2ClassName).toEqual(''); |
| 80 | + } |
| 81 | +}); |
0 commit comments