@@ -1,7 +1,9 @@
|
||||
import React from 'react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { shallow } from 'enzyme';
|
||||
import EditorContainer from './EditorContainer';
|
||||
|
||||
jest.mock('@edx/frontend-lib-content-components', () => ({ EditorPage: () => 'HeaderTitle' }));
|
||||
|
||||
jest.mock('react-router', () => ({
|
||||
...jest.requireActual('react-router'), // use actual for all non-hook parts
|
||||
useParams: () => ({
|
||||
@@ -10,24 +12,12 @@ jest.mock('react-router', () => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
const mockRole = 'Tiny-MCE-Mock';
|
||||
jest.mock('@tinymce/tinymce-react', () => {
|
||||
const originalModule = jest.requireActual('@tinymce/tinymce-react');
|
||||
return {
|
||||
__esModule: true,
|
||||
...originalModule,
|
||||
Editor: () => <div role={mockRole} />
|
||||
,
|
||||
};
|
||||
});
|
||||
const props = { courseId: 'cOuRsEId' };
|
||||
|
||||
describe('Editor Container', () => {
|
||||
it('shows a rich text editor loading with an error', () => {
|
||||
render(<EditorContainer
|
||||
courseId="demoXDemocourse"
|
||||
/>);
|
||||
expect(screen.getByText('Cancel')).toBeTruthy();
|
||||
expect(screen.getByText('Add To Course')).toBeTruthy();
|
||||
expect(screen.findByRole(mockRole)).toBeTruthy();
|
||||
describe('snapshots', () => {
|
||||
test('rendering correctly with expected Input', () => {
|
||||
expect(shallow(<EditorContainer {...props} />)).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
14
src/editors/__snapshots__/EditorContainer.test.jsx.snap
Normal file
14
src/editors/__snapshots__/EditorContainer.test.jsx.snap
Normal file
@@ -0,0 +1,14 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Editor Container snapshots rendering correctly with expected Input 1`] = `
|
||||
<div
|
||||
className="editor-page"
|
||||
>
|
||||
<EditorPage
|
||||
blockId="company-id1"
|
||||
blockType="html"
|
||||
courseId="cOuRsEId"
|
||||
studioEndpointUrl="http://localhost:18010"
|
||||
/>
|
||||
</div>
|
||||
`;
|
||||
@@ -4,6 +4,13 @@ import '@testing-library/jest-dom';
|
||||
import '@testing-library/jest-dom/extend-expect';
|
||||
import ReactDOM from 'react-dom';
|
||||
|
||||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
import Enzyme from 'enzyme';
|
||||
import Adapter from 'enzyme-adapter-react-16';
|
||||
import 'babel-polyfill';
|
||||
|
||||
Enzyme.configure({ adapter: new Adapter() });
|
||||
|
||||
/* need to mock window for tinymce on import, as it is JSDOM incompatible */
|
||||
|
||||
Object.defineProperty(window, 'matchMedia', {
|
||||
|
||||
Reference in New Issue
Block a user