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
2 changes: 1 addition & 1 deletion web/api/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function readIndex(): Promise<string> {
return index;
}

/** /@:handle and /d/:did, with person-specific link-preview meta. */
/** /:handle and /d/:did, with person-specific link-preview meta. */
export const GET = createMetaHandler({
readIndex,
baseUrl: process.env.PUBLIC_BASE_URL,
Expand Down
78 changes: 60 additions & 18 deletions web/e2e/customise.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,28 +389,70 @@ test.describe('lanyard customiser', () => {
expect(lanyardSaves(writes)[0]?.hidden).toEqual([]);
});

test('switches to View as public and back', async ({ page }) => {
test('moves between Customise and View from the top bar (#150)', async ({
page,
}) => {
await openCustomiser(page);
const sidebar = page.getByRole('complementary', { name: 'Style' });
await expect(sidebar).toBeVisible();
await page.getByRole('button', { name: 'View as public' }).click();
const nav = page
.getByRole('banner')
.getByRole('navigation', { name: 'Your Lanyards' });
await expect(nav.getByRole('link', { name: 'Customise' })).toHaveAttribute(
'aria-current',
'page'
);
await nav.getByRole('link', { name: 'View' }).click();
await expect(page).toHaveURL(/\/alice\.test$/);
await expect(sidebar).toBeHidden();
await expect(
page.getByText('You’re seeing your lanyard as the public sees it.')
).toBeVisible();
await expect(page.getByRole('switch', { name: 'Show Links' })).toBeHidden();
await expect(
page.getByRole('button', { name: 'View as public' })
).toHaveAttribute('aria-pressed', 'true');
await page.getByRole('button', { name: 'Edit' }).click();
await expect(nav.getByRole('link', { name: 'View' })).toHaveAttribute(
'aria-current',
'page'
);
await nav.getByRole('link', { name: 'Customise' }).click();
await expect(page).toHaveURL(/\/alice\.test\/edit$/);
await expect(sidebar).toBeVisible();
});

test('gives phones a bottom bar, Show QR first among equals (#150)', async ({
page,
}) => {
await page.setViewportSize({ width: 320, height: 640 });
await openCustomiser(page);
const bar = page.getByRole('navigation', { name: 'Your Lanyards' });
// Only the bottom bar's: the top bar's links are hidden on phones.
await expect(bar).toHaveCount(1);
const box = await bar.boundingBox();
expect((box?.y ?? 0) + (box?.height ?? 0)).toBeCloseTo(640, 0);
const widths: Record<string, number> = {};
for (const name of ['Customise', 'View', 'Show QR', 'Your account']) {
const link = bar.getByRole('link', { name });
await expect(link).toBeVisible();
widths[name] = (await link.boundingBox())?.width ?? 0;
}
expect(widths['Show QR']).toBeGreaterThan(
Math.max(
widths.Customise ?? 0,
widths.View ?? 0,
widths['Your account'] ?? 0
)
);
expect(
await page.evaluate(() => document.documentElement.scrollWidth)
).toBeLessThanOrEqual(320);
await bar.getByRole('link', { name: 'Show QR' }).click();
await expect(page).toHaveURL(/\/alice\.test\/share$/);
});

test('asks before leaving unsaved changes: a link, Back and reload', async ({
page,
}) => {
await page.goto('/settings');
await page.getByRole('link', { name: 'My lanyard' }).click();
await page
.getByRole('banner')
.getByRole('link', { name: 'Customise' })
.click();
await expect(
page.getByRole('button', { name: 'Reorder Links' })
).toBeEnabled();
Expand All @@ -424,25 +466,23 @@ test.describe('lanyard customiser', () => {
await page.getByRole('link', { name: 'Lanyards' }).click();
await page.goBack();
await expect.poll(() => dialogs).toEqual(['confirm', 'confirm']);
await expect(page).toHaveURL(/\/lanyard$/);
await expect(page).toHaveURL(/\/alice\.test\/edit$/);
// Dismissing the prompt cancels the reload, so don't wait for a load.
await page.evaluate(() => window.location.reload());
await expect.poll(() => dialogs).toContain('beforeunload');
await expect(page.locator('html')).toHaveAttribute('data-accent', 'mint');
});

test('never hides keyboard focus under the phone toolbar', async ({
page,
}) => {
test('never hides keyboard focus under the bottom bar', async ({ page }) => {
await page.setViewportSize({ width: 390, height: 844 });
await openCustomiser(page);
const toolbar = page.getByRole('toolbar', { name: 'Customiser' });
const toolbar = page.getByRole('navigation', { name: 'Your Lanyards' });
const hidden: string[] = [];
for (let step = 0; step < 120; step += 1) {
await page.keyboard.press('Tab');
const covered = await page.evaluate(() => {
const focused = document.activeElement as HTMLElement | null;
const bar = document.querySelector('[role="toolbar"]');
const bar = document.querySelector('[data-bottom-toolbar]');
if (!focused || !bar || bar.contains(focused)) return null;
// Tabbing past the last control returns to the page itself.
if (focused === document.body) return null;
Expand Down Expand Up @@ -531,8 +571,10 @@ test.describe('lanyard customiser', () => {
await expect(
page.getByRole('complementary', { name: 'Style' })
).toBeHidden();
const toolbar = page.getByRole('toolbar', { name: 'Customiser' });
const style = toolbar.getByRole('button', { name: 'Style' });
// On phones, Style is in the top bar (#150).
const style = page
.getByRole('banner')
.getByRole('button', { name: 'Style' });
await style.click();
const sheet = page.getByRole('dialog', { name: 'Style' });
await expect(sheet).toBeVisible();
Expand Down
6 changes: 3 additions & 3 deletions web/e2e/feedback.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ test.describe('feedback (#134)', () => {

// On phones, support is at the foot of the Style sheet.
await page
.getByRole('toolbar', { name: 'Customiser' })
.getByRole('banner')
.getByRole('button', { name: 'Style' })
.click();
const sheet = page.getByRole('dialog', { name: 'Style' });
Expand Down Expand Up @@ -162,7 +162,7 @@ test.describe('feedback (#134)', () => {
await expect(form.getByRole('img', { name: 'Screenshot 1' })).toBeVisible();
await form.getByLabel('Describe screenshot 1').fill('The QR sheet');
await form.getByLabel('Include technical details').check();
await expect(form.locator('pre')).toContainText('Page: /lanyard');
await expect(form.locator('pre')).toContainText('Page: /alice.test/edit');

// Nothing in the dialog spills sideways at 320 px.
const overflow = await page.evaluate(
Expand Down Expand Up @@ -200,7 +200,7 @@ test.describe('feedback (#134)', () => {
expect(post?.record.body).toContain(
'On my phone the bottom of the code is hidden.'
);
expect(post?.record.body).toContain('Page: /lanyard');
expect(post?.record.body).toContain('Page: /alice.test/edit');
});

test('captures the page without the dialog over it', async ({ page }) => {
Expand Down
2 changes: 1 addition & 1 deletion web/e2e/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { test as base, expect } from '@playwright/test';
export const HEADING = 'Welcome to Lanyards';

/** The homepage's live sample lanyard (#145), framed at `md` and up. */
export const SAMPLE_PATH = '/@renderg.host';
export const SAMPLE_PATH = '/renderg.host';

const APP_ORIGIN = 'http://127.0.0.1:4173';

Expand Down
86 changes: 86 additions & 0 deletions web/e2e/landing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,89 @@ test.describe('the homepage (#145)', () => {
await expect(handle).toBeInViewport();
});
});

test.describe('the homepage’s hero (#151)', () => {
/** The element around the heading that sways: its inline transform. */
const swayOf = (page: import('@playwright/test').Page) =>
page.evaluate(() => {
let element = document.querySelector<HTMLElement>('main h1');
while (element && !element.classList.contains('origin-top')) {
element = element.parentElement;
}
return element?.style.transform ?? null;
});

/** Sweeps the mouse right across the badge, in small steps. */
async function sweep(page: import('@playwright/test').Page) {
const box = await page
.getByRole('heading', { name: HEADING })
.boundingBox();
const y = (box?.y ?? 0) + (box?.height ?? 0) / 2;
await page.mouse.move((box?.x ?? 0) + 10, y);
await page.mouse.move((box?.x ?? 0) + (box?.width ?? 0) - 10, y, {
steps: 12,
});
}

for (const colorScheme of ['light', 'dark'] as const) {
test(`sets the header straight on the blue (${colorScheme})`, async ({
page,
}) => {
await page.emulateMedia({ colorScheme });
await page.setViewportSize({ width: 1440, height: 900 });
await page.goto('/');
await expect(page.getByRole('heading', { name: HEADING })).toBeVisible();
const banner = page.getByRole('banner');
await expect(banner.getByRole('link', { name: 'Sign in' })).toBeVisible();
// No bar: nothing painted behind it, and the hero starts under it.
expect(
await banner.evaluate(
(header) => getComputedStyle(header).backgroundColor
)
).toBe('rgba(0, 0, 0, 0)');
expect((await banner.boundingBox())?.y).toBe(0);
const ground = await page.evaluate(() => {
const hero = document.querySelector('main section');
const stage = hero?.firstElementChild;
if (!stage) return null;
return {
top: stage.getBoundingClientRect().top,
colour: getComputedStyle(stage).backgroundColor,
};
});
expect(ground).toEqual({ top: 0, colour: 'rgb(64, 32, 223)' });
const results = await new AxeBuilder({ page })
.include('header')
.withTags(WCAG)
.analyze();
expect(results.violations).toEqual([]);
});
}

test('sways the badge with the mouse, then lets it settle', async ({
page,
}) => {
await page.setViewportSize({ width: 1440, height: 900 });
await page.goto('/');
await expect(page.getByRole('heading', { name: HEADING })).toBeVisible();
expect(await swayOf(page)).toBe('');
await sweep(page);
await expect
.poll(() => swayOf(page), { timeout: 2000 })
.toMatch(/^rotate\(-?[\d.]+deg\)$/);
// Never more than a couple of degrees.
const angle = Number(/-?[\d.]+/.exec((await swayOf(page)) ?? '')?.[0]);
expect(Math.abs(angle)).toBeLessThan(2);
await expect.poll(() => swayOf(page), { timeout: 8000 }).toBe('');
});

test('keeps the badge still with reduced motion', async ({ page }) => {
await page.emulateMedia({ reducedMotion: 'reduce' });
await page.setViewportSize({ width: 1440, height: 900 });
await page.goto('/');
await expect(page.getByRole('heading', { name: HEADING })).toBeVisible();
await sweep(page);
await page.waitForTimeout(300);
expect(await swayOf(page)).toBe('');
});
});
Loading
Loading