|
| 1 | +import { expect, type Page, test } from "@playwright/test"; |
| 2 | +import { |
| 3 | + createEventTitle, |
| 4 | + ensureSidebarOpen, |
| 5 | + expectSomedayEventVisible, |
| 6 | + fillTitleAndSaveEventForm, |
| 7 | + openSomedayEventFormWithMouse, |
| 8 | + prepareCalendarPage, |
| 9 | +} from "../utils/event-test-utils"; |
| 10 | + |
| 11 | +test.skip( |
| 12 | + ({ isMobile }) => isMobile, |
| 13 | + "Mouse flows are desktop-only in week view.", |
| 14 | +); |
| 15 | + |
| 16 | +const sidebarButton = (page: Page, name: string) => |
| 17 | + page.locator("#sidebar").getByRole("button", { name }); |
| 18 | + |
| 19 | +const centerOf = async ( |
| 20 | + page: Page, |
| 21 | + name: string, |
| 22 | + scope: "sidebar" | "grid", |
| 23 | +) => { |
| 24 | + const locator = |
| 25 | + scope === "sidebar" |
| 26 | + ? sidebarButton(page, name) |
| 27 | + : page.locator("#mainGrid").getByRole("button", { name }); |
| 28 | + const box = await locator.boundingBox(); |
| 29 | + |
| 30 | + if (!box) { |
| 31 | + throw new Error(`Expected ${scope} element "${name}" to have a box.`); |
| 32 | + } |
| 33 | + |
| 34 | + return { x: box.x + box.width / 2, y: box.y + box.height / 2, box }; |
| 35 | +}; |
| 36 | + |
| 37 | +const createSomeday = async ( |
| 38 | + page: Page, |
| 39 | + section: "week" | "month", |
| 40 | + prefix: string, |
| 41 | +) => { |
| 42 | + const title = createEventTitle(prefix); |
| 43 | + await openSomedayEventFormWithMouse(page, section); |
| 44 | + await fillTitleAndSaveEventForm(page, title); |
| 45 | + await expectSomedayEventVisible(page, title); |
| 46 | + return title; |
| 47 | +}; |
| 48 | + |
| 49 | +// Creates a TALL timed event via vertical drag-select and waits for its |
| 50 | +// optimistic/pending state to settle, so it can be reliably grabbed for a drag |
| 51 | +// (a short, freshly-created event lands on the resize handle / refuses to drag). |
| 52 | +const createTimed = async (page: Page, prefix: string) => { |
| 53 | + const title = createEventTitle(prefix); |
| 54 | + const grid = await page.locator("#mainGrid").boundingBox(); |
| 55 | + |
| 56 | + if (!grid) throw new Error("Expected the week grid to be visible."); |
| 57 | + |
| 58 | + const gx = grid.x + grid.width * 0.4; |
| 59 | + const gy = grid.y + grid.height * 0.25; |
| 60 | + |
| 61 | + await page.mouse.move(gx, gy); |
| 62 | + await page.mouse.down(); |
| 63 | + await page.mouse.move(gx, gy + 160, { steps: 12 }); |
| 64 | + await page.mouse.up(); |
| 65 | + await fillTitleAndSaveEventForm(page, title); |
| 66 | + |
| 67 | + await expect( |
| 68 | + page.locator("#mainGrid").getByRole("button", { name: title }), |
| 69 | + ).toBeVisible({ timeout: 8000 }); |
| 70 | + await page.waitForTimeout(2500); |
| 71 | + |
| 72 | + return title; |
| 73 | +}; |
| 74 | + |
| 75 | +test("drags a timed grid event into the Someday week list and reorders rows live", async ({ |
| 76 | + page, |
| 77 | +}) => { |
| 78 | + await prepareCalendarPage(page); |
| 79 | + await ensureSidebarOpen(page); |
| 80 | + |
| 81 | + const weekA = await createSomeday(page, "week", "Week A"); |
| 82 | + const weekB = await createSomeday(page, "week", "Week B"); |
| 83 | + const timed = await createTimed(page, "Timed T"); |
| 84 | + |
| 85 | + const start = await centerOf(page, timed, "grid"); |
| 86 | + const a = await centerOf(page, weekA, "sidebar"); |
| 87 | + const b = await centerOf(page, weekB, "sidebar"); |
| 88 | + |
| 89 | + // Aim for the seam between A and B in the week list. |
| 90 | + const target = { x: a.x, y: (a.y + b.y) / 2 }; |
| 91 | + |
| 92 | + await page.mouse.move(start.x, start.y); |
| 93 | + await page.mouse.down(); |
| 94 | + await page.mouse.move(target.x, target.y, { steps: 16 }); |
| 95 | + await page.waitForTimeout(250); |
| 96 | + |
| 97 | + await page.screenshot({ |
| 98 | + path: "test-results/repro/week-list-mid-drag.png", |
| 99 | + }); |
| 100 | + |
| 101 | + // The dragged event should appear in the sidebar between A and B (the existing |
| 102 | + // rows opened a gap). The dragged row drops its `button` role, so match text. |
| 103 | + const placeholder = page |
| 104 | + .locator("#sidebar") |
| 105 | + .getByText(timed, { exact: false }); |
| 106 | + await expect(placeholder).toBeVisible(); |
| 107 | + |
| 108 | + const placeholderBox = await placeholder.boundingBox(); |
| 109 | + const aBox = await sidebarButton(page, weekA).boundingBox(); |
| 110 | + const bBox = await sidebarButton(page, weekB).boundingBox(); |
| 111 | + |
| 112 | + await page.mouse.up(); |
| 113 | + |
| 114 | + expect(placeholderBox).not.toBeNull(); |
| 115 | + expect(aBox).not.toBeNull(); |
| 116 | + expect(bBox).not.toBeNull(); |
| 117 | + |
| 118 | + if (placeholderBox && aBox && bBox) { |
| 119 | + const placeholderMid = placeholderBox.y + placeholderBox.height / 2; |
| 120 | + const aMid = aBox.y + aBox.height / 2; |
| 121 | + const bMid = bBox.y + bBox.height / 2; |
| 122 | + |
| 123 | + expect(aMid).toBeLessThan(placeholderMid); |
| 124 | + expect(placeholderMid).toBeLessThan(bMid); |
| 125 | + } |
| 126 | +}); |
| 127 | + |
| 128 | +test("snaps to the nearest Someday list when dropped between the lists", async ({ |
| 129 | + page, |
| 130 | +}) => { |
| 131 | + await prepareCalendarPage(page); |
| 132 | + await ensureSidebarOpen(page); |
| 133 | + |
| 134 | + const weekA = await createSomeday(page, "week", "Week A"); |
| 135 | + const monthM = await createSomeday(page, "month", "Month M"); |
| 136 | + const timed = await createTimed(page, "Timed T"); |
| 137 | + |
| 138 | + const start = await centerOf(page, timed, "grid"); |
| 139 | + const a = await centerOf(page, weekA, "sidebar"); |
| 140 | + const m = await centerOf(page, monthM, "sidebar"); |
| 141 | + |
| 142 | + // A point in the empty space between the week list (above) and the month |
| 143 | + // list (below), biased toward the month list so "nearest" should be Month. |
| 144 | + const gapTarget = { x: a.x, y: m.box.y - 8 }; |
| 145 | + |
| 146 | + await page.mouse.move(start.x, start.y); |
| 147 | + await page.mouse.down(); |
| 148 | + await page.mouse.move(gapTarget.x, gapTarget.y, { steps: 16 }); |
| 149 | + await page.waitForTimeout(250); |
| 150 | + |
| 151 | + await page.screenshot({ |
| 152 | + path: "test-results/repro/between-lists-mid-drag.png", |
| 153 | + }); |
| 154 | + |
| 155 | + await page.mouse.up(); |
| 156 | + await page.waitForTimeout(400); |
| 157 | + |
| 158 | + await page.screenshot({ |
| 159 | + path: "test-results/repro/between-lists-after-drop.png", |
| 160 | + }); |
| 161 | + |
| 162 | + // It should have converted to a Someday event (nearest = Month), not jumped |
| 163 | + // back onto the grid. |
| 164 | + await expect( |
| 165 | + page.locator("#mainGrid").getByRole("button", { name: timed }), |
| 166 | + ).toHaveCount(0, { timeout: 8000 }); |
| 167 | + await expect(sidebarButton(page, timed)).toBeVisible({ timeout: 8000 }); |
| 168 | +}); |
0 commit comments