|
12 | 12 | * at every sample; a flick hands its presentation velocity to the settle; |
13 | 13 | * a finger that lands on a settling row catches it without a jump; the |
14 | 14 | * settle keeps advancing through a blocked main thread; the drag and the |
15 | | - * settle do no Layout or Paint per frame; a storyboard of the drag and the |
16 | | - * settle. |
| 15 | + * settle do no Layout or Paint per frame; a tap on a resting row's own |
| 16 | + * content closes it and clicks nothing, and a scroll that starts on it |
| 17 | + * closes it; a storyboard of the drag and the settle. |
17 | 18 | * @position Interaction proofs of Item's swipeActions (the shape of |
18 | 19 | * BottomSheetDetent.interaction.browser.spec.ts, the harness exemplar). The |
19 | 20 | * row moves by the individual `translate` property (the compositor |
@@ -42,6 +43,7 @@ import { |
42 | 43 | seekAnimations, |
43 | 44 | springStep, |
44 | 45 | startScreencast, |
| 46 | + tap, |
45 | 47 | thawTimers, |
46 | 48 | timeline, |
47 | 49 | touchDriver, |
@@ -522,6 +524,117 @@ test('the settle keeps advancing every frame while the main thread is blocked', |
522 | 524 | expect(proof.monotonic).toBe(true); |
523 | 525 | }); |
524 | 526 |
|
| 527 | +/** A held drag on `open`'s row past half its panel: it rests open. Resolves with the open width. */ |
| 528 | +async function restOpen({driver, row, entries, start}: OpenRow) { |
| 529 | + const openWidth = await entries.evaluate( |
| 530 | + node => (node as HTMLElement).offsetWidth, |
| 531 | + ); |
| 532 | + await driver.play(heldDrag(start, -130)); |
| 533 | + await expect.poll(async () => xOf(row)).toBeCloseTo(-openWidth, 0); |
| 534 | + return openWidth; |
| 535 | +} |
| 536 | + |
| 537 | +/** |
| 538 | + * A tap through the engine's own tap path where clicks are concerned: WebKit's |
| 539 | + * Linux build synthesises a click only from its tap gesture, not from injected |
| 540 | + * touch events (the gesture system's browser tests note the same). |
| 541 | + */ |
| 542 | +async function engineTap( |
| 543 | + page: Page, |
| 544 | + browserName: string, |
| 545 | + driver: TouchDriver, |
| 546 | + at: {x: number; y: number}, |
| 547 | +) { |
| 548 | + if (browserName === 'webkit') { |
| 549 | + await page.touchscreen.tap(Math.round(at.x), Math.round(at.y)); |
| 550 | + } else { |
| 551 | + await driver.play(tap(at)); |
| 552 | + } |
| 553 | +} |
| 554 | + |
| 555 | +/** Counts the clicks that reach `row` (capture, before the row's own handlers). */ |
| 556 | +async function countClicks(row: Locator) { |
| 557 | + await row.evaluate(node => { |
| 558 | + const counter = {clicks: 0}; |
| 559 | + Object.assign(window, {__rowClicks: counter}); |
| 560 | + node.addEventListener( |
| 561 | + 'click', |
| 562 | + () => { |
| 563 | + counter.clicks += 1; |
| 564 | + }, |
| 565 | + true, |
| 566 | + ); |
| 567 | + }); |
| 568 | + return async () => |
| 569 | + row |
| 570 | + .page() |
| 571 | + .evaluate( |
| 572 | + () => |
| 573 | + (window as unknown as {__rowClicks: {clicks: number}}).__rowClicks |
| 574 | + .clicks, |
| 575 | + ); |
| 576 | +} |
| 577 | + |
| 578 | +test('a tap on the resting row’s own content closes it, and no click reaches the row', async ({ |
| 579 | + page, |
| 580 | + browserName, |
| 581 | +}) => { |
| 582 | + const open = await openRow(page); |
| 583 | + const {driver, row, rest} = open; |
| 584 | + await restOpen(open); |
| 585 | + const clicks = await countClicks(row); |
| 586 | + // On the row's own content, clear of the open panel at its trailing end. |
| 587 | + const content = {x: rest.x + 60, y: rest.y + rest.height / 2}; |
| 588 | + await engineTap(page, browserName, driver, content); |
| 589 | + await expect.poll(async () => xOf(row)).toBeCloseTo(0, 0); |
| 590 | + await page.waitForTimeout(400); |
| 591 | + expect(await clicks()).toBe(0); |
| 592 | + // The same tap on the closed row is the row's own. |
| 593 | + await engineTap(page, browserName, driver, content); |
| 594 | + await expect.poll(clicks).toBe(1); |
| 595 | +}); |
| 596 | + |
| 597 | +test('a scroll that starts on the resting row closes it', async ({ |
| 598 | + page, |
| 599 | + browserName, |
| 600 | +}) => { |
| 601 | + test.skip( |
| 602 | + browserName === 'webkit', |
| 603 | + 'WebKit’s Linux build cannot scroll from injected touches; Mobile Safari on the simulator covers it', |
| 604 | + ); |
| 605 | + await openStory(page, storybook(), 'core-item--swipe-actions'); |
| 606 | + const driver = await touchDriver(page); |
| 607 | + // A row low on the page, and room below the list to scroll into. |
| 608 | + await page.evaluate(() => { |
| 609 | + document.body.style.minHeight = '3000px'; |
| 610 | + }); |
| 611 | + const row = page.locator('.astryx-item').nth(4); |
| 612 | + await expect(row.locator('[data-swipe-panel="trailing"]')).toBeAttached(); |
| 613 | + const entries = row.locator('[data-swipe-panel="trailing"] > div > div'); |
| 614 | + const rest = await row.boundingBox(); |
| 615 | + if (rest == null) { |
| 616 | + throw new Error('no row'); |
| 617 | + } |
| 618 | + await restOpen({ |
| 619 | + driver, |
| 620 | + row, |
| 621 | + entries, |
| 622 | + panel: row.locator('[data-swipe-panel="trailing"]'), |
| 623 | + track: row.locator('[data-swipe-panel="trailing"] > div'), |
| 624 | + rest, |
| 625 | + start: {x: rest.x + rest.width - 24, y: rest.y + rest.height / 2}, |
| 626 | + }); |
| 627 | + // Up from the row's own content: the page scrolls, and the row closes. |
| 628 | + const from = {x: rest.x + 60, y: rest.y + rest.height / 2}; |
| 629 | + await driver.play( |
| 630 | + drag(from, {x: from.x, y: from.y - 200}, {durationMs: 300, hz: 60}), |
| 631 | + ); |
| 632 | + await expect |
| 633 | + .poll(async () => page.evaluate(() => scrollY)) |
| 634 | + .toBeGreaterThan(50); |
| 635 | + await expect.poll(async () => xOf(row)).toBeCloseTo(0, 0); |
| 636 | +}); |
| 637 | + |
525 | 638 | test('the drag and the settle do no Layout or Paint per frame', async ({ |
526 | 639 | page, |
527 | 640 | browserName, |
@@ -642,6 +755,46 @@ test( |
642 | 755 | }, |
643 | 756 | ); |
644 | 757 |
|
| 758 | +test( |
| 759 | + 'storyboard: a tap on the open row’s content closes it', |
| 760 | + {tag: '@storyboard'}, |
| 761 | + async ({page, browserName}, testInfo) => { |
| 762 | + const open = await openRow(page); |
| 763 | + const {driver, row, rest} = open; |
| 764 | + await restOpen(open); |
| 765 | + await installTimerGate(page); |
| 766 | + const clip = { |
| 767 | + x: 0, |
| 768 | + y: Math.max(0, rest.y - 8), |
| 769 | + width: page.viewportSize()?.width ?? 402, |
| 770 | + height: rest.height + 16, |
| 771 | + }; |
| 772 | + await engineTap(page, browserName, driver, { |
| 773 | + x: rest.x + 60, |
| 774 | + y: rest.y + rest.height / 2, |
| 775 | + }); |
| 776 | + await waitForAnimation(row); |
| 777 | + await freezeTimers(page); |
| 778 | + const {storyboard} = await animationStoryboard(page, { |
| 779 | + name: 'item-swipe-tap-closes', |
| 780 | + clip, |
| 781 | + scope: row, |
| 782 | + measure: async () => ({x: await xOf(row)}), |
| 783 | + times: timeline((await motionOf(row, 0)).ms + 50, 1000 / 30), |
| 784 | + columns: 6, |
| 785 | + cellScale: 0.6, |
| 786 | + }); |
| 787 | + await releaseAnimations(page, {finish: true}); |
| 788 | + await thawTimers(page); |
| 789 | + await storyboard.write(testInfo); |
| 790 | + const xs = storyboard.frames.map(f => f.data.x as number); |
| 791 | + // From open to closed without a step back: the settle spring, from rest. |
| 792 | + expect(xs[0]).toBeLessThan(-100); |
| 793 | + expect(xs.every((x, i) => i === 0 || x >= xs[i - 1] - 0.5)).toBe(true); |
| 794 | + expect(xs.at(-1)).toBeCloseTo(0, 0); |
| 795 | + }, |
| 796 | +); |
| 797 | + |
645 | 798 | test( |
646 | 799 | 'storyboard: a flick opens the row and a finger catches it mid-settle', |
647 | 800 | {tag: '@storyboard'}, |
|
0 commit comments