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
7 changes: 3 additions & 4 deletions web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,9 @@ keep falling back to broad permissions for a few minutes after publishing.
## Deploying (`lanyards.app`)

The app deploys from the Vercel project **`lanyards`** (team `renderghost`,
Git repo `renderghost/lanyards`), with Root Directory `web`. Until the swap
(#154), that project served the legacy Next.js app from the repository root,
and the beta ran on a second project, `lanyards-next`, at
`next.lanyards.app`.
Git repo `renderghost/lanyards`), with Root Directory `web`. It was the
beta's project, `lanyards-next`, renamed at the swap (#154), when the legacy
Next.js project was deleted and `lanyards.app` moved to it.

### 1. Project settings

Expand Down
2 changes: 1 addition & 1 deletion web/e2e/callback.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test('explains a cancelled sign-in and scrubs the URL', async ({ page }) => {
expect(page.url()).not.toContain('#');
await expect(page.getByRole('link', { name: 'Try again' })).toHaveAttribute(
'href',
'/'
'/sign-in'
);
});

Expand Down
13 changes: 0 additions & 13 deletions web/e2e/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ 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';

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

/**
Expand All @@ -24,16 +21,6 @@ export const test = base.extend({
await page.route('https://public.api.bsky.app/**', (route) =>
route.fulfill({ json: { actors: [] } })
);
// The homepage frames a real person's lanyard: stand in a page, so its
// reads of that person never leave the run.
await page.route(
(url) => url.origin === APP_ORIGIN && url.pathname === SAMPLE_PATH,
(route) =>
route.fulfill({
contentType: 'text/html',
body: '<!doctype html><title>Sample lanyard</title><h1>Sample</h1>',
})
);
await use(page);
expect(unexpected, 'unexpected third-party requests').toEqual([]);
},
Expand Down
100 changes: 50 additions & 50 deletions web/e2e/landing.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import AxeBuilder from '@axe-core/playwright';

import { expect, HEADING, SAMPLE_PATH, test } from './fixtures';
import { expect, HEADING, test } from './fixtures';

const WCAG = ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa', 'wcag22aa'];

/** The sign-in page's heading (#157). */
const SIGN_IN = { level: 1, name: 'Sign in' } as const;

test('asks for a handle when submitted empty', async ({ page }) => {
await page.goto('/');
await expect(page.getByRole('heading', { name: HEADING })).toBeVisible();
await page.goto('/sign-in');
await expect(page.getByRole('heading', SIGN_IN)).toBeVisible();
await page.getByRole('button', { name: 'Sign in' }).click();
await expect(page.getByText('Enter your handle')).toBeVisible();
});
Expand All @@ -16,6 +19,11 @@ for (const colorScheme of ['light', 'dark'] as const) {
await page.emulateMedia({ colorScheme });
await page.goto('/');
await expect(page.getByRole('heading', { name: HEADING })).toBeVisible();
const home = await new AxeBuilder({ page }).withTags(WCAG).analyze();
expect(home.violations).toEqual([]);

await page.goto('/sign-in');
await expect(page.getByRole('heading', SIGN_IN)).toBeVisible();
const clean = await new AxeBuilder({ page }).withTags(WCAG).analyze();
expect(clean.violations).toEqual([]);

Expand All @@ -26,70 +34,62 @@ for (const colorScheme of ['light', 'dark'] as const) {
});
}

test('fits a 320px-wide screen without sideways scrolling', async ({
page,
}) => {
await page.setViewportSize({ width: 320, height: 640 });
await page.goto('/');
await expect(page.getByRole('heading', { name: HEADING })).toBeVisible();
const scrollWidth = await page.evaluate(
() => document.documentElement.scrollWidth
);
expect(scrollWidth).toBeLessThanOrEqual(320);
});
for (const path of ['/', '/sign-in']) {
test(`fits a 320px-wide screen without sideways scrolling (${path})`, async ({
page,
}) => {
await page.setViewportSize({ width: 320, height: 640 });
await page.goto(path);
await expect(page.getByRole('heading', { level: 1 })).toBeVisible();
const scrollWidth = await page.evaluate(
() => document.documentElement.scrollWidth
);
expect(scrollWidth).toBeLessThanOrEqual(320);
});
}

