|
| 1 | +/** |
| 2 | + * https://github.com/motiondivision/motion/issues/4042 |
| 3 | + * |
| 4 | + * An open card shares a layoutId with a gallery item, and its nested child |
| 5 | + * shares a layoutId with the item's nested child. Switching the open card to |
| 6 | + * another item's layoutIds, then closing it, must still let AnimatePresence |
| 7 | + * remove the card once its 1s exit is done. |
| 8 | + */ |
| 9 | +import { expect, Page, test } from "@playwright/test" |
| 10 | + |
| 11 | +const box = (page: Page, selector: string) => |
| 12 | + page.locator(selector).evaluate((element) => { |
| 13 | + const { x, y, width, height } = element.getBoundingClientRect() |
| 14 | + return { x, y, width, height } |
| 15 | + }) |
| 16 | + |
| 17 | +for (const switchItem of [true, false]) { |
| 18 | + test(`card exits ${ |
| 19 | + switchItem ? "after switching to another item" : "without switching" |
| 20 | + }`, async ({ page }) => { |
| 21 | + const errors: string[] = [] |
| 22 | + page.on("pageerror", (error) => errors.push(error.message)) |
| 23 | + |
| 24 | + await page.goto("?test=issue-4042") |
| 25 | + await expect(page.locator("#red")).toBeVisible() |
| 26 | + const redDot = await box(page, "#dot-red") |
| 27 | + |
| 28 | + await page.click("#red") |
| 29 | + await page.waitForTimeout(1500) |
| 30 | + |
| 31 | + if (switchItem) { |
| 32 | + await page.click("#blue", { force: true }) |
| 33 | + |
| 34 | + // The red item's dot animates home from the card's dot |
| 35 | + await page.waitForTimeout(300) |
| 36 | + const midway = await box(page, "#dot-red") |
| 37 | + expect(midway.x).toBeGreaterThan(redDot.x + 20) |
| 38 | + expect(midway.y).toBeGreaterThan(redDot.y + 20) |
| 39 | + |
| 40 | + await page.waitForTimeout(1200) |
| 41 | + expect(await box(page, "#dot-red")).toEqual(redDot) |
| 42 | + } |
| 43 | + |
| 44 | + await page.click("#close", { force: true }) |
| 45 | + await expect(page.locator("#card")).toHaveCount(0, { timeout: 2500 }) |
| 46 | + expect(errors).toEqual([]) |
| 47 | + }) |
| 48 | +} |
0 commit comments