forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: [AXIMST-510] signature edit cancel issue (#182)
Co-authored-by: Kyrylo Hudym-Levkovych <[email protected]>
- Loading branch information
1 parent
f9d8a50
commit 51c81a2
Showing
8 changed files
with
148 additions
and
16 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
117 changes: 117 additions & 0 deletions
117
src/certificates/certificate-edit-form/CertificateEditForm.test.jsx
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,117 @@ | ||
import { Provider } from 'react-redux'; | ||
import { render, waitFor, within } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { initializeMockApp } from '@edx/frontend-platform'; | ||
import { IntlProvider } from '@edx/frontend-platform/i18n'; | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||
|
||
import { executeThunk } from '../../utils'; | ||
import initializeStore from '../../store'; | ||
import { getCertificatesApiUrl, getUpdateCertificateApiUrl } from '../data/api'; | ||
import { fetchCertificates, deleteCourseCertificate, updateCourseCertificate } from '../data/thunks'; | ||
import { certificatesDataMock } from '../__mocks__'; | ||
import { MODE_STATES } from '../data/constants'; | ||
import messagesDetails from '../certificate-details/messages'; | ||
import messages from '../messages'; | ||
import CertificateEditForm from './CertificateEditForm'; | ||
|
||
let axiosMock; | ||
let store; | ||
const courseId = 'course-123'; | ||
|
||
jest.mock('@edx/frontend-platform/i18n', () => ({ | ||
...jest.requireActual('@edx/frontend-platform/i18n'), | ||
useIntl: () => ({ | ||
formatMessage: (message) => message.defaultMessage, | ||
}), | ||
})); | ||
|
||
const renderComponent = () => render( | ||
<Provider store={store}> | ||
<IntlProvider locale="en"> | ||
<CertificateEditForm courseId="course-123" /> | ||
</IntlProvider> | ||
</Provider>, | ||
); | ||
|
||
const initialState = { | ||
certificates: { | ||
certificatesData: {}, | ||
componentMode: MODE_STATES.editAll, | ||
}, | ||
}; | ||
|
||
describe('CertificatesList Component', () => { | ||
beforeEach(async () => { | ||
initializeMockApp({ | ||
authenticatedUser: { | ||
userId: 3, | ||
username: 'abc123', | ||
administrator: true, | ||
roles: [], | ||
}, | ||
}); | ||
store = initializeStore(initialState); | ||
axiosMock = new MockAdapter(getAuthenticatedHttpClient()); | ||
axiosMock | ||
.onGet(getCertificatesApiUrl(courseId)) | ||
.reply(200, certificatesDataMock); | ||
await executeThunk(fetchCertificates(courseId), store.dispatch); | ||
}); | ||
|
||
it('submits the form with updated certificate details', async () => { | ||
const courseTitleOverrideValue = 'Updated Course Title'; | ||
const signatoryNameValue = 'Updated signatory name'; | ||
const newCertificateData = { | ||
...certificatesDataMock, | ||
courseTitle: courseTitleOverrideValue, | ||
certificates: [{ | ||
...certificatesDataMock.certificates[0], | ||
signatories: [{ | ||
...certificatesDataMock.certificates[0].signatories[0], | ||
name: signatoryNameValue, | ||
}], | ||
}], | ||
}; | ||
|
||
const { getByDisplayValue, getByRole, getByPlaceholderText } = renderComponent(); | ||
|
||
userEvent.type( | ||
getByPlaceholderText(messagesDetails.detailsCourseTitleOverride.defaultMessage), | ||
courseTitleOverrideValue, | ||
); | ||
|
||
userEvent.click(getByRole('button', { name: messages.saveTooltip.defaultMessage })); | ||
|
||
axiosMock.onPost( | ||
getUpdateCertificateApiUrl(courseId, certificatesDataMock.certificates[0].id), | ||
).reply(200, newCertificateData); | ||
await executeThunk(updateCourseCertificate(courseId, newCertificateData), store.dispatch); | ||
|
||
await waitFor(() => { | ||
expect(getByDisplayValue( | ||
certificatesDataMock.certificates[0].courseTitle + courseTitleOverrideValue, | ||
)).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('deletes a certificate and updates the store', async () => { | ||
axiosMock.onDelete( | ||
getUpdateCertificateApiUrl(courseId, certificatesDataMock.certificates[0].id), | ||
).reply(200); | ||
|
||
const { getByRole } = renderComponent(); | ||
|
||
userEvent.click(getByRole('button', { name: messages.deleteTooltip.defaultMessage })); | ||
|
||
const confirmDeleteModal = getByRole('dialog'); | ||
userEvent.click(within(confirmDeleteModal).getByRole('button', { name: messages.deleteTooltip.defaultMessage })); | ||
|
||
await executeThunk(deleteCourseCertificate(courseId, certificatesDataMock.certificates[0].id), store.dispatch); | ||
|
||
await waitFor(() => { | ||
expect(store.getState().certificates.certificatesData.certificates.length).toBe(0); | ||
}); | ||
}); | ||
}); |
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