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
151 changes: 139 additions & 12 deletions web/e2e/landing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,21 @@ test.describe('the homepage (#145)', () => {
});

test.describe('the homepage’s hero (#151)', () => {
/** The element around the heading that sways: its inline transform. */
/** The badge's transform, as the lanyard sways it (#174). */
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;
});
page.evaluate(
() =>
document.querySelector<HTMLElement>('main [data-swing]')?.style
.transform ?? null
);

/** The lanyard's tab's shift, as it sways with the badge. */
const tabOf = (page: import('@playwright/test').Page) =>
page.evaluate(
() =>
document.querySelector('main [data-tab]')?.getAttribute('transform') ??
null
);

/** Sweeps the mouse right across the badge, in small steps. */
async function sweep(page: import('@playwright/test').Page) {
Expand Down Expand Up @@ -151,30 +157,151 @@ test.describe('the homepage’s hero (#151)', () => {
});
}

test('sways the badge with the mouse, then lets it settle', async ({
test('swings in, settles, then sways with the mouse and settles (#174)', 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('');
// It arrives swinging, then hangs straight within about six seconds.
expect(await swayOf(page)).toMatch(/rotate\(/);
await expect.poll(() => swayOf(page), { timeout: 9000 }).toBe('');
await sweep(page);
await expect
.poll(() => swayOf(page), { timeout: 2000 })
.toMatch(/^rotate\(-?[\d.]+deg\)$/);
.toMatch(/^translateX\(-?[\d.]+px\) rotate\(-?[\d.]+deg\)$/);
// The lanyard sways with it, a little.
expect(await tabOf(page)).toMatch(/^translate\(-?[\d.]+ 0\)$/);
// A few degrees at most, and still again after about six seconds.
const angle = Number(/-?[\d.]+/.exec((await swayOf(page)) ?? '')?.[0]);
const angle = Number(
/rotate\((-?[\d.]+)/.exec((await swayOf(page)) ?? '')?.[1]
);
expect(Math.abs(angle)).toBeLessThan(5);
await expect.poll(() => swayOf(page), { timeout: 9000 }).toBe('');
expect(await tabOf(page)).toBeNull();
});

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();
// No swing as it arrives, and none for the mouse.
expect(await swayOf(page)).toBe('');
await sweep(page);
await page.waitForTimeout(300);
expect(await swayOf(page)).toBe('');
});
});

test.describe('the homepage badge, turned over to sign in (#175)', () => {
/** The badge's two faces, front then back. */
const faces = (page: import('@playwright/test').Page) =>
page.locator('main [data-face] > [data-sleeve]');

test('turns over to the form, at the same size, and back again', async ({
page,
}) => {
await page.setViewportSize({ width: 1440, height: 900 });
await page.goto('/');
const turning = page.locator('main [data-face]');
await expect(turning).toHaveAttribute('data-face', 'front');
// It turns, rather than jumping.
expect(
await turning.evaluate(
(element) => getComputedStyle(element).transitionDuration
)
).toBe('0.7s');

await page
.getByRole('banner')
.getByRole('link', { name: 'Sign in' })
.click();
await expect(page).toHaveURL('/sign-in');
await expect(turning).toHaveAttribute('data-face', 'back');
await expect(page.getByRole('heading', SIGN_IN)).toBeFocused();
await page.waitForTimeout(800);
// Front and back are one size, so the turn is convincing.
const [front, back] = await Promise.all([
faces(page).nth(0).boundingBox(),
faces(page).nth(1).boundingBox(),
]);
expect(back?.width).toBeCloseTo(front?.width ?? 0, 0);
expect(back?.height).toBeCloseTo(front?.height ?? 0, 0);
await expect(
page.getByRole('combobox', { name: 'Your handle' })
).toBeVisible();
await expect(page.getByRole('heading', { name: HEADING })).toHaveCount(0);

await page.goBack();
await expect(page).toHaveURL('/');
await expect(turning).toHaveAttribute('data-face', 'front');
await expect(page.getByRole('heading', { name: HEADING })).toBeFocused();
await expect(page.getByRole('combobox')).toHaveCount(0);
});

test('turns over at once with reduced motion', async ({ page }) => {
await page.emulateMedia({ reducedMotion: 'reduce' });
await page.goto('/sign-in');
const turning = page.locator('main [data-face]');
await expect(turning).toHaveAttribute('data-face', 'back');
expect(
await turning.evaluate(
(element) => getComputedStyle(element).transitionDuration
)
).toBe('0s');
});

test('shows every suggestion for a handle, past the badge’s edge (#176)', async ({
page,
}) => {
await page.route(
'https://public.api.bsky.app/xrpc/app.bsky.actor.searchActorsTypeahead**',
(route) =>
route.fulfill({
json: {
actors: Array.from({ length: 8 }, (_, index) => ({
did: `did:plc:suggestion${index}aaaaaaaaaaaaaa`,
handle: `ren${index}.bsky.social`,
displayName: `Ren ${index}`,
})),
},
})
);
// On a phone the form is at the badge's foot, so the list hangs out.
await page.setViewportSize({ width: 390, height: 844 });
await page.goto('/sign-in');
await page.getByRole('combobox', { name: 'Your handle' }).fill('ren');
const listbox = page.getByRole('listbox');
await expect(listbox.getByRole('option')).toHaveCount(8);
await listbox.evaluate((element) =>
element.scrollIntoView({ block: 'end' })
);
// Nothing it sits in clips it, however tall it grows.
const clippers = await listbox.evaluate((element) => {
const found: string[] = [];
for (
let parent = element.parentElement;
parent && parent !== document.body;
parent = parent.parentElement
) {
const { overflowY } = getComputedStyle(parent);
if (overflowY !== 'visible')
found.push(`${parent.tagName}: ${overflowY}`);
}
return found;
});
expect(clippers).toEqual([]);
const box = await listbox.boundingBox();
// Its foot is its own: nothing covers it.
const foot = await page.evaluate(
({ x, y }) =>
Boolean(document.elementFromPoint(x, y)?.closest('[role="listbox"]')),
{
x: (box?.x ?? 0) + (box?.width ?? 0) / 2,
y: (box?.y ?? 0) + (box?.height ?? 0) - 4,
}
);
expect(foot).toBe(true);
});
});
28 changes: 28 additions & 0 deletions web/e2e/qr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,34 @@ test.describe('QR sheet', () => {
await expect(sheet).toBeHidden();
});

test('sways with the mouse, as the homepage’s does, then settles (#174)', async ({
page,
}) => {
await page.setViewportSize({ width: 1440, height: 900 });
await page.goto('/lanyard');
await page.getByRole('link', { name: 'Share' }).click();
const sheet = page.getByRole('dialog', { name: 'Dr Ada Example' });
const sleeve = sheet.locator('[data-sleeve]');
// Straight as it opens: the code is there to be scanned.
expect(await sleeve.evaluate((element) => element.style.transform)).toBe(
''
);
const box = await sleeve.boundingBox();
const y = (box?.y ?? 0) + (box?.height ?? 0) * 0.7;
await page.mouse.move((box?.x ?? 0) + 10, y);
await page.mouse.move((box?.x ?? 0) + (box?.width ?? 0) - 10, y, {
steps: 12,
});
await expect
.poll(() => sleeve.evaluate((element) => element.style.transform))
.toMatch(/rotate\(/);
await expect
.poll(() => sleeve.evaluate((element) => element.style.transform), {
timeout: 9000,
})
.toBe('');
});

test('stays black on white in dark mode', async ({ page }) => {
await page.emulateMedia({ colorScheme: 'dark' });
await page.goto('/lanyard');
Expand Down
16 changes: 16 additions & 0 deletions web/e2e/settings.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, test } from './fixtures';
import { ADA, mockPerson, signIn } from './mocks';

test('sends signed-out visitors to sign in first', async ({ page }) => {
await page.goto('/settings');
Expand All @@ -8,3 +9,18 @@ test('sends signed-out visitors to sign in first', async ({ page }) => {
).toBeVisible();
await expect(page.getByRole('button', { name: 'Sign in' })).toBeVisible();
});

test('signing out goes to the homepage (#172)', async ({ page }) => {
await mockPerson(page);
await signIn(page, { did: ADA.did, scope: 'atproto transition:generic' });
await page.goto('/settings');
await page.getByRole('button', { name: 'Sign out' }).click();
await expect(page.getByText('Signed out')).toBeVisible();
await expect(page).toHaveURL('/');
await expect(
page.getByRole('heading', { level: 1, name: 'Welcome to Lanyards' })
).toBeVisible();
await expect(
page.getByRole('banner').getByRole('link', { name: 'Sign in' })
).toBeVisible();
});
11 changes: 8 additions & 3 deletions web/src/app/customise.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,14 @@ describe('/<handle>/edit', { timeout: 20_000 }, () => {
expect(grounds()).toHaveLength(1);
const [ground] = grounds();
expect(ground).toContainElement(region);
expect(ground).toContainElement(
screen.getByRole('heading', { level: 1, name: 'Customise your lanyard' })
);
const heading = screen.getByRole('heading', {
level: 1,
name: 'Customise your lanyard',
});
expect(ground).toContainElement(heading);
// For screen readers only: the lanyard hangs from the canvas's top
// edge, and the header already says Customise (#173).
expect(heading).toHaveClass('sr-only');
});

it('shows only its own header, with the customiser’s actions', async () => {
Expand Down
46 changes: 45 additions & 1 deletion web/src/app/landing.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { screen, within } from '@testing-library/react';
import { screen, waitFor, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { http, HttpResponse } from 'msw';
import { beforeEach, describe, expect, it, vi } from 'vitest';

Expand Down Expand Up @@ -48,7 +49,11 @@ describe('landing page', () => {
expect(
await screen.findByRole('heading', { name: 'Welcome to Lanyards' })
).toBeInTheDocument();
// The form is on the badge's back, out of reach until it turns (#175).
expect(screen.queryByRole('combobox')).toBeNull();
expect(
screen.getByRole('combobox', { hidden: true }).closest('[inert]')
).not.toBeNull();
expect(screen.queryByRole('button', { name: 'Sign in' })).toBeNull();
expect(document.title).toBe(
'Researcher profiles on the AT Protocol · Lanyards'
Expand Down Expand Up @@ -88,6 +93,45 @@ describe('landing page', () => {
expect(document.title).toBe('Sign in · Lanyards');
});

it('turns the homepage badge over to sign in, and back (#175)', async () => {
vi.mocked(useSession).mockReturnValue({
status: 'signedOut',
signOut: vi.fn(),
refresh: vi.fn(),
});
const { router } = renderRoute('/');
const welcome = await screen.findByRole('heading', {
name: 'Welcome to Lanyards',
});
// One badge, two faces: the sign-in face is behind, out of reach.
const signIn = () =>
screen.getByRole('heading', { level: 1, name: 'Sign in', hidden: true });
expect(welcome.closest('[inert]')).toBeNull();
expect(signIn().closest('[inert]')).not.toBeNull();

const banner = screen.getByRole('banner');
await userEvent.click(
await within(banner).findByRole('link', { name: 'Sign in' })
);
await waitForRoute(router, '/sign-in');
// The same badge, turned over: nothing was rebuilt.
await waitFor(() => expect(welcome.closest('[inert]')).not.toBeNull());
expect(welcome).toBeInTheDocument();
expect(signIn().closest('[inert]')).toBeNull();
expect(signIn()).toHaveFocus();
expect(document.title).toBe('Sign in · Lanyards');
expect(within(banner).queryByRole('link', { name: 'Sign in' })).toBeNull();

router.history.back();
await waitForRoute(router, '/');
await waitFor(() => expect(welcome.closest('[inert]')).toBeNull());
expect(signIn().closest('[inert]')).not.toBeNull();
expect(welcome).toHaveFocus();
expect(document.title).toBe(
'Researcher profiles on the AT Protocol · Lanyards'
);
});

// Links from before the sign-in page had its own address (#157).
it('sends /?returnTo= on to /sign-in, keeping where to return', async () => {
vi.mocked(useSession).mockReturnValue({
Expand Down
Loading
Loading