|
| 1 | +import {test, expect} from "../utils/playwright-fixtures.js"; |
| 2 | +import {closeServer, loadFixtureState} from "../utils/fixed-state-server.js"; |
| 3 | + |
| 4 | +test.describe('Desktop Layout', () => { |
| 5 | + let server; |
| 6 | + |
| 7 | + test.afterEach(async () => { |
| 8 | + await closeServer(server); |
| 9 | + }); |
| 10 | + |
| 11 | + test('Items container shrinks when viewport narrows within lg breakpoint', async ({ page, serverPort }) => { |
| 12 | + await page.setViewportSize({ width: 1300, height: 800 }); |
| 13 | + server = await loadFixtureState('desktop-test-user-item-view', serverPort, page); |
| 14 | + |
| 15 | + const itemsContainer = page.locator('.items-container'); |
| 16 | + const itemDetails = page.locator('.item-details'); |
| 17 | + |
| 18 | + // At 1300px (lg), both items-container and item-details should be visible |
| 19 | + await expect(itemsContainer).toBeVisible(); |
| 20 | + await expect(itemDetails).toBeVisible(); |
| 21 | + |
| 22 | + const initialWidth = await itemsContainer.evaluate(el => el.offsetWidth); |
| 23 | + |
| 24 | + // Shrink to 1200px (still lg) |
| 25 | + await page.setViewportSize({ width: 1200, height: 800 }); |
| 26 | + |
| 27 | + // Items-container should shrink |
| 28 | + const shrunkWidth = await itemsContainer.evaluate(el => el.offsetWidth); |
| 29 | + expect(shrunkWidth).toBeLessThan(initialWidth); |
| 30 | + |
| 31 | + // Item details should still be fully within the viewport |
| 32 | + const detailsBox = await itemDetails.boundingBox(); |
| 33 | + expect(detailsBox.x + detailsBox.width).toBeLessThanOrEqual(1200); |
| 34 | + }); |
| 35 | + |
| 36 | + test('Layout switches from 3-column to 2-column when crossing lg/md breakpoint', async ({ page, serverPort }) => { |
| 37 | + await page.setViewportSize({ width: 1300, height: 800 }); |
| 38 | + server = await loadFixtureState('desktop-test-user-item-view', serverPort, page); |
| 39 | + |
| 40 | + const items = page.locator('section.items'); |
| 41 | + const itemsContainer = page.locator('.items-container'); |
| 42 | + const itemDetails = page.locator('.item-details'); |
| 43 | + |
| 44 | + // At 1300px (lg): row layout -- items-container and item-details side by side |
| 45 | + let itemsDirection = await items.evaluate(el => getComputedStyle(el).flexDirection); |
| 46 | + expect(itemsDirection).toBe('row'); |
| 47 | + |
| 48 | + // Shrink to 1024px (md): column layout -- items-container and item-details stacked |
| 49 | + await page.setViewportSize({ width: 1024, height: 800 }); |
| 50 | + |
| 51 | + itemsDirection = await items.evaluate(el => getComputedStyle(el).flexDirection); |
| 52 | + expect(itemsDirection).toBe('column'); |
| 53 | + |
| 54 | + // Both should be visible within viewport |
| 55 | + await expect(itemsContainer).toBeVisible(); |
| 56 | + await expect(itemDetails).toBeVisible(); |
| 57 | + |
| 58 | + const containerBox = await itemsContainer.boundingBox(); |
| 59 | + const detailsBox = await itemDetails.boundingBox(); |
| 60 | + |
| 61 | + // Item details should be below items-container (stacked layout) |
| 62 | + expect(detailsBox.y).toBeGreaterThanOrEqual(containerBox.y + containerBox.height - 1); |
| 63 | + |
| 64 | + // Item details should be within the viewport |
| 65 | + expect(detailsBox.y + detailsBox.height).toBeLessThanOrEqual(800); |
| 66 | + }); |
| 67 | +}); |
0 commit comments