Skip to content

Commit 5f203b3

Browse files
committed
e2e test for token list page
1 parent a636089 commit 5f203b3

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed

app/pages/settings/AccessTokensPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default function AccessTokensPage() {
7070
colHelper.accessor('id', {
7171
header: () => (
7272
<>
73-
ID{' '}
73+
ID
7474
<TipIcon className="ml-1.5">
7575
A database ID for the token record, not the bearer token itself.
7676
</TipIcon>

mock-api/token.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ import type { Json } from './json-type'
1212
export const deviceTokens: Json<DeviceAccessToken>[] = [
1313
{
1414
id: '6e762538-dd89-454e-b6e7-82a199b6e51a',
15-
time_created: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString(), // 7 days ago
16-
time_expires: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString(), // 30 days from now
15+
time_created: '2025-05-27T15:11:00Z',
16+
time_expires: '2025-07-03T15:11:00Z',
1717
},
1818
{
1919
id: '9c858b30-bb11-4596-8c5e-c2bf1a26843e',
20-
time_created: new Date(Date.now() - 14 * 24 * 60 * 60 * 1000).toISOString(), // 14 days ago
21-
time_expires: new Date(Date.now() + 60 * 24 * 60 * 60 * 1000).toISOString(), // 60 days from now
20+
time_created: '2025-05-20T15:11:00Z',
21+
time_expires: '2025-08-02T15:11:00Z',
2222
},
2323
{
2424
id: '29b1d980-e0d3-4318-b714-4a1f3e7b191f',
25-
time_created: new Date(Date.now() - 3 * 24 * 60 * 60 * 1000).toISOString(), // 3 days ago
26-
time_expires: null, // Never expires
25+
time_created: '2025-05-31T15:11:00Z',
26+
time_expires: null,
2727
},
2828
]

test/e2e/access-tokens.e2e.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
5+
*
6+
* Copyright Oxide Computer Company
7+
*/
8+
9+
import { expect, test } from '@playwright/test'
10+
11+
import { clickRowAction, expectRowVisible } from './utils'
12+
13+
const token1 = '6e762538-dd89-454e-b6e7-82a199b6e51a'
14+
const token2 = '9c858b30-bb11-4596-8c5e-c2bf1a26843e'
15+
const token3 = '29b1d980-e0d3-4318-b714-4a1f3e7b191f'
16+
17+
test('Access tokens', async ({ page }) => {
18+
await page.goto('/')
19+
20+
await page.getByLabel('User menu').click()
21+
await page.getByRole('menuitem', { name: 'Settings' }).click()
22+
await page.getByRole('link', { name: 'Access Tokens' }).click()
23+
24+
await expect(page.getByRole('heading', { name: 'Access Tokens' })).toBeVisible()
25+
26+
const table = page.getByRole('table')
27+
await expectRowVisible(table, {
28+
ID: token1,
29+
created: expect.stringContaining('May 27, 2025'),
30+
Expires: expect.stringContaining('Jul 3, 2025'),
31+
})
32+
await expectRowVisible(table, {
33+
ID: token2,
34+
created: expect.stringContaining('May 20, 2025'),
35+
Expires: expect.stringContaining('Aug 2, 2025'),
36+
})
37+
await expectRowVisible(table, {
38+
ID: token3,
39+
created: expect.stringContaining('May 31, 2025'),
40+
Expires: 'Never',
41+
})
42+
43+
// Delete a token
44+
await clickRowAction(page, token1, 'Delete')
45+
await expect(page.getByRole('dialog').getByText('Cannot be undone')).toBeVisible()
46+
await page.getByRole('button', { name: 'Confirm' }).click()
47+
48+
// Token should be gone
49+
await expect(page.getByRole('cell', { name: token1 })).toBeHidden()
50+
51+
// Other two tokens should still be there
52+
await expectRowVisible(table, { ID: token2 })
53+
await expectRowVisible(table, { ID: token3 })
54+
})

0 commit comments

Comments
 (0)