Skip to content

Commit de6b1e8

Browse files
heyoubclaude
authored andcommitted
test(web): cover breadcrumbs, per-row names and time elements
Regression cover for the parts of this branch that are easy to undo by accident. The breadcrumb tests assert the exact trails app-shell.md prescribes, including that the final crumb is text with aria-current rather than a link — the detail that makes a trail a trail. The Revoke test asserts that two rows produce two distinct accessible names, which is the property that actually broke, rather than asserting one label's spelling. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent ede6bf4 commit de6b1e8

3 files changed

Lines changed: 107 additions & 5 deletions

File tree

‎apps/web/tests/Account.test.tsx‎

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* by AppShell on every page), and is covered by its own test file.
66
*/
77
import { describe, expect, it, vi, afterEach } from 'vitest';
8-
import { screen, waitFor } from '@testing-library/react';
8+
import { screen, waitFor, within } from '@testing-library/react';
99
import { renderScreen, mockOk } from './test-utils.js';
1010
import { Account } from '../src/screens/Account.js';
1111
import { AuthProvider } from '../src/hooks/useAuth.js';
@@ -17,7 +17,24 @@ interface MeShape {
1717
lastLoginMethod: 'github' | 'legacy_password' | 'password_reset' | null;
1818
}
1919

20-
function mockApi(me: MeShape): void {
20+
const SESSIONS = [
21+
{
22+
jti: 'sess-1',
23+
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X) Chrome/120',
24+
ipAddress: '203.0.113.1',
25+
issuedAt: '2026-05-01T00:00:00Z',
26+
current: false,
27+
},
28+
{
29+
jti: 'sess-2',
30+
userAgent: 'Mozilla/5.0 (Windows NT 10.0) Firefox/121',
31+
ipAddress: '203.0.113.2',
32+
issuedAt: '2026-05-02T00:00:00Z',
33+
current: false,
34+
},
35+
];
36+
37+
function mockApi(me: MeShape, sessions: unknown[] = []): void {
2138
vi.spyOn(globalThis, 'fetch').mockImplementation(((input: string) => {
2239
if (input.startsWith('/api/auth/me')) {
2340
return Promise.resolve(
@@ -29,7 +46,7 @@ function mockApi(me: MeShape): void {
2946
}
3047
if (input.startsWith('/api/auth/sessions')) {
3148
return Promise.resolve(
32-
new Response(JSON.stringify(mockOk([])), {
49+
new Response(JSON.stringify(mockOk(sessions)), {
3350
status: 200,
3451
headers: { 'content-type': 'application/json' },
3552
}),
@@ -105,3 +122,38 @@ describe('Account — Identity card', () => {
105122
).toBe(0);
106123
});
107124
});
125+
126+
describe('Account — accessibility structure', () => {
127+
afterEach(() => {
128+
vi.restoreAllMocks();
129+
});
130+
131+
it('renders the "Settings" breadcrumb trail from app-shell.md', async () => {
132+
mockApi(githubPerson);
133+
render();
134+
const trail = await screen.findByRole('navigation', { name: 'Breadcrumb' });
135+
expect(within(trail).getByText('Settings')).toHaveAttribute('aria-current', 'page');
136+
});
137+
138+
it('names each Revoke button after its own session', async () => {
139+
mockApi(githubPerson, SESSIONS);
140+
render();
141+
await waitFor(() => {
142+
expect(screen.getByRole('button', { name: 'Revoke session on Chrome on macOS' }))
143+
.toBeInTheDocument();
144+
});
145+
expect(
146+
screen.getByRole('button', { name: 'Revoke session on Firefox on Windows' }),
147+
).toBeInTheDocument();
148+
// The visible text is still "Revoke" on both (SC 2.5.3 keeps it a substring).
149+
expect(screen.getAllByRole('button', { name: /^Revoke session on/ })).toHaveLength(2);
150+
});
151+
152+
it('exposes session timestamps as machine-readable <time>', async () => {
153+
mockApi(githubPerson, SESSIONS);
154+
render();
155+
await waitFor(() => {
156+
expect(document.querySelector('time[datetime="2026-05-01T00:00:00Z"]')).not.toBeNull();
157+
});
158+
});
159+
});

‎apps/web/tests/PersonDetail.test.tsx‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it, vi, afterEach } from 'vitest';
2-
import { screen, waitFor } from '@testing-library/react';
2+
import { screen, waitFor, within } from '@testing-library/react';
33
import { Routes, Route } from 'react-router';
44
import { renderScreen, mockOk } from './test-utils.js';
55
import { PersonDetail } from '../src/screens/PersonDetail.js';
@@ -42,6 +42,31 @@ function makeFetchMock(person: typeof BASE_PERSON) {
4242
}) as typeof fetch;
4343
}
4444

45+
describe('PersonDetail breadcrumbs', () => {
46+
afterEach(() => {
47+
vi.restoreAllMocks();
48+
});
49+
50+
it('renders the "Members › <fullName>" trail from app-shell.md', async () => {
51+
vi.spyOn(globalThis, 'fetch').mockImplementation(makeFetchMock(BASE_PERSON));
52+
renderScreen(
53+
<AuthProvider>
54+
<Routes>
55+
<Route path="/members/:slug" element={<PersonDetail />} />
56+
</Routes>
57+
</AuthProvider>,
58+
{ initialEntries: ['/members/jane-doe'] },
59+
);
60+
61+
const trail = await screen.findByRole('navigation', { name: 'Breadcrumb' });
62+
expect(within(trail).getByRole('link', { name: 'Members' })).toHaveAttribute(
63+
'href',
64+
'/members',
65+
);
66+
expect(within(trail).getByText('Jane Doe')).toHaveAttribute('aria-current', 'page');
67+
});
68+
});
69+
4570
describe('PersonDetail Contact sidebar', () => {
4671
afterEach(() => {
4772
vi.restoreAllMocks();

‎apps/web/tests/ProjectDetail.test.tsx‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest';
2-
import { screen, waitFor } from '@testing-library/react';
2+
import { screen, waitFor, within } from '@testing-library/react';
33
import { Routes, Route } from 'react-router';
44
import { renderScreen, mockOk, mockPaginated } from './test-utils.js';
55
import { ProjectDetail } from '../src/screens/ProjectDetail.js';
@@ -59,6 +59,31 @@ describe('ProjectDetail', () => {
5959
vi.restoreAllMocks();
6060
});
6161

62+
it('renders the "Projects › <title>" breadcrumb trail from app-shell.md', async () => {
63+
renderScreen(
64+
<AuthProvider>
65+
<Routes>
66+
<Route path="/projects/:slug" element={<ProjectDetail />} />
67+
</Routes>
68+
</AuthProvider>,
69+
{ initialEntries: ['/projects/sample-project'] },
70+
);
71+
72+
const trail = await screen.findByRole('navigation', { name: 'Breadcrumb' });
73+
expect(within(trail).getByRole('link', { name: 'Projects' })).toHaveAttribute(
74+
'href',
75+
'/projects',
76+
);
77+
// The last crumb is the current page, so it is text, not a link.
78+
expect(within(trail).getByText('Sample Project')).toHaveAttribute(
79+
'aria-current',
80+
'page',
81+
);
82+
expect(
83+
within(trail).queryByRole('link', { name: 'Sample Project' }),
84+
).not.toBeInTheDocument();
85+
});
86+
6287
it('renders the title, overview, and Sign-in CTA for anonymous', async () => {
6388
renderScreen(
6489
<AuthProvider>

0 commit comments

Comments
 (0)