chore: Add tests for CertificateList and CertificateUploadDialog components

- Implement test to deselect a row checkbox in CertificateList by clicking it a second time.
- Add test to close detail dialog via the close button in CertificateList.
- Add test to close export dialog via the cancel button in CertificateList.
- Add test to show KEY format badge when a .key file is uploaded in CertificateUploadDialog.
- Add test to ensure no format badge is shown for unknown file extensions in CertificateUploadDialog.
This commit is contained in:
GitHub Actions
2026-04-15 11:35:10 +00:00
parent fb8d80f6a3
commit 8239a94938
10 changed files with 3334 additions and 1724 deletions
@@ -440,4 +440,40 @@ describe('CertificateList', () => {
await user.click(within(customRow).getByTestId('export-cert-cert-1'))
expect(await screen.findByRole('dialog')).toBeInTheDocument()
})
it('deselects a row checkbox by clicking it a second time', async () => {
const user = userEvent.setup()
renderWithClient(<CertificateList />)
const rows = await screen.findAllByRole('row')
const customRow = rows.find(r => r.textContent?.includes('CustomCert'))!
const checkbox = within(customRow).getByRole('checkbox')
await user.click(checkbox)
expect(screen.getByRole('status')).toBeInTheDocument()
await user.click(checkbox)
await waitFor(() => expect(screen.queryByRole('status')).not.toBeInTheDocument())
})
it('closes detail dialog via the dialog close button', async () => {
const user = userEvent.setup()
renderWithClient(<CertificateList />)
const rows = await screen.findAllByRole('row')
const customRow = rows.find(r => r.textContent?.includes('CustomCert'))!
await user.click(within(customRow).getByTestId('view-cert-cert-1'))
const dialog = await screen.findByRole('dialog')
expect(dialog).toBeInTheDocument()
await user.click(within(dialog).getByRole('button', { name: 'Close' }))
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
})
it('closes export dialog via the cancel button', async () => {
const user = userEvent.setup()
renderWithClient(<CertificateList />)
const rows = await screen.findAllByRole('row')
const customRow = rows.find(r => r.textContent?.includes('CustomCert'))!
await user.click(within(customRow).getByTestId('export-cert-cert-1'))
const dialog = await screen.findByRole('dialog')
expect(dialog).toBeInTheDocument()
await user.click(within(dialog).getByRole('button', { name: 'common.cancel' }))
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
})
})
@@ -384,4 +384,26 @@ describe('CertificateUploadDialog', () => {
expect(screen.queryByTestId('certificate-validation-preview')).toBeFalsy()
})
})
it('shows KEY format badge when .key file is uploaded', async () => {
const user = userEvent.setup({ applyAccept: false })
renderDialog()
const certInput = document.getElementById('cert-file') as HTMLInputElement
const file = new File(['key-data'], 'server.key', { type: 'application/x-pem-file' })
await user.upload(certInput, file)
expect(await screen.findByText('KEY')).toBeTruthy()
})
it('shows no format badge for unknown file extension', async () => {
const user = userEvent.setup({ applyAccept: false })
renderDialog()
const certInput = document.getElementById('cert-file') as HTMLInputElement
const file = new File(['data'], 'cert.bin', { type: 'application/octet-stream' })
await user.upload(certInput, file)
await screen.findByText('cert.bin')
expect(screen.queryByText('KEY')).toBeNull()
expect(screen.queryByText('DER')).toBeNull()
expect(screen.queryByText('PFX/PKCS#12')).toBeNull()
expect(screen.queryByText('PEM')).toBeNull()
})
})