|
| 1 | +import React from 'react'; |
| 2 | +import { render, screen, initializeMocks } from '@src/testUtils'; |
| 3 | +import { formatMessage } from '@src/editors/testUtils'; |
| 4 | +import { HandoutWidgetInternal as HandoutWidget } from '.'; |
| 5 | + |
| 6 | +jest.mock('@src/editors/data/redux', () => ({ |
| 7 | + actions: { |
| 8 | + video: { |
| 9 | + updateField: jest.fn().mockName('actions.video.updateField'), |
| 10 | + }, |
| 11 | + }, |
| 12 | + selectors: { |
| 13 | + video: { |
| 14 | + getHandoutDownloadUrl: jest.fn(args => ({ getHandoutDownloadUrl: args })).mockName('selectors.video.getHandoutDownloadUrl'), |
| 15 | + handout: jest.fn(state => ({ handout: state })), |
| 16 | + }, |
| 17 | + app: { |
| 18 | + isLibrary: jest.fn(args => ({ isLibrary: args })), |
| 19 | + }, |
| 20 | + requests: { |
| 21 | + isFailed: jest.fn(args => ({ isFailed: args })), |
| 22 | + }, |
| 23 | + }, |
| 24 | +})); |
| 25 | + |
| 26 | +describe('HandoutWidget', () => { |
| 27 | + const props = { |
| 28 | + intl: { formatMessage }, |
| 29 | + isLibrary: false, |
| 30 | + handout: '', |
| 31 | + isUploadError: false, |
| 32 | + getHandoutDownloadUrl: jest.fn().mockName('args.getHandoutDownloadUrl'), |
| 33 | + updateField: jest.fn().mockName('args.updateField'), |
| 34 | + }; |
| 35 | + |
| 36 | + describe('renders', () => { |
| 37 | + beforeEach(() => { |
| 38 | + initializeMocks(); |
| 39 | + }); |
| 40 | + test('renders as expected with default props', () => { |
| 41 | + render(<HandoutWidget {...props} />); |
| 42 | + expect(screen.getByText('Handout')).toBeInTheDocument(); |
| 43 | + expect(screen.getByRole('button', { name: 'Upload Handout' })).toBeInTheDocument(); |
| 44 | + expect(screen.getByRole('button', { name: 'Handout' })).toBeInTheDocument(); |
| 45 | + expect(screen.getByRole('button', { name: 'Collapse' })).toBeInTheDocument(); |
| 46 | + }); |
| 47 | + test('renders as expected with isLibrary true', () => { |
| 48 | + const { container } = render(<HandoutWidget {...props} isLibrary />); |
| 49 | + const reduxWrapper = container.firstChild; |
| 50 | + expect(reduxWrapper?.textContent).toBe(''); |
| 51 | + expect(screen.queryByText('Handout')).not.toBeInTheDocument(); |
| 52 | + }); |
| 53 | + test('renders as expected with handout', () => { |
| 54 | + const handoutUrl = 'sOMeUrl '; |
| 55 | + render(<HandoutWidget {...props} handout={handoutUrl} />); |
| 56 | + expect(screen.getByText('Handout')).toBeInTheDocument(); |
| 57 | + expect(screen.getByText(handoutUrl.trim())).toBeInTheDocument(); |
| 58 | + }); |
| 59 | + }); |
| 60 | +}); |
0 commit comments