Skip to content

Commit

Permalink
test: ExportModal.test added
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Oct 20, 2023
1 parent 09aa8b6 commit 1925fae
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
53 changes: 53 additions & 0 deletions src/taxonomy/modals/ExportModal.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import { IntlProvider, injectIntl } from '@edx/frontend-platform/i18n';
import { initializeMockApp } from '@edx/frontend-platform';
import { AppProvider } from '@edx/frontend-platform/react';
import { render, fireEvent } from '@testing-library/react';
import ExportModal from './ExportModal';
import initializeStore from '../../store';
import { callExportTaxonomy } from '../api/hooks/selectors';

const onClose = jest.fn();
let store;
const taxonomyId = 1;

jest.mock('../api/hooks/selectors', () => ({
callExportTaxonomy: jest.fn(),
}));

const ExportModalComponent = () => (
<AppProvider store={store}>
<IntlProvider locale="en" messages={{}}>
<ExportModal intl={injectIntl} taxonomyId={taxonomyId} onClose={onClose} isOpen />
</IntlProvider>
</AppProvider>
);

describe('<ExportModal />', async () => {
beforeEach(async () => {
initializeMockApp({
authenticatedUser: {
userId: 3,
username: 'abc123',
administrator: true,
roles: [],
},
});
store = initializeStore();
});

it('should render the modal', () => {
const { getByText } = render(<ExportModalComponent />);
expect(getByText('Select format to export')).toBeInTheDocument();
});

it('should call export endpoint', () => {
const { getByText } = render(<ExportModalComponent />);

fireEvent.click(getByText('JSON file'));
fireEvent.click(getByText('Export'));

expect(onClose).toHaveBeenCalled();
expect(callExportTaxonomy).toHaveBeenCalledWith(taxonomyId, 'json');
});
});
1 change: 1 addition & 0 deletions src/taxonomy/taxonomy-card/TaxonomyCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const TaxonomyCard = ({ className, original, intl }) => {
setIsExportModalOpen(true);
break;
default:
/* istanbul ignore next */
break;
}
};
Expand Down
4 changes: 0 additions & 4 deletions src/taxonomy/taxonomy-card/TaxonomyCard.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import initializeStore from '../../store';

import TaxonomyCard from './TaxonomyCard';

jest.mock('../api/hooks/selectors', () => ({
useExportTaxonomyMutation: jest.fn(),
}));

let store;

const data = {
Expand Down

0 comments on commit 1925fae

Please sign in to comment.