-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e420a30
commit 5587c9d
Showing
8 changed files
with
379 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { MockedProvider } from '@apollo/client/testing'; | ||
import { CERTIFICATE_LIST_MOCKS, CERTIFICATE_MOCKS } from 'mocks/Certificate'; | ||
import { MemoryRouter, Route, Routes } from 'react-router'; | ||
import CertificateList from './CertificatesList/CertificateList'; | ||
import Certificate from './Certificate'; | ||
import { fireEvent, render, screen, waitFor } from '@testing-library/react'; | ||
import * as Notification from 'common/notification'; | ||
|
||
const wrapper = ( | ||
<MockedProvider mocks={[...CERTIFICATE_LIST_MOCKS, ...CERTIFICATE_MOCKS]}> | ||
<MemoryRouter initialEntries={['/certificates']}> | ||
<Routes> | ||
<Route path="/certificates" element={<CertificateList />} /> | ||
<Route path="/certificate/add" element={<Certificate />} /> | ||
<Route path="/certificate/:id/edit" element={<Certificate />} /> | ||
</Routes> | ||
</MemoryRouter> | ||
</MockedProvider> | ||
); | ||
|
||
const notificationSpy = vi.spyOn(Notification, 'setNotification'); | ||
|
||
describe('Certificate', () => { | ||
test('should render Certificate list', async () => { | ||
render(wrapper); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText('Certificates')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
test('should edit a certificate', async () => { | ||
render(wrapper); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText('Certificates')).toBeInTheDocument(); | ||
}); | ||
|
||
fireEvent.click(screen.getAllByTestId('EditIcon')[0]); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText('Edit Certificate')).toBeInTheDocument(); | ||
}); | ||
|
||
fireEvent.change(screen.getAllByRole('textbox')[0], { target: { value: 'new label' } }); | ||
fireEvent.click(screen.getByText('Save')); | ||
|
||
await waitFor(() => { | ||
expect(notificationSpy).toBeCalledWith('Certificate edited successfully!'); | ||
}); | ||
}); | ||
|
||
test('should create a certificate', async () => { | ||
render(wrapper); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText('Certificates')).toBeInTheDocument(); | ||
}); | ||
|
||
fireEvent.click(screen.getByTestId('newItemButton')); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText('Add a new Certificate')).toBeInTheDocument(); | ||
}); | ||
|
||
const inputs = screen.getAllByRole('textbox'); | ||
|
||
fireEvent.change(inputs[0], { target: { value: 'label' } }); | ||
fireEvent.change(inputs[1], { target: { value: 'description' } }); | ||
|
||
// testing url validation | ||
fireEvent.change(inputs[2], { target: { value: 'url' } }); | ||
fireEvent.click(screen.getByText('Save')); | ||
await waitFor(() => { | ||
expect(screen.getByText('Invalid URL')).toBeInTheDocument(); | ||
}); | ||
fireEvent.change(inputs[2], { | ||
target: { | ||
value: 'https://docs.google.com/presentation/d/1fBrDFDCD2iwnaKg8sxKd45lRbqLuBFvsZbSH1sjm7aI/edit#slide=id.p', | ||
}, | ||
}); | ||
|
||
fireEvent.click(screen.getByText('Save')); | ||
|
||
await waitFor(() => { | ||
expect(notificationSpy).toBeCalledWith('Certificate created successfully!'); | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { gql } from '@apollo/client'; | ||
|
||
export const CREATE_CERTIFICATE = gql` | ||
mutation CreateCertificateTemplate($input: CertificateTemplateInput!) { | ||
createCertificateTemplate(input: $input) { | ||
certificateTemplate { | ||
label | ||
id | ||
} | ||
errors { | ||
key | ||
message | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export const UPDATE_CERTIFICATE = gql` | ||
mutation UpdateCertificateTemplate($id: ID!, $input: CertificateTemplateInput!) { | ||
updateCertificateTemplate(id: $id, input: $input) { | ||
certificateTemplate { | ||
id | ||
label | ||
} | ||
errors { | ||
message | ||
key | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export const DELETE_CERTIFICATE = gql` | ||
mutation DeleteCertificateTemplate($id: ID!) { | ||
deleteCertificateTemplate(id: $id) { | ||
certificateTemplate { | ||
label | ||
} | ||
errors { | ||
key | ||
message | ||
} | ||
} | ||
} | ||
`; |
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,37 @@ | ||
import { gql } from '@apollo/client'; | ||
|
||
export const LIST_CERTIFICATES = gql` | ||
query CertificateTemplates($filter: CertificateTemplateFilter, $opts: Opts) { | ||
certificateTemplates(filter: $filter, opts: $opts) { | ||
id | ||
description | ||
label | ||
type | ||
url | ||
} | ||
} | ||
`; | ||
|
||
export const COUNT_CERTIFICATES = gql` | ||
query RootQueryType($filter: CertificateTemplateFilter) { | ||
countCertificateTemplates(filter: $filter) | ||
} | ||
`; | ||
|
||
export const GET_CERTIFICATE = gql` | ||
query CertificateTemplate($id: ID!) { | ||
certificateTemplate(id: $id) { | ||
certificateTemplate { | ||
id | ||
label | ||
type | ||
url | ||
description | ||
} | ||
errors { | ||
message | ||
key | ||
} | ||
} | ||
} | ||
`; |
Oops, something went wrong.