Skip to content

Commit 61559e3

Browse files
committed
refactor(tests): address code review nitpicks
- Add comment explaining direct DOM query for skeleton detection - Add null checks before non-null assertions for safer element selection - Complete mutation mock to handle RevokeApiKeyDocument for consistency
1 parent 6493830 commit 61559e3

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

frontend/__tests__/unit/pages/ApiKeysPage.test.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ describe('ApiKeysPage Component', () => {
119119
setupMocks({ data: null, loading: true })
120120
render(<ApiKeysPage />)
121121
expect(screen.queryByText('API Key Management')).not.toBeInTheDocument()
122+
// Note: Using direct DOM query as skeleton components don't have semantic roles
122123
expect(document.querySelectorAll('.animate-pulse').length).toBeGreaterThan(0)
123124
})
124125

@@ -253,8 +254,9 @@ describe('ApiKeysPage Component', () => {
253254
describe('API Key Revocation', () => {
254255
test('revokes API key after confirmation', async () => {
255256
render(<ApiKeysPage />)
256-
const row = (await screen.findByText('mock key 1')).closest('tr')!
257-
fireEvent.click(within(row).getByRole('button'))
257+
const row = (await screen.findByText('mock key 1')).closest('tr')
258+
expect(row).not.toBeNull()
259+
fireEvent.click(within(row!).getByRole('button'))
258260

259261
const dialog = await screen.findByRole('dialog')
260262
expect(within(dialog).getByText(/Are you sure you want to revoke/)).toBeInTheDocument()
@@ -267,8 +269,9 @@ describe('ApiKeysPage Component', () => {
267269

268270
test('cancels revocation when cancel button is clicked', async () => {
269271
render(<ApiKeysPage />)
270-
const row = (await screen.findByText('mock key 1')).closest('tr')!
271-
fireEvent.click(within(row).getByRole('button'))
272+
const row = (await screen.findByText('mock key 1')).closest('tr')
273+
expect(row).not.toBeNull()
274+
fireEvent.click(within(row!).getByRole('button'))
272275

273276
const dialog = await screen.findByRole('dialog')
274277
fireEvent.click(within(dialog).getByRole('button', { name: /Cancel/i }))
@@ -322,6 +325,15 @@ describe('ApiKeysPage Component', () => {
322325
{ loading: true },
323326
]
324327
}
328+
if (mutation === RevokeApiKeyDocument) {
329+
return [
330+
createMutationFn(
331+
mockRevokeMutation,
332+
options as { onCompleted?: (data: unknown) => void }
333+
),
334+
{ loading: false },
335+
]
336+
}
325337
return [jest.fn(), { loading: false }]
326338
}
327339
mockUseMutation.mockImplementation(createLoadingMutation)

0 commit comments

Comments
 (0)