-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [M3-7160] - Add AGLB "Edit Certificate" drawer (#9723)
* Initial set up, open edit drawer action * Update mock data, dynamic drawer display, and unit test * Update tests to add TODOs and skip correctly * Update payload for PUT request, update unit test * Only include key in errorFields for a downstream cert type * Add validation * Fix schema * Address feedback * Re-enable cert and key fields; add cert field validation * Add placeholder text to private key field * Address Slack feedback * Address feedback, but WIP validation * Add type so validation triggers correctly; thanks @bnussman-akamai * Address PR and UX feedback * Fix failure in load-balancer-certificates.spec.ts due to label change
- Loading branch information
Showing
11 changed files
with
351 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
...src/features/LoadBalancers/LoadBalancerDetail/Certificates/EditCertificateDrawer.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { Certificate } from '@linode/api-v4'; | ||
import { act, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import React from 'react'; | ||
|
||
import { mockCertificate } from 'src/factories'; | ||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { EditCertificateDrawer } from './EditCertificateDrawer'; | ||
|
||
const mockTLSCertificate: Certificate = { | ||
certificate: mockCertificate, | ||
id: 0, | ||
label: 'test-tls-cert', | ||
type: 'downstream', | ||
}; | ||
const mockCACertificate: Certificate = { | ||
certificate: mockCertificate, | ||
id: 0, | ||
label: 'test-ca-cert', | ||
type: 'ca', | ||
}; | ||
|
||
describe('EditCertificateDrawer', () => { | ||
it('should contain the name of the cert in the drawer title and label field', () => { | ||
const onClose = jest.fn(); | ||
|
||
const { getByLabelText, getByTestId } = renderWithTheme( | ||
<EditCertificateDrawer | ||
certificate={mockTLSCertificate} | ||
loadbalancerId={0} | ||
onClose={onClose} | ||
open | ||
/> | ||
); | ||
|
||
const labelInput = getByLabelText('Certificate Label'); | ||
|
||
expect(getByTestId('drawer-title')).toHaveTextContent( | ||
`Edit ${mockTLSCertificate.label}` | ||
); | ||
expect(labelInput).toHaveDisplayValue(mockTLSCertificate.label); | ||
}); | ||
|
||
it('should contain the cert in the cert field and placeholder text in the private key for a downstream cert', () => { | ||
const onClose = jest.fn(); | ||
|
||
const { getByLabelText } = renderWithTheme( | ||
<EditCertificateDrawer | ||
certificate={mockTLSCertificate} | ||
loadbalancerId={0} | ||
onClose={onClose} | ||
open | ||
/> | ||
); | ||
|
||
const certInput = getByLabelText('TLS Certificate'); | ||
const keyInput = getByLabelText('Private Key'); | ||
|
||
expect(certInput).toHaveDisplayValue(mockTLSCertificate.certificate.trim()); | ||
expect(keyInput).toHaveAttribute( | ||
'placeholder', | ||
'Private key is redacted for security.' | ||
); | ||
}); | ||
|
||
it('should submit and close drawer when only the label of the certificate is edited', async () => { | ||
const onClose = jest.fn(); | ||
|
||
const { getByLabelText, getByTestId } = renderWithTheme( | ||
<EditCertificateDrawer | ||
certificate={mockCACertificate} | ||
loadbalancerId={0} | ||
onClose={onClose} | ||
open | ||
/> | ||
); | ||
|
||
const labelInput = getByLabelText('Certificate Label'); | ||
const certInput = getByLabelText('Server Certificate'); | ||
|
||
expect(labelInput).toHaveDisplayValue(mockCACertificate.label); | ||
expect(certInput).toHaveDisplayValue(mockCACertificate.certificate.trim()); | ||
|
||
act(() => { | ||
userEvent.type(labelInput, 'my-updated-cert-0'); | ||
userEvent.click(getByTestId('submit')); | ||
}); | ||
|
||
await waitFor(() => expect(onClose).toBeCalled()); | ||
}); | ||
|
||
it('should submit and close drawer when both a certificate and key are included', async () => { | ||
const onClose = jest.fn(); | ||
|
||
const { getByLabelText, getByTestId } = renderWithTheme( | ||
<EditCertificateDrawer | ||
certificate={mockTLSCertificate} | ||
loadbalancerId={0} | ||
onClose={onClose} | ||
open | ||
/> | ||
); | ||
const labelInput = getByLabelText('Certificate Label'); | ||
const certInput = getByLabelText('TLS Certificate'); | ||
const keyInput = getByLabelText('Private Key'); | ||
|
||
act(() => { | ||
userEvent.type(labelInput, 'my-cert-0'); | ||
userEvent.type(certInput, 'massive cert'); | ||
userEvent.type(keyInput, 'massive key'); | ||
|
||
userEvent.click(getByTestId('submit')); | ||
}); | ||
|
||
await waitFor(() => expect(onClose).toBeCalled()); | ||
}); | ||
}); |
Oops, something went wrong.