Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions e2e/accessibility.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,27 +453,28 @@ test.describe('Accessibility - prefers-reduced-motion', () => {
await page.emulateMedia({ reducedMotion: 'reduce' });

// Emulate BEFORE navigation so the @media query resolves at first
// paint and the override applies the moment .reply-fade children
// paint and reduced-motion behavior applies the moment replies
// mount on expand.
await page.goto('/#/item/12345');

// Wait for the top-level comment to mount, then expand its reply
// tree. Mock data: comment 1001 (patio11) has child 2001 (tptacek).
await expect(page.getByText('patio11').first()).toBeVisible({ timeout: 10000 });
await page.getByText(/1 reply/i).first().click();
await expect(page.getByText('tptacek').first()).toBeVisible();

// Override target is `.reply-fade > *` (the inner Comment), NOT
// the .reply-fade wrapper itself. The wrapper has to stay opaque
// because it carries `.tree-branch::before` + `.tree-branch--last
// ::after` — the trunk connector and trunk-end mask. If the
// selector ever drifts (the rule and the override are paired in
// src/index.css and easy to evolve out of sync), AT users get
// opacity:0 replies and the cascade animation they opted out of,
// on every expand.
const replyChild = page.locator('.reply-fade > *').first();
await expect(replyChild).toBeAttached();

const replyAuthor = page.getByRole('link', { name: 'tptacek' }).first();
await expect(replyAuthor).toBeVisible();

// Reduced-motion users should never pass through the transient
// `.reply-fade` state. The branch stays mounted, so asserting on
// the branch that owns the visible reply is stable even if the DOM
// is slow.
const replyBranch = replyAuthor.locator('xpath=ancestor::div[contains(@class, "tree-branch")][1]');
await expect(replyBranch).not.toHaveClass(/reply-fade/);

// The inner Comment row remains the element that would animate in
// motion-enabled mode, so we still verify it rests at the reduced-
// motion contract: `animation-name:none` and `opacity:1`.
const replyChild = replyBranch.locator(':scope > .comment-row').first();
const replyStyles = await replyChild.evaluate((el) => {
const style = getComputedStyle(el);
return { animationName: style.animationName, opacity: style.opacity };
Expand Down
92 changes: 79 additions & 13 deletions e2e/comment-swipe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
import { test, expect } from '@playwright/test';
import { setupApiMocks } from './fixtures/api-mocks';
import { waitForSwipeReady, smoothScrollAndAwaitSettled, waitForScrollAtIndex } from './fixtures/swipe-helpers';
import {
expectActiveSwipePanelText,
waitForSwipeReady,
smoothScrollAndAwaitSettled,
waitForScrollAtIndex,
} from './fixtures/swipe-helpers';

async function getSwipeScrollbarTranslateY(page: Parameters<typeof test>[0]['page']) {
return page.evaluate(() => {
const transform = getComputedStyle(document.body, '::after').transform;

if (!transform || transform === 'none') {
return 0;
}

const match = transform.match(/^matrix(3d)?\((.+)\)$/);
if (!match) {
return 0;
}

const values = match[2]
.split(',')
.map((value) => Number.parseFloat(value.trim()));

return match[1] === '3d'
? (values[13] ?? 0)
: (values[5] ?? 0);
});
}

test.describe('Mobile Comment Swipe Viewer', () => {
test.use({
Expand All @@ -23,7 +51,7 @@ test.describe('Mobile Comment Swipe Viewer', () => {
// that fallback path.
await page.goto('/#/item/1001');

await expect(page.getByText('patio11').first()).toBeVisible({ timeout: 10000 });
await expectActiveSwipePanelText(page, 'patio11', { timeout: 10000 });

await expect(page).toHaveURL(/\/item\/1001/, { timeout: 5000 });
});
Expand All @@ -34,9 +62,9 @@ test.describe('Mobile Comment Swipe Viewer', () => {
const swipeContainer = page.getByTestId('swipe-container');
await expect(swipeContainer).toBeVisible();

await expect(page.getByText('patio11').first()).toBeVisible({ timeout: 10000 });
await expectActiveSwipePanelText(page, 'patio11', { timeout: 10000 });

await expect(page.getByText(/wasm-bindgen/i).first()).toBeVisible();
await expectActiveSwipePanelText(page, /wasm-bindgen/i);
});

test('loads sibling comments as swipeable panels', async ({ page }) => {
Expand All @@ -61,7 +89,45 @@ test.describe('Mobile Comment Swipe Viewer', () => {
await waitForScrollAtIndex(page, 1);
await expect(page).toHaveURL(/\/item\/1002/, { timeout: 5000 });

await expect(page.getByText('jgrahamc').first()).toBeVisible({ timeout: 10000 });
await expectActiveSwipePanelText(page, 'jgrahamc', { minPanels: 4, timeout: 10000 });
});

test('custom swipe scrollbar moves when document scrolls in comment viewer', async ({ page }) => {
await page.goto('/#/item/1002');

await waitForSwipeReady(page, 4);
await waitForScrollAtIndex(page, 1);
await expect(page).toHaveURL(/\/item\/1002/, { timeout: 5000 });

await page.evaluate(() => {
const activePanel = document.querySelector('[data-testid="swipe-panel"].active');
if (activePanel) {
(activePanel as HTMLElement).style.minHeight = `${window.innerHeight + 1200}px`;
}
});

await expect(async () => {
const isScrollable = await page.evaluate(() => {
return document.documentElement.scrollHeight > window.innerHeight;
});
expect(isScrollable).toBe(true);
}).toPass();

const initialTranslateY = await getSwipeScrollbarTranslateY(page);

await page.evaluate(() => {
window.scrollTo(0, 300);
});

await expect.poll(
() => page.evaluate(() => window.scrollY),
{ timeout: 5000 },
).toBeGreaterThanOrEqual(250);

await expect.poll(
() => getSwipeScrollbarTranslateY(page),
{ timeout: 5000 },
).toBeGreaterThan(initialTranslateY + 5);
});

test('can swipe through multiple siblings and back', async ({ page }) => {
Expand Down Expand Up @@ -92,18 +158,18 @@ test.describe('Mobile Comment Swipe Viewer', () => {
test('shows parent and story links in comment', async ({ page }) => {
await page.goto('/#/item/1001');

await expect(page.getByText('patio11').first()).toBeVisible({ timeout: 10000 });
await expectActiveSwipePanelText(page, 'patio11', { timeout: 10000 });

const parentLink = page.getByRole('link', { name: 'parent' }).first();
await expect(parentLink).toBeVisible();

await expect(page.getByText('Rust Is the Future of JavaScript Infrastructure').first()).toBeVisible();
await expectActiveSwipePanelText(page, 'Rust Is the Future of JavaScript Infrastructure');
});

test('header shows "comments" indicator on mobile comment view', async ({ page }) => {
await page.goto('/#/item/1001');

await expect(page.getByText('patio11').first()).toBeVisible({ timeout: 10000 });
await expectActiveSwipePanelText(page, 'patio11', { timeout: 10000 });

await expect(page.getByText('comments').first()).toBeVisible();
});
Expand Down Expand Up @@ -133,7 +199,7 @@ test.describe('Mobile Comment Swipe Viewer', () => {
test('in-panel links have correct hrefs and comments indicator clears when leaving comment view', async ({ page }) => {
await page.goto('/#/item/1001');

await expect(page.getByText('patio11').first()).toBeVisible({ timeout: 10000 });
await expectActiveSwipePanelText(page, 'patio11', { timeout: 10000 });
await expect(page.getByText('comments').first()).toBeVisible();

const firstPanel = page.locator('[data-item-id="1001"]');
Expand Down Expand Up @@ -248,7 +314,7 @@ test.describe('Mobile Comment Swipe Viewer', () => {
test('sets document title to "Comment by {author}" for the current comment', async ({ page }) => {
await page.goto('/#/item/1001');

await expect(page.getByText('patio11').first()).toBeVisible({ timeout: 10000 });
await expectActiveSwipePanelText(page, 'patio11', { timeout: 10000 });

await expect(page).toHaveTitle(/Comment by patio11/);
});
Expand Down Expand Up @@ -283,7 +349,7 @@ test.describe('Mobile Comment Swipe Viewer', () => {
await smoothScrollAndAwaitSettled(container, panelWidth);
await waitForScrollAtIndex(page, 1);
await expect(page).toHaveURL(/\/item\/1002/, { timeout: 5000 });
await expect(page.getByText('jgrahamc').first()).toBeVisible({ timeout: 10000 });
await expectActiveSwipePanelText(page, 'jgrahamc', { minPanels: 4, timeout: 10000 });

const panel1002 = page.locator('[data-item-id="1002"]');
await panel1002.getByRole('link', { name: 'parent' }).click();
Expand All @@ -297,14 +363,14 @@ test.describe('Mobile Comment Swipe Viewer', () => {
// link must carry isComment: true and land in SwipeCommentViewer for 1001.
await page.goto('/#/item/2001');

await expect(page.getByText('tptacek').first()).toBeVisible({ timeout: 10000 });
await expectActiveSwipePanelText(page, 'tptacek', { timeout: 10000 });

await page.getByRole('link', { name: 'parent' }).click();
await expect(page).toHaveURL(/\/item\/1001/, { timeout: 10000 });

// 1001's siblings are [1001, 1002, 1003, 1004] → confirms we're in the
// comment viewer with the correct sibling set.
await expect(page.getByText('patio11').first()).toBeVisible({ timeout: 10000 });
await expectActiveSwipePanelText(page, 'patio11', { minPanels: 4, timeout: 10000 });
await expect(page).toHaveTitle(/Comment by patio11/);

await waitForSwipeReady(page, 4);
Expand Down
19 changes: 14 additions & 5 deletions e2e/domain-filter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { test, expect } from '@playwright/test';
import { setupApiMocks, stubEmptyDomainSearch } from './fixtures/api-mocks';
import { ALGOLIA_API } from './fixtures/mock-data';
import { waitForSwipeReady, smoothScrollAndAwaitSettled, waitForScrollAtIndex } from './fixtures/swipe-helpers';
import {
expectActiveSwipePanelText,
waitForSwipeReady,
smoothScrollAndAwaitSettled,
waitForScrollAtIndex,
} from './fixtures/swipe-helpers';

test.describe('Domain Filter', () => {
test.beforeEach(async ({ page }) => {
Expand Down Expand Up @@ -270,7 +275,10 @@ test.describe('Domain Filter - Mobile Swipe', () => {
// mockDomainItem + 4 clones = 5 panels total; we just need ≥2 for snap.
await waitForSwipeReady(page, 2);

await expect(page.getByText('Google Announces Gemini 3.0 with Extended Context').first()).toBeVisible({ timeout: 10000 });
await expectActiveSwipePanelText(page, 'Google Announces Gemini 3.0 with Extended Context', {
minPanels: 2,
timeout: 10000,
});
});

test('updates URL to /item/:id and carries fromDomain state on swipe', async ({ page }) => {
Expand Down Expand Up @@ -406,9 +414,10 @@ test.describe('Domain Filter - Mobile Swipe', () => {

// Story renders inside the swipe viewer after recovery. `.first()`
// because the title may also render in the document title bar.
await expect(
page.getByText('Google Announces Gemini 3.0 with Extended Context').first(),
).toBeVisible({ timeout: 10000 });
await expectActiveSwipePanelText(page, 'Google Announces Gemini 3.0 with Extended Context', {
minPanels: 1,
timeout: 10000,
});
});
});

Expand Down
41 changes: 41 additions & 0 deletions e2e/fixtures/swipe-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import type { Page, Locator } from '@playwright/test';
import { expect } from '@playwright/test';

interface ActiveSwipeTextOptions {
minPanels?: number;
timeout?: number;
}

/**
* Wait for swipe container to be ready with multiple panels.
* Verifies container visibility, minimum panel count, rendered dimensions,
Expand All @@ -27,6 +32,42 @@ export async function waitForSwipeReady(page: Page, minPanels = 2) {
const el = document.querySelector('[data-testid="swipe-container"]');
return el && (el as HTMLElement).dataset.swipeEnabled === 'true';
}, { timeout: 5000 });

// Some Mobile Safari route transitions attach listeners one frame before the
// viewer finishes applying its `.active` marker. Tests that scope to the
// active panel should not proceed until exactly one panel owns that state.
await page.waitForFunction(() => {
const containerEl = document.querySelector('[data-testid="swipe-container"]');
if (!containerEl) return false;

const activePanels = containerEl.querySelectorAll('[data-testid="swipe-panel"].active');
if (activePanels.length !== 1) return false;

const activePanel = activePanels[0] as HTMLElement;
return activePanel.getBoundingClientRect().width > 0;
}, { timeout: 5000 });
}

/** Returns the currently active swipe panel. */
export function getActiveSwipePanel(page: Page) {
return page.locator('[data-testid="swipe-panel"].active');
}

/**
* Assert that visible content is inside the active swipe panel, not just
* somewhere in the mounted panel stack.
*/
export async function expectActiveSwipePanelText(
page: Page,
text: string | RegExp,
{ minPanels = 1, timeout = 5000 }: ActiveSwipeTextOptions = {},
) {
await waitForSwipeReady(page, minPanels);

const activePanel = getActiveSwipePanel(page);

await expect(activePanel).toBeVisible({ timeout });
await expect(activePanel.getByText(text)).toBeVisible({ timeout });
}

/**
Expand Down
Loading