From 349a9d367386946f217fab14e1bbde3b507655ab Mon Sep 17 00:00:00 2001 From: hided62 Date: Fri, 21 Aug 2026 02:34:41 +0000 Subject: [PATCH] =?UTF-8?q?test(frontend):=20=EB=AA=A8=EB=B0=94=EC=9D=BC?= =?UTF-8?q?=20=ED=84=B0=EC=B9=98=20=EB=93=9C=EB=9E=98=EA=B7=B8=20=EC=A2=8C?= =?UTF-8?q?=ED=91=9C=EB=A5=BC=20=EC=95=88=EC=A0=95=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/game-frontend/e2e/npcPolicy.spec.ts | 1 - app/game-frontend/e2e/touchDrag.ts | 114 +++++++++++++----- .../src/components/ui/SortableStringList.ts | 2 - 3 files changed, 83 insertions(+), 34 deletions(-) diff --git a/app/game-frontend/e2e/npcPolicy.spec.ts b/app/game-frontend/e2e/npcPolicy.spec.ts index d4b2fe43..97e0b2ab 100644 --- a/app/game-frontend/e2e/npcPolicy.spec.ts +++ b/app/game-frontend/e2e/npcPolicy.spec.ts @@ -344,7 +344,6 @@ test('physical mobile touch reorders NPC priority across active and inactive lis const nationPanel = mobilePage.locator('.priority-panel').first(); const activeList = nationPanel.locator('.priority-column').nth(1).locator('.priority-list'); const activeRows = activeList.locator('.priority-item'); - await expect(activeRows.first()).toHaveCSS('touch-action', 'none'); await touchDrag( mobilePage, activeRows.nth(0), diff --git a/app/game-frontend/e2e/touchDrag.ts b/app/game-frontend/e2e/touchDrag.ts index c79bcb99..11b607fb 100644 --- a/app/game-frontend/e2e/touchDrag.ts +++ b/app/game-frontend/e2e/touchDrag.ts @@ -9,15 +9,27 @@ type TouchDragOptions = { targetYRatio?: number; }; -const pointIn = async (locator: Locator, yRatio = 0.5): Promise => { - const box = await locator.boundingBox(); - if (!box) { - throw new Error('Touch drag target has no visible bounding box'); +const pointInStable = async (locator: Locator, yRatio = 0.5): Promise => { + let previous: TouchPoint | null = null; + for (let attempt = 0; attempt < 5; attempt += 1) { + await locator.evaluate( + () => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve()))) + ); + const box = await locator.boundingBox(); + if (!box) { + throw new Error('Touch drag target has no visible bounding box'); + } + const point = { + x: box.x + box.width / 2, + y: box.y + box.height * yRatio, + }; + if (previous && Math.abs(previous.x - point.x) < 0.25 && Math.abs(previous.y - point.y) < 0.25) { + return point; + } + previous = point; } - return { - x: box.x + box.width / 2, - y: box.y + box.height * yRatio, - }; + if (!previous) throw new Error('Touch drag target did not produce a stable point'); + return previous; }; export const touchDrag = async ( @@ -26,25 +38,66 @@ export const touchDrag = async ( target: Locator, options: TouchDragOptions = {} ): Promise => { - await source.scrollIntoViewIfNeeded(); - await target.scrollIntoViewIfNeeded(); - const from = await pointIn(source); - const to = await pointIn(target, options.targetYRatio); const cdp = await page.context().newCDPSession(page); - await page.evaluate(() => { - document.documentElement.removeAttribute('data-playwright-touch-trusted'); - document.addEventListener( - 'touchstart', - (event) => document.documentElement.setAttribute('data-playwright-touch-trusted', String(event.isTrusted)), - { capture: true, once: true } - ); - }); + let from: TouchPoint | null = null; + let to: TouchPoint | null = null; + + for (let attempt = 0; attempt < 2; attempt += 1) { + await source.scrollIntoViewIfNeeded(); + await target.scrollIntoViewIfNeeded(); + from = await pointInStable(source); + to = await pointInStable(target, options.targetYRatio); + await page.evaluate(() => { + for (const element of document.querySelectorAll('[data-playwright-touch-source]')) { + element.removeAttribute('data-playwright-touch-source'); + } + }); + await source.evaluate((element) => element.setAttribute('data-playwright-touch-source', '')); + await page.evaluate(() => { + document.documentElement.removeAttribute('data-playwright-touch-trusted'); + document.documentElement.removeAttribute('data-playwright-touch-source-hit'); + document.addEventListener( + 'touchstart', + (event) => { + const sourceElement = document.querySelector('[data-playwright-touch-source]'); + document.documentElement.setAttribute('data-playwright-touch-trusted', String(event.isTrusted)); + document.documentElement.setAttribute( + 'data-playwright-touch-source-hit', + String(event.target instanceof Node && sourceElement?.contains(event.target)) + ); + }, + { capture: true, once: true } + ); + }); + + await cdp.send('Input.dispatchTouchEvent', { + type: 'touchStart', + touchPoints: [{ ...from, id: 0, radiusX: 1, radiusY: 1, force: 1 }], + }); + await page.waitForTimeout(50); + const startState = await page.evaluate(() => ({ + trusted: document.documentElement.getAttribute('data-playwright-touch-trusted') === 'true', + sourceHit: document.documentElement.getAttribute('data-playwright-touch-source-hit') === 'true', + })); + if (!startState.trusted) { + throw new Error('Chromium did not dispatch a trusted touchstart event'); + } + if (startState.sourceHit) break; + + await cdp.send('Input.dispatchTouchEvent', { type: 'touchCancel', touchPoints: [] }); + await page.evaluate(() => { + for (const element of document.querySelectorAll('[data-playwright-touch-source]')) { + element.removeAttribute('data-playwright-touch-source'); + } + }); + from = null; + to = null; + } + + if (!from || !to) { + throw new Error('Trusted touchstart did not land on the requested drag source'); + } - await cdp.send('Input.dispatchTouchEvent', { - type: 'touchStart', - touchPoints: [{ ...from, id: 0, radiusX: 1, radiusY: 1, force: 1 }], - }); - await page.waitForTimeout(50); const dispatchMove = async (ratio: number) => { await cdp.send('Input.dispatchTouchEvent', { type: 'touchMove', @@ -68,10 +121,9 @@ export const touchDrag = async ( } await page.waitForTimeout(50); await cdp.send('Input.dispatchTouchEvent', { type: 'touchEnd', touchPoints: [] }); - const trusted = await page.evaluate( - () => document.documentElement.getAttribute('data-playwright-touch-trusted') === 'true' - ); - if (!trusted) { - throw new Error('Chromium did not dispatch a trusted touchstart event'); - } + await page.evaluate(() => { + for (const element of document.querySelectorAll('[data-playwright-touch-source]')) { + element.removeAttribute('data-playwright-touch-source'); + } + }); }; diff --git a/app/game-frontend/src/components/ui/SortableStringList.ts b/app/game-frontend/src/components/ui/SortableStringList.ts index 30f17229..d5e4cbe3 100644 --- a/app/game-frontend/src/components/ui/SortableStringList.ts +++ b/app/game-frontend/src/components/ui/SortableStringList.ts @@ -105,8 +105,6 @@ export default defineComponent({ cloneVNode(node, { key: element, [SORTABLE_ITEM_ATTRIBUTE]: element, - // Prevent a long-list touch gesture from being cancelled as page scrolling. - style: [node.props?.style, { touchAction: 'none' }], }) ) );