Skip to content

Commit

Permalink
refactor: add changes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyrylo Hudym-Levkovych authored and Kyrylo Hudym-Levkovych committed Mar 15, 2024
1 parent 2c22c7c commit 42e3f41
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/certificates/Certificates.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Certificates = ({ courseId }) => {

if (loadingStatus === RequestStatus.DENIED) {
return (
<div className="row justify-content-center m-6">
<div className="row justify-content-center m-6" data-testid="request-denied-placeholder">
<Placeholder />
</div>
);
Expand Down
25 changes: 25 additions & 0 deletions src/certificates/Certificates.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AppProvider } from '@edx/frontend-platform/react';
import MockAdapter from 'axios-mock-adapter';
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';

import { RequestStatus } from '../data/constants';
import { executeThunk } from '../utils';
import initializeStore from '../store';
import { getCertificatesApiUrl } from './data/api';
Expand Down Expand Up @@ -161,4 +162,28 @@ describe('Certificates', () => {
expect(queryByTestId('certificate-details')).not.toBeInTheDocument();
expect(queryByTestId('signatory')).not.toBeInTheDocument();
});

it('renders placeholder if request fails', async () => {
axiosMock
.onGet(getCertificatesApiUrl(courseId))
.reply(403, certificatesDataMock);

const { getByTestId } = renderComponent();

await executeThunk(fetchCertificates(courseId), store.dispatch);

expect(getByTestId('request-denied-placeholder')).toBeInTheDocument();
});

it('updates loading status if request fails', async () => {
axiosMock
.onGet(getCertificatesApiUrl(courseId))
.reply(404, certificatesDataMock);

renderComponent();

await executeThunk(fetchCertificates(courseId), store.dispatch);

expect(store.getState().certificates.loadingStatus).toBe(RequestStatus.FAILED);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { IntlProvider } from '@edx/frontend-platform/i18n';
import MockAdapter from 'axios-mock-adapter';
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';

import { RequestStatus } from '../../data/constants';
import { executeThunk } from '../../utils';
import initializeStore from '../../store';
import { getCertificatesApiUrl, getUpdateCertificateApiUrl } from '../data/api';
Expand Down Expand Up @@ -108,6 +109,25 @@ describe('CertificateEditForm Component', () => {
});
});

it('updates loading status if delete fails', async () => {
axiosMock.onDelete(
getUpdateCertificateApiUrl(courseId, certificatesDataMock.certificates[0].id),
).reply(404);

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.savingStatus).toBe(RequestStatus.FAILED);
});
});

it('cancel edit form', async () => {
const { getByRole } = renderComponent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const useHeaderButtons = () => {
const previewUrl = useMemo(() => {
if (!certificateWebViewUrl) { return ''; }

const url = new URL(certificateWebViewUrl, window.location.origin);
const getUrl = () => new URL(certificateWebViewUrl, window.location.origin);
const url = getUrl();

const searchParams = new URLSearchParams(url.search);
searchParams.set('preview', dropdowmItem);
Expand Down

0 comments on commit 42e3f41

Please sign in to comment.