test.describe('the homepage (#145)', () => {
test('frames a sample lanyard on desktop, and links to it', async ({
test('takes Sign in at the top to the sign-in page (#157)', async ({
page,
}) => {
await page.setViewportSize({ width: 1280, height: 900 });
await page.goto('/');
await expect(page.getByRole('heading', { name: HEADING })).toBeVisible();
const frame = page.getByTitle('Sample lanyard');
await expect(frame).toBeVisible();
await expect(frame).toHaveAttribute('src', SAMPLE_PATH);
const banner = page.getByRole('banner');
await expect(
page.frameLocator('iframe[title="Sample lanyard"]').getByRole('heading')
).toHaveText('Sample');
banner.getByRole('button', { name: 'Make your lanyard' })
).toHaveCount(0);
await banner.getByRole('link', { name: 'Sign in' }).click();
await expect(page).toHaveURL('/sign-in');
await expect(page.getByRole('heading', SIGN_IN)).toBeVisible();
await expect(
page.getByRole('link', { name: /View sample profile/ })
).toHaveAttribute('href', SAMPLE_PATH);
page.getByRole('combobox', { name: 'Your handle' })
).toBeVisible();
});

test('links to the sample, without the frame, on phones', async ({
test('leads with a call to action to the sign-in page (#157)', async ({
page,
}) => {
await page.setViewportSize({ width: 320, height: 640 });
await page.goto('/');
await expect(page.getByRole('heading', { name: HEADING })).toBeVisible();
await expect(page.getByTitle('Sample lanyard')).toBeHidden();
await expect(
page.getByRole('link', { name: /View sample profile/ })
).toBeVisible();
await expect(page.getByRole('combobox')).toHaveCount(0);
await expect(page.getByTitle('Sample lanyard')).toHaveCount(0);
const start = page.getByRole('region', {
name: 'Everything you work on, in one link',
});
await start.getByRole('link', { name: 'Sign in to get started' }).click();
await expect(page).toHaveURL('/sign-in');
});

test('takes “Create your lanyard” to the sign-in form', async ({ page }) => {
test('takes “Create your lanyard” to the sign-in page', async ({ page }) => {
await page.goto('/');
await page.getByRole('button', { name: 'Create your lanyard' }).click();
const handle = page.getByRole('combobox', { name: 'Your handle' });
await expect(handle).toBeFocused();
await expect(handle).toBeInViewport();
await page.getByRole('link', { name: 'Create your lanyard' }).click();
await expect(page).toHaveURL('/sign-in');
await expect(page.getByRole('heading', SIGN_IN)).toBeVisible();
});

test('offers Sign in at the top, taking people to the form (#148)', async ({
page,
}) => {
await page.setViewportSize({ width: 1920, height: 1080 });
await page.goto('/');
const signIn = page
.getByRole('banner')
.getByRole('link', { name: 'Sign in' });
await expect(signIn).toBeInViewport();
const handle = page.getByRole('combobox', { name: 'Your handle' });
await expect(handle).not.toBeInViewport();
await signIn.click();
await expect(handle).toBeFocused();
await expect(handle).toBeInViewport();
// Old links to the homepage's sign-in (#157).
test('sends /?returnTo= on to the sign-in page', async ({ page }) => {
await page.goto('/?returnTo=%2Fsettings');
await expect(page).toHaveURL('/sign-in?returnTo=%2Fsettings');
await expect(page.getByRole('heading', SIGN_IN)).toBeVisible();
});
});

Expand Down
8 changes: 5 additions & 3 deletions web/e2e/settings.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { expect, HEADING, test } from './fixtures';
import { expect, test } from './fixtures';

test('sends signed-out visitors to sign in first', async ({ page }) => {
await page.goto('/settings');
await expect(page).toHaveURL('/?returnTo=%2Fsettings');
await expect(page.getByRole('heading', { name: HEADING })).toBeVisible();
await expect(page).toHaveURL('/sign-in?returnTo=%2Fsettings');
await expect(
page.getByRole('heading', { level: 1, name: 'Sign in' })
).toBeVisible();
await expect(page.getByRole('button', { name: 'Sign in' })).toBeVisible();
});
18 changes: 12 additions & 6 deletions web/src/app/callback.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ describe('OAuth callback, trying again', () => {
);
renderRoute('/oauth/callback#error=access_denied');
await screen.findByText('Sign-in was cancelled.');
expect(tryAgain()).toHaveAttribute('href', '/?returnTo=%2F%40alice.test');
expect(tryAgain()).toHaveAttribute(
'href',
'/sign-in?returnTo=%2F%40alice.test'
);
sessionStorage.clear();
});

Expand All @@ -54,7 +57,7 @@ describe('OAuth callback, trying again', () => {
);
renderRoute('/oauth/callback#error=access_denied');
await screen.findByText('Sign-in was cancelled.');
expect(tryAgain()).toHaveAttribute('href', '/');
expect(tryAgain()).toHaveAttribute('href', '/sign-in');
sessionStorage.clear();
});
});
Expand All @@ -68,7 +71,7 @@ describe('OAuth callback', () => {
expect(
await screen.findByText('Sign-in was cancelled.')
).toBeInTheDocument();
expect(tryAgain()).toHaveAttribute('href', '/');
expect(tryAgain()).toHaveAttribute('href', '/sign-in');
expect(completeSignIn).toHaveBeenCalledTimes(1);
expect(completeSignIn).toHaveBeenCalledWith('#error=access_denied');
expect(router.state.location.hash).toBe('');
Expand All @@ -83,13 +86,16 @@ describe('OAuth callback', () => {
vi.mocked(completeSignIn).mockRejectedValue(
new OAuthCallbackError('denied')
);
renderRoute('/oauth/callback#error=access_denied');
const { router } = renderRoute('/oauth/callback#error=access_denied');
await userEvent.click(
await screen.findByRole('link', { name: 'Try again' })
);
// Trying again goes to the sign-in page (#157), whose heading is also
// "Sign in": wait for it to replace the callback page's.
await waitForRoute(router, '/sign-in');
const heading = await screen.findByRole('heading', {
level: 1,
name: 'Welcome to Lanyards',
name: 'Sign in',
});
await waitFor(() => expect(heading).toHaveFocus());
});
Expand All @@ -104,7 +110,7 @@ describe('OAuth callback', () => {
'This sign-in link has expired or was already used.'
)
).toBeInTheDocument();
expect(tryAgain()).toHaveAttribute('href', '/');
expect(tryAgain()).toHaveAttribute('href', '/sign-in');
});

it('explains a failed exchange and reports it', async () => {
Expand Down
2 changes: 1 addition & 1 deletion web/src/app/customise.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe('/<handle>/edit', { timeout: 20_000 }, () => {
it('sends signed-out visitors to sign in, then back here', async () => {
vi.mocked(useSession).mockReturnValue(signedOutSession());
const { router } = renderRoute(EDIT);
await waitForRoute(router, `/?returnTo=${encodeURIComponent(EDIT)}`, 5000);
await waitForRoute(router, `/sign-in?returnTo=${encodeURIComponent(EDIT)}`, 5000);
});

it('forwards /lanyard to your own /<handle>/edit (#150)', async () => {
Expand Down
39 changes: 30 additions & 9 deletions web/src/app/landing.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ describe('landing page', () => {
refresh: vi.fn(),
});
renderRoute('/');
await screen.findByRole('button', { name: 'Sign in' });
await screen.findByRole('heading', { name: 'Welcome to Lanyards' });
expect(screen.queryByRole('button', { name: 'Send feedback' })).toBeNull();
expect(screen.queryByRole('button', { name: 'Give feedback' })).toBeNull();
});

it('shows the sign-in form to signed-out visitors', async () => {
it('shows signed-out visitors the homepage, with no form on it (#157)', async () => {
vi.mocked(useSession).mockReturnValue({
status: 'signedOut',
signOut: vi.fn(),
Expand All @@ -48,13 +48,14 @@ describe('landing page', () => {
expect(
await screen.findByRole('heading', { name: 'Welcome to Lanyards' })
).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Sign in' })).toBeInTheDocument();
expect(screen.queryByRole('combobox')).toBeNull();
expect(screen.queryByRole('button', { name: 'Sign in' })).toBeNull();
expect(document.title).toBe(
'Researcher profiles on the AT Protocol · Lanyards'
);
});

it('offers Sign in and Make your lanyard in the header (#148)', async () => {
it('offers Sign in in the header, to its own page (#157)', async () => {
vi.mocked(useSession).mockReturnValue({
status: 'signedOut',
signOut: vi.fn(),
Expand All @@ -64,21 +65,41 @@ describe('landing page', () => {
const banner = await screen.findByRole('banner');
expect(
await within(banner).findByRole('link', { name: 'Sign in' })
).toHaveAttribute('href', '/sign-in');
expect(
within(banner).queryByRole('button', { name: 'Make your lanyard' })
).toBeNull();
});

it('signs in on /sign-in, with the typeahead (#157)', async () => {
vi.mocked(useSession).mockReturnValue({
status: 'signedOut',
signOut: vi.fn(),
refresh: vi.fn(),
});
renderRoute('/sign-in?returnTo=%2Fsettings');
expect(
await screen.findByRole('heading', { level: 1, name: 'Sign in' })
).toBeInTheDocument();
expect(
within(banner).getByRole('button', { name: 'Make your lanyard' })
screen.getByRole('combobox', { name: 'Your handle' })
).toBeInTheDocument();
expect(screen.getAllByRole('banner')).toHaveLength(1);
expect(document.title).toBe('Sign in · Lanyards');
});

it('is titled for signing in when sent here to sign in (#145)', async () => {
// 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({
status: 'signedOut',
signOut: vi.fn(),
refresh: vi.fn(),
});
renderRoute('/?returnTo=%2Fsettings');
await screen.findByRole('heading', { name: 'Welcome to Lanyards' });
expect(document.title).toBe('Sign in · Lanyards');
const { router } = renderRoute('/?returnTo=%2Fsettings');
await waitForRoute(router, '/sign-in?returnTo=%2Fsettings');
expect(
await screen.findByRole('heading', { level: 1, name: 'Sign in' })
).toBeInTheDocument();
});

it('sends a signed-in visitor to their own customiser (#150)', async () => {
Expand Down
4 changes: 2 additions & 2 deletions web/src/app/lanyard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ describe('lanyard page states', () => {
).toBeInTheDocument();
expect(
within(screen.getByRole('main')).getByRole('link', { name: 'Sign in' })
).toHaveAttribute('href', '/?returnTo=%2Falice.test');
).toHaveAttribute('href', '/sign-in?returnTo=%2Falice.test');
expect(screen.queryByText('Dr Ada Example')).not.toBeInTheDocument();
// The name must not leak through the tab title either.
await waitFor(() =>
Expand Down Expand Up @@ -366,7 +366,7 @@ describe('visitor actions on the page', () => {
within(header).getByRole('link', { name: 'Sign in' })
).toHaveAttribute(
'href',
`/?returnTo=${encodeURIComponent('/alice.test')}`
`/sign-in?returnTo=${encodeURIComponent('/alice.test')}`
);
expect(
within(header).getByRole('button', { name: 'Make your lanyard' })
Expand Down
2 changes: 1 addition & 1 deletion web/src/app/settings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('/settings', () => {
refresh: vi.fn(),
});
const { router } = renderRoute('/settings');
await waitForRoute(router, '/?returnTo=%2Fsettings');
await waitForRoute(router, '/sign-in?returnTo=%2Fsettings');
});

it('shows the account to signed-in visitors', async () => {
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/AppHeader/AppHeader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('AppHeader', () => {
await screen.findByRole('link', { name: 'Sign in' })
).toHaveAttribute(
'href',
`/?returnTo=${encodeURIComponent('/@alice.test')}`
`/sign-in?returnTo=${encodeURIComponent('/@alice.test')}`
);
await userEvent.click(
screen.getByRole('button', { name: 'Make your lanyard' })
Expand Down
6 changes: 5 additions & 1 deletion web/src/components/AppHeader/AppHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ export function AppHeader({
} else if (signedOutActions && session.status === 'signedOut') {
end = (
<div className={styles.nav}>
<Link to="/" search={{ returnTo: path }} className={styles.navLink}>
<Link
to="/sign-in"
search={{ returnTo: path }}
className={styles.navLink}
>
{t`Sign in`}
</Link>
<Button
Expand Down
Loading
Loading