|
1 |
| -import 'CourseAuthoring/editors/setupEditorTest'; |
2 |
| -import { shallow } from '@edx/react-unit-test-utils'; |
3 |
| - |
4 |
| -import { formatMessage } from '../../testUtils'; |
| 1 | +import { render, initializeMocks } from '@src/testUtils'; |
5 | 2 | import VideoEditor from '.';
|
| 3 | +import * as hooks from './hooks'; |
| 4 | + |
| 5 | +const reduxSelectors = require('../../data/redux').selectors; |
6 | 6 |
|
7 | 7 | jest.mock('../EditorContainer', () => 'EditorContainer');
|
8 | 8 | jest.mock('./components/VideoEditorModal', () => 'VideoEditorModal');
|
9 | 9 |
|
10 |
| -jest.mock('./hooks', () => ({ |
11 |
| - ErrorContext: { |
12 |
| - Provider: 'ErrorContext.Provider', |
13 |
| - }, |
14 |
| - errorsHook: jest.fn(() => ({ |
15 |
| - error: 'hooks.errorsHook.error', |
16 |
| - validateEntry: jest.fn().mockName('validateEntry'), |
17 |
| - })), |
18 |
| - fetchVideoContent: jest.fn().mockName('fetchVideoContent'), |
19 |
| -})); |
20 |
| - |
21 |
| -jest.mock('../../data/redux', () => ({ |
22 |
| - selectors: { |
23 |
| - requests: { |
24 |
| - isFinished: jest.fn((state, params) => ({ isFailed: { state, params } })), |
25 |
| - }, |
26 |
| - app: { |
27 |
| - isLibrary: jest.fn(state => ({ isLibrary: state })), |
28 |
| - }, |
29 |
| - }, |
30 |
| -})); |
31 |
| - |
32 |
| -jest.mock('@openedx/paragon', () => ({ |
33 |
| - ...jest.requireActual('@openedx/paragon'), |
34 |
| - Spinner: 'Spinner', |
35 |
| -})); |
36 |
| - |
37 | 10 | describe('VideoEditor', () => {
|
38 | 11 | const props = {
|
39 | 12 | onClose: jest.fn().mockName('props.onClose'),
|
40 |
| - intl: { formatMessage }, |
41 |
| - studioViewFinished: false, |
42 |
| - isLibrary: false, |
| 13 | + returnFunction: jest.fn().mockName('props.returnFunction'), |
43 | 14 | };
|
44 |
| - describe('snapshots', () => { |
45 |
| - test('renders as expected with default behavior', () => { |
46 |
| - expect(shallow(<VideoEditor {...props} />).snapshot).toMatchSnapshot(); |
| 15 | + |
| 16 | + describe('conditional rendering', () => { |
| 17 | + let isFinishedSpy: jest.SpyInstance; |
| 18 | + let isLibrarySpy: jest.SpyInstance; |
| 19 | + let shouldCreateBlockSpy: jest.SpyInstance; |
| 20 | + let errorsHookSpy: jest.SpyInstance; |
| 21 | + let fetchVideoContentSpy: jest.SpyInstance; |
| 22 | + |
| 23 | + beforeEach(() => { |
| 24 | + isFinishedSpy = jest.spyOn(reduxSelectors.requests, 'isFinished'); |
| 25 | + isLibrarySpy = jest.spyOn(reduxSelectors.app, 'isLibrary'); |
| 26 | + shouldCreateBlockSpy = jest.spyOn(reduxSelectors.app, 'shouldCreateBlock'); |
| 27 | + errorsHookSpy = jest.spyOn(hooks, 'errorsHook'); |
| 28 | + fetchVideoContentSpy = jest.spyOn(hooks, 'fetchVideoContent'); |
| 29 | + errorsHookSpy.mockReturnValue({ error: null, validateEntry: jest.fn() }); |
| 30 | + fetchVideoContentSpy.mockReturnValue(jest.fn()); |
| 31 | + isLibrarySpy.mockReturnValue(false); |
| 32 | + initializeMocks(); |
| 33 | + }); |
| 34 | + |
| 35 | + afterEach(() => { |
| 36 | + jest.clearAllMocks(); |
| 37 | + }); |
| 38 | + |
| 39 | + test('shows spinner when neither create workflow nor studio view finished', () => { |
| 40 | + isFinishedSpy.mockReturnValue(false); |
| 41 | + shouldCreateBlockSpy.mockReturnValue(false); |
| 42 | + const { container } = render(<VideoEditor {...props} />); |
| 43 | + expect(container.querySelector('.pgn__spinner')).toBeInTheDocument(); |
| 44 | + expect(container.querySelector('EditorContainer')).toBeInTheDocument(); |
| 45 | + expect(container.querySelector('VideoEditorModal')).not.toBeInTheDocument(); |
| 46 | + }); |
| 47 | + |
| 48 | + test('shows VideoEditorModal when isCreateWorkflow is true', () => { |
| 49 | + isFinishedSpy.mockReturnValue(false); |
| 50 | + shouldCreateBlockSpy.mockReturnValue(true); |
| 51 | + const { container } = render(<VideoEditor {...props} />); |
| 52 | + expect(container.querySelector('.pgn__spinner')).not.toBeInTheDocument(); |
| 53 | + expect(container.querySelector('EditorContainer')).toBeInTheDocument(); |
| 54 | + expect(container.querySelector('VideoEditorModal')).toBeInTheDocument(); |
| 55 | + }); |
| 56 | + |
| 57 | + test('shows VideoEditorModal when studioViewFinished is true', () => { |
| 58 | + isFinishedSpy.mockReturnValue(true); |
| 59 | + shouldCreateBlockSpy.mockReturnValue(false); |
| 60 | + |
| 61 | + const { container } = render(<VideoEditor {...props} />); |
| 62 | + expect(container.querySelector('.pgn__spinner')).not.toBeInTheDocument(); |
| 63 | + expect(container.querySelector('EditorContainer')).toBeInTheDocument(); |
| 64 | + expect(container.querySelector('VideoEditorModal')).toBeInTheDocument(); |
| 65 | + }); |
| 66 | + |
| 67 | + test('passes isLibrary, onClose, and returnFunction to VideoEditorModal', () => { |
| 68 | + isFinishedSpy.mockReturnValue(true); |
| 69 | + shouldCreateBlockSpy.mockReturnValue(false); |
| 70 | + isLibrarySpy.mockReturnValue(true); |
| 71 | + |
| 72 | + const { container } = render(<VideoEditor {...props} />); |
| 73 | + expect(container.querySelector('.video-editor')).toBeInTheDocument(); |
| 74 | + }); |
| 75 | + |
| 76 | + test('calls fetchVideoContent and passes validateEntry to EditorContainer', () => { |
| 77 | + isFinishedSpy.mockReturnValue(true); |
| 78 | + shouldCreateBlockSpy.mockReturnValue(false); |
| 79 | + |
| 80 | + render(<VideoEditor {...props} />); |
| 81 | + expect(fetchVideoContentSpy).toHaveBeenCalled(); |
| 82 | + expect(errorsHookSpy).toHaveBeenCalled(); |
47 | 83 | });
|
48 | 84 | });
|
49 | 85 | });
|
0 commit comments