diff --git a/src/components/Assessment/EditableAssessment/AssessmentActions.test.jsx b/src/components/Assessment/EditableAssessment/AssessmentActions.test.jsx index a66ca733..8fcdbb54 100644 --- a/src/components/Assessment/EditableAssessment/AssessmentActions.test.jsx +++ b/src/components/Assessment/EditableAssessment/AssessmentActions.test.jsx @@ -1,72 +1,141 @@ -import { shallow } from '@edx/react-unit-test-utils'; +import { render, screen, fireEvent } from '@testing-library/react'; +import '@testing-library/jest-dom'; -import { useExitWithoutSavingAction, useSubmitAssessmentAction } from 'hooks/actions'; +import { + useExitWithoutSavingAction, + useSubmitAssessmentAction, +} from 'hooks/actions'; import AssessmentActions from './AssessmentActions'; +/* eslint-disable react/prop-types */ + +jest.unmock('@openedx/paragon'); +jest.unmock('react'); +jest.unmock('@edx/frontend-platform/i18n'); + jest.mock('hooks/actions', () => ({ useExitWithoutSavingAction: jest.fn(), useSubmitAssessmentAction: jest.fn(), })); -jest.mock('components/ActionButton', () => 'ActionButton'); -jest.mock('components/ConfirmDialog', () => 'ConfirmDialog'); +jest.mock( + 'components/ActionButton', + () => ({ + children, variant, onClick, ...props + }) => ( + + {children} + + ), +); + +jest.mock( + 'components/ConfirmDialog', + () => ({ title, onConfirm, ...props }) => ( + e.key === 'Enter' && onConfirm()} + {...props} + /> + ), +); -describe('', () => { +describe('AssessmentActions', () => { const mockExitWithoutSavingAction = { action: { onClick: jest.fn().mockName('useExitWithoutSavingAction.onClick'), + children: 'Exit without saving', }, confirmProps: { onConfirm: jest.fn().mockName('useExitWithoutSavingAction.onConfirm'), + title: 'Exit without saving', }, }; const mockSubmitAssessmentAction = { action: { onClick: jest.fn().mockName('useSubmitAssessmentAction.onClick'), + children: 'Submit assessment', }, confirmProps: { onConfirm: jest.fn().mockName('useSubmitAssessmentAction.onConfirm'), + title: 'Submit assessment', }, }; beforeEach(() => { + jest.clearAllMocks(); useExitWithoutSavingAction.mockReturnValue(mockExitWithoutSavingAction); useSubmitAssessmentAction.mockReturnValue(mockSubmitAssessmentAction); }); - it('render default', () => { - const wrapper = shallow(); - expect(wrapper.snapshot).toMatchSnapshot(); + it('renders both action buttons and confirm dialogs', () => { + render(); - expect(wrapper.instance.findByType('ActionButton')).toHaveLength(2); - expect(wrapper.instance.findByType('ConfirmDialog')).toHaveLength(2); + expect( + screen.getByLabelText('Action Button outline-primary'), + ).toBeInTheDocument(); + expect(screen.getByLabelText('Action Button primary')).toBeInTheDocument(); + expect( + screen.getByLabelText('Confirm Dialog Exit without saving'), + ).toBeInTheDocument(); + expect( + screen.getByLabelText('Confirm Dialog Submit assessment'), + ).toBeInTheDocument(); }); - it('render without submitConfirmDialog', () => { + it('renders without submit confirm dialog when confirmProps is null', () => { useSubmitAssessmentAction.mockReturnValueOnce({ action: mockSubmitAssessmentAction.action, confirmProps: null, }); - const wrapper = shallow(); - expect(wrapper.snapshot).toMatchSnapshot(); + render(); - expect(wrapper.instance.findByType('ActionButton')).toHaveLength(2); - expect(wrapper.instance.findByType('ConfirmDialog')).toHaveLength(1); + expect( + screen.getByLabelText('Action Button outline-primary'), + ).toBeInTheDocument(); + expect(screen.getByLabelText('Action Button primary')).toBeInTheDocument(); + expect( + screen.getByLabelText('Confirm Dialog Exit without saving'), + ).toBeInTheDocument(); + expect( + screen.queryByLabelText('Confirm Dialog Submit assessment'), + ).not.toBeInTheDocument(); }); - it('has correct mock value', () => { - const wrapper = shallow(); + it('calls the correct handlers when buttons and dialogs are clicked', () => { + render(); - const exitButton = wrapper.instance.findByType('ActionButton')[0]; - expect(exitButton.props).toMatchObject(mockExitWithoutSavingAction.action); + const exitButton = screen.getByLabelText('Action Button outline-primary'); + expect(exitButton).toHaveTextContent('Exit without saving'); + fireEvent.click(exitButton); + expect(mockExitWithoutSavingAction.action.onClick).toHaveBeenCalled(); - const exitConfirmDialog = wrapper.instance.findByType('ConfirmDialog')[0]; - expect(exitConfirmDialog.props).toMatchObject(mockExitWithoutSavingAction.confirmProps); + const submitButton = screen.getByLabelText('Action Button primary'); + expect(submitButton).toHaveTextContent('Submit assessment'); + fireEvent.click(submitButton); + expect(mockSubmitAssessmentAction.action.onClick).toHaveBeenCalled(); - const submitButton = wrapper.instance.findByType('ActionButton')[1]; - expect(submitButton.props).toMatchObject(mockSubmitAssessmentAction.action); + const exitDialog = screen.getByLabelText( + 'Confirm Dialog Exit without saving', + ); + fireEvent.click(exitDialog); + expect( + mockExitWithoutSavingAction.confirmProps.onConfirm, + ).toHaveBeenCalled(); - const submitConfirmDialog = wrapper.instance.findByType('ConfirmDialog')[1]; - expect(submitConfirmDialog.props).toMatchObject(mockSubmitAssessmentAction.confirmProps); + const submitDialog = screen.getByLabelText( + 'Confirm Dialog Submit assessment', + ); + fireEvent.click(submitDialog); + expect( + mockSubmitAssessmentAction.confirmProps.onConfirm, + ).toHaveBeenCalled(); }); }); diff --git a/src/components/Assessment/EditableAssessment/__snapshots__/AssessmentActions.test.jsx.snap b/src/components/Assessment/EditableAssessment/__snapshots__/AssessmentActions.test.jsx.snap deleted file mode 100644 index 13e71f46..00000000 --- a/src/components/Assessment/EditableAssessment/__snapshots__/AssessmentActions.test.jsx.snap +++ /dev/null @@ -1,40 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` render default 1`] = ` - - - - - - -`; - -exports[` render without submitConfirmDialog 1`] = ` - - - - - -`; diff --git a/src/components/CriterionContainer/GradedCriterion.test.jsx b/src/components/CriterionContainer/GradedCriterion.test.jsx index df044fff..1c4aaba5 100644 --- a/src/components/CriterionContainer/GradedCriterion.test.jsx +++ b/src/components/CriterionContainer/GradedCriterion.test.jsx @@ -1,24 +1,64 @@ -import { shallow } from '@edx/react-unit-test-utils'; +import { render, screen } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import { IntlProvider } from '@edx/frontend-platform/i18n'; import GradedCriterion from './GradedCriterion'; -describe('', () => { - const props = { +jest.unmock('@openedx/paragon'); +jest.unmock('react'); +jest.unmock('@edx/frontend-platform/i18n'); + +const renderComponent = (props = {}) => render( + + + , +); + +describe('GradedCriterion', () => { + const defaultProps = { selectedOption: { name: 'option1', label: 'Option 1', - points: 1, + points: 5, }, - feedbackValue: 'Feedback', + feedbackValue: 'Feedback text', }; - it('renders correctly', () => { - const wrapper = shallow(); - expect(wrapper.snapshot).toMatchSnapshot(); + it('displays the option label and points', () => { + renderComponent(defaultProps); + + expect(screen.getByText('Option 1')).toBeInTheDocument(); + expect(screen.getByText('5 points')).toBeInTheDocument(); + }); + + it('displays the option name if label is not provided', () => { + const props = { + selectedOption: { + name: 'option1', + points: 5, + }, + }; + renderComponent(props); + + expect(screen.getByText('option1')).toBeInTheDocument(); + expect(screen.getByText('5 points')).toBeInTheDocument(); + }); + + it('displays feedback when provided', () => { + renderComponent(defaultProps); + expect(screen.getByText('Feedback text')).toBeInTheDocument(); }); - it('renders correctly with no feedback', () => { - const wrapper = shallow(); - expect(wrapper.snapshot).toMatchSnapshot(); + it('does not display feedback when not provided', () => { + const props = { + selectedOption: defaultProps.selectedOption, + }; + renderComponent(props); + expect(screen.queryByText('Feedback text')).not.toBeInTheDocument(); }); }); diff --git a/src/components/CriterionContainer/__snapshots__/GradedCriterion.test.jsx.snap b/src/components/CriterionContainer/__snapshots__/GradedCriterion.test.jsx.snap deleted file mode 100644 index 8daf77a0..00000000 --- a/src/components/CriterionContainer/__snapshots__/GradedCriterion.test.jsx.snap +++ /dev/null @@ -1,72 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` renders correctly 1`] = ` - - - Option 1 - - - - - - - - Feedback - - - - -`; - -exports[` renders correctly with no feedback 1`] = ` - - - Option 1 - - - - - - - - - -`; diff --git a/src/components/FileUpload/__snapshots__/index.test.jsx.snap b/src/components/FileUpload/__snapshots__/index.test.jsx.snap deleted file mode 100644 index 9790302f..00000000 --- a/src/components/FileUpload/__snapshots__/index.test.jsx.snap +++ /dev/null @@ -1,351 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` render default 1`] = ` - - - File upload - - - - Uploaded files - - , - ] - } - /> - - - - -`; - -exports[` render empty on studentTraining 1`] = `null`; - -exports[` render empty when file upload is not enabled 1`] = `null`; - -exports[` render extra columns when activeStepName is submission 1`] = ` - - - File upload - - - - Uploaded files - - , - ] - } - /> - - - - -`; - -exports[` render without dropzone and confirm modal when isReadOnly 1`] = ` - - - File upload - - - - - Uploaded files - - , - ] - } - /> - -`; - -exports[` render without file preview if uploadedFiles are empty and isReadOnly 1`] = ` - - - File upload - - - - Uploaded files - - , - ] - } - /> - -`; - -exports[` render without header 1`] = ` - - - Uploaded files - - , - ] - } - /> - - - - -`; - -exports[`createFileActionCell should return a function that is an action cell 1`] = ` - -`; diff --git a/src/components/FileUpload/index.test.jsx b/src/components/FileUpload/index.test.jsx index b8ac4bc9..a0ffb7fd 100644 --- a/src/components/FileUpload/index.test.jsx +++ b/src/components/FileUpload/index.test.jsx @@ -1,127 +1,126 @@ -import { shallow } from '@edx/react-unit-test-utils'; +import { render, screen } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import { IntlProvider } from '@edx/frontend-platform/i18n'; +import { MemoryRouter } from 'react-router-dom'; -import { useActiveStepName, useFileUploadConfig } from 'hooks/app'; +import { useFileUploadConfig, useActiveStepName } from 'hooks/app'; import { useViewStep } from 'hooks/routing'; -import { stepNames } from 'constants/index'; - import { useFileUploadHooks } from './hooks'; +import FileUpload from './index'; +import messages from './messages'; -import FileUpload, { createFileActionCell } from './index'; +jest.unmock('@openedx/paragon'); +jest.unmock('react'); +jest.unmock('@edx/frontend-platform/i18n'); jest.mock('hooks/app', () => ({ - useActiveStepName: jest.fn(), useFileUploadConfig: jest.fn(), + useActiveStepName: jest.fn(), })); + jest.mock('hooks/routing', () => ({ useViewStep: jest.fn(), })); + jest.mock('./hooks', () => ({ useFileUploadHooks: jest.fn(), })); -jest.mock('./UploadConfirmModal', () => 'UploadConfirmModal'); -jest.mock('./ActionCell', () => 'ActionCell'); -jest.mock('./FileDownload', () => 'FileDownload'); -jest.mock('components/FilePreview', () => 'FilePreview'); -describe('', () => { - const props = { +jest.mock('./UploadConfirmModal', () => () => Upload Confirm Modal); +jest.mock('./ActionCell', () => () => Action Cell); +jest.mock('./FileDownload', () => () => File Download); +jest.mock('components/FilePreview', () => () => File Preview); + +const renderComponent = (props = {}) => render( + + + + + , +); + +describe('FileUpload', () => { + const defaultProps = { isReadOnly: false, - uploadedFiles: [ - { - abc: 123, - fileSize: 123, - }, - { - def: 456, - fileSize: 'will be unknown', - }, - ], + uploadedFiles: [], onFileUploaded: jest.fn(), onDeletedFile: jest.fn(), defaultCollapsePreview: false, hideHeader: false, - }; - - const defaultFileUploadHooks = { - confirmUpload: jest.fn().mockName('confirmUpload'), - closeUploadModal: jest.fn().mockName('closeUploadModal'), - isModalOpen: false, - onProcessUpload: jest.fn().mockName('onProcessUpload'), - uploadArgs: { - abc: 123, - }, - }; - - const defaultUploadConfig = { - enabled: true, - fileUploadLimit: 10, - allowedExtensions: ['pdf', 'jpg'], - maxFileSize: 123456, + isInValid: false, }; beforeEach(() => { - useActiveStepName.mockReturnValue('someActiveStep'); - useViewStep.mockReturnValue('someStep'); - useFileUploadHooks.mockReturnValue(defaultFileUploadHooks); - useFileUploadConfig.mockReturnValue(defaultUploadConfig); - }); - - it('render default', () => { - const wrapper = shallow(); - expect(wrapper.snapshot).toMatchSnapshot(); + jest.clearAllMocks(); + useActiveStepName.mockReturnValue('submission'); + useViewStep.mockReturnValue('submission'); + useFileUploadHooks.mockReturnValue({ + confirmUpload: jest.fn(), + closeUploadModal: jest.fn(), + isModalOpen: false, + onProcessUpload: jest.fn(), + uploadArgs: {}, + }); }); - it('render without header', () => { - const wrapper = shallow(); - expect(wrapper.snapshot).toMatchSnapshot(); + it('renders empty state when no files are uploaded', () => { + useFileUploadConfig.mockReturnValue({ + enabled: true, + fileUploadLimit: 3, + allowedExtensions: ['pdf', 'txt'], + maxFileSize: 10, + }); + + renderComponent(defaultProps); + + expect(screen.getByText('File upload')).toBeInTheDocument(); + expect(screen.getByText('Uploaded files')).toBeInTheDocument(); + expect(screen.getByText('File name')).toBeInTheDocument(); + expect(screen.getByText('File description')).toBeInTheDocument(); + expect(screen.getByText('File size')).toBeInTheDocument(); + expect(screen.getByText('Actions')).toBeInTheDocument(); }); - it('render without file preview if uploadedFiles are empty and isReadOnly', () => { - const wrapper = shallow(); - expect(wrapper.snapshot).toMatchSnapshot(); - - expect(wrapper.instance.findByType('FilePreview')).toHaveLength(0); - }); - - it('render without dropzone and confirm modal when isReadOnly', () => { - const wrapper = shallow(); - expect(wrapper.snapshot).toMatchSnapshot(); - - expect(wrapper.instance.findByType('UploadConfirmModal')).toHaveLength(0); - expect(wrapper.instance.findByType('Dropzone')).toHaveLength(0); - }); - - it('render empty on studentTraining', () => { - useViewStep.mockReturnValueOnce(stepNames.studentTraining); - const wrapper = shallow(); - expect(wrapper.snapshot).toMatchSnapshot(); + it('renders file table when files are uploaded', () => { + useFileUploadConfig.mockReturnValue({ + enabled: true, + fileUploadLimit: 3, + allowedExtensions: ['pdf', 'txt'], + maxFileSize: 10, + }); + + const props = { + ...defaultProps, + uploadedFiles: [ + { + fileName: 'test.pdf', + fileDescription: 'Test file', + fileSize: 1024, + }, + ], + }; + + renderComponent(props); + + expect(screen.getByText('test.pdf')).toBeInTheDocument(); + expect(screen.getByText('Test file')).toBeInTheDocument(); }); - it('render empty when file upload is not enabled', () => { - useFileUploadConfig.mockReturnValueOnce({ enabled: false }); - const wrapper = shallow(); - expect(wrapper.snapshot).toMatchSnapshot(); - }); - - it('render extra columns when activeStepName is submission', () => { - useActiveStepName.mockReturnValueOnce(stepNames.submission); - const wrapper = shallow(); - expect(wrapper.snapshot).toMatchSnapshot(); - - expect(wrapper.instance.findByType('DataTable')[0].props.columns).toHaveLength(4); - }); -}); + it('shows required validation message when isInValid is true', () => { + useFileUploadConfig.mockReturnValue({ + enabled: true, + fileUploadLimit: 3, + allowedExtensions: ['pdf', 'txt'], + maxFileSize: 10, + }); -describe('createFileActionCell', () => { - it('should return a function that is an action cell', () => { - const onDeletedFile = jest.fn(); - const isReadOnly = false; - const FileActionCell = createFileActionCell({ onDeletedFile, isReadOnly }); - expect(typeof FileActionCell).toBe('function'); + const props = { + ...defaultProps, + isInValid: true, + }; - const wrapper = shallow(); - expect(wrapper.snapshot).toMatchSnapshot(); + renderComponent(props); - expect(wrapper.instance.findByType('ActionCell')).toHaveLength(1); + expect(screen.getByText('File Upload is required')).toBeInTheDocument(); }); }); diff --git a/src/views/AssessmentView/__snapshots__/index.test.jsx.snap b/src/views/AssessmentView/__snapshots__/index.test.jsx.snap deleted file mode 100644 index cf874b90..00000000 --- a/src/views/AssessmentView/__snapshots__/index.test.jsx.snap +++ /dev/null @@ -1,86 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` render empty on not loaded 1`] = `null`; - -exports[` render with files 1`] = ` - - - - - -`; - -exports[` render with prompts and text responses 1`] = ` - - - - - - - Your response - - - - - - - - - Your response - - - - - - -`; diff --git a/src/views/AssessmentView/index.test.jsx b/src/views/AssessmentView/index.test.jsx index ea28ee67..2d3ae589 100644 --- a/src/views/AssessmentView/index.test.jsx +++ b/src/views/AssessmentView/index.test.jsx @@ -1,67 +1,93 @@ -import { shallow } from '@edx/react-unit-test-utils'; +import { render, screen } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import { IntlProvider } from '@edx/frontend-platform/i18n'; import { useViewStep } from 'hooks/routing'; - import { stepNames } from 'constants/index'; import useAssessmentData from './useAssessmentData'; import AssessmentView from './index'; +/* eslint-disable react/prop-types */ + +jest.unmock('@openedx/paragon'); +jest.unmock('react'); +jest.unmock('@edx/frontend-platform/i18n'); + jest.mock('hooks/routing', () => ({ useViewStep: jest.fn(), })); -jest.mock('components/Prompt', () => 'Prompt'); -jest.mock('components/TextResponse', () => 'TextResponse'); -jest.mock('components/FileUpload', () => 'FileUpload'); + jest.mock('./useAssessmentData', () => jest.fn()); -describe('', () => { - useViewStep.mockReturnValue(stepNames.self); - it('render empty on not loaded', () => { +jest.mock('components/Prompt', () => () => Prompt); +jest.mock('components/TextResponse', () => () => Text Response); +jest.mock('components/FileUpload', () => () => File Upload); +jest.mock('./BaseAssessmentView', () => ({ children }) => ( + Base View {children} +)); + +const renderComponent = (component) => render( + + {component} + , +); + +describe('AssessmentView', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + it('renders nothing when data is not loaded', () => { + useAssessmentData.mockReturnValue({ isLoaded: false }); + const { container } = renderComponent(); + expect(container).toBeEmptyDOMElement(); + }); + + it('renders prompts without responses when text responses are empty', () => { useAssessmentData.mockReturnValue({ - prompts: [], - response: {}, - isLoaded: false, + isLoaded: true, + prompts: [{ id: 1 }, { id: 2 }], + response: { + textResponses: [], + uploadedFiles: [], + }, }); - const wrapper = shallow(); - expect(wrapper.snapshot).toMatchSnapshot(); - expect(wrapper.isEmptyRender()).toBe(true); + useViewStep.mockReturnValue(stepNames.submission); + + renderComponent(); + + const prompts = screen.getAllByText('Prompt'); + expect(prompts).toHaveLength(2); + expect(screen.queryByText('Text Response')).not.toBeInTheDocument(); }); - it('render with prompts and text responses', () => { + it('renders file upload when there are uploaded files', () => { useAssessmentData.mockReturnValue({ - prompts: [ - { id: 1, prompt: 'prompt' }, - { id: 2, prompt: 'prompt' }, - ], + isLoaded: true, + prompts: [], response: { - textResponses: [ - { id: 1, response: 'response' }, - { id: 2, response: 'response' }, - ], + textResponses: [], + uploadedFiles: [{ id: 1 }], }, - isLoaded: true, }); - const wrapper = shallow(); - expect(wrapper.snapshot).toMatchSnapshot(); - expect(wrapper.instance.findByType('Prompt').length).toBe(2); - expect(wrapper.instance.findByType('TextResponse').length).toBe(2); - expect(wrapper.instance.findByType('FileUpload').length).toBe(0); + renderComponent(); + + expect(screen.getByText('File Upload')).toBeInTheDocument(); }); - it('render with files', () => { + it('does not render file upload when there are no files', () => { useAssessmentData.mockReturnValue({ + isLoaded: true, prompts: [], response: { - uploadedFiles: [{ id: 1, name: 'file' }], + textResponses: [], + uploadedFiles: [], }, - isLoaded: true, }); - const wrapper = shallow(); - expect(wrapper.snapshot).toMatchSnapshot(); - expect(wrapper.instance.findByType('Prompt').length).toBe(0); - expect(wrapper.instance.findByType('TextResponse').length).toBe(0); - expect(wrapper.instance.findByType('FileUpload').length).toBe(1); + renderComponent(); + + expect(screen.queryByText('File Upload')).not.toBeInTheDocument(); }); }); diff --git a/src/views/SubmissionView/__snapshots__/index.test.jsx.snap b/src/views/SubmissionView/__snapshots__/index.test.jsx.snap deleted file mode 100644 index 494064e7..00000000 --- a/src/views/SubmissionView/__snapshots__/index.test.jsx.snap +++ /dev/null @@ -1,112 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` renders disable show rubric 1`] = ` - - - - - - - - Your response - - - - - - - - - - - - -`; - -exports[` renders enable show rubric 1`] = ` - - - - - - - - Your response - - - - - - - - - - - - - -`; diff --git a/src/views/SubmissionView/index.test.jsx b/src/views/SubmissionView/index.test.jsx index 427fcf18..88a2aee7 100644 --- a/src/views/SubmissionView/index.test.jsx +++ b/src/views/SubmissionView/index.test.jsx @@ -1,17 +1,24 @@ -import { shallow } from '@edx/react-unit-test-utils'; +import { render, screen } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import { IntlProvider } from '@edx/frontend-platform/i18n'; import useSubmissionViewData from './hooks'; - import SubmissionView from './index'; -jest.mock('components/Rubric', () => 'Rubric'); -jest.mock('components/ModalActions', () => 'ModalActions'); -jest.mock('components/FileUpload', () => 'FileUpload'); -jest.mock('components/Instructions', () => 'Instructions'); -jest.mock('components/StatusAlert', () => 'StatusAlert'); -jest.mock('./SubmissionPrompts', () => 'SubmissionPrompts'); +jest.unmock('@openedx/paragon'); +jest.unmock('react'); +jest.unmock('@edx/frontend-platform/i18n'); + +jest.mock('components/Rubric', () => () => Rubric); +jest.mock('components/ModalActions', () => () => Modal Actions); +jest.mock('components/FileUpload', () => () => File Upload); +jest.mock('components/Instructions', () => () => Instructions); +jest.mock('components/StatusAlert', () => () => Status Alert); +jest.mock('./SubmissionPrompts', () => () => Submission Prompts); jest.mock('./hooks', () => jest.fn()); +const renderWithIntl = (component) => render({component}); + describe('', () => { const mockUseSubmissionViewData = { actionOptions: { @@ -30,18 +37,23 @@ describe('', () => { }; useSubmissionViewData.mockReturnValue(mockUseSubmissionViewData); - it('renders disable show rubric', () => { - const wrapper = shallow(); - expect(wrapper.snapshot).toMatchSnapshot(); + it('does not render rubric when showRubric is false', () => { + renderWithIntl(); - expect(wrapper.instance.findByType('Rubric').length).toBe(0); + expect(screen.queryByText('Rubric')).not.toBeInTheDocument(); + expect(screen.getByText('Modal Actions')).toBeInTheDocument(); + expect(screen.getByText('Submission Prompts')).toBeInTheDocument(); }); - it('renders enable show rubric', () => { - mockUseSubmissionViewData.showRubric = true; - const wrapper = shallow(); - expect(wrapper.snapshot).toMatchSnapshot(); + it('renders rubric when showRubric is true', () => { + useSubmissionViewData.mockReturnValue({ + ...mockUseSubmissionViewData, + showRubric: true, + }); + renderWithIntl(); - expect(wrapper.instance.findByType('Rubric').length).toBe(1); + expect(screen.getByText('Rubric')).toBeInTheDocument(); + expect(screen.getByText('Modal Actions')).toBeInTheDocument(); + expect(screen.getByText('Submission Prompts')).toBeInTheDocument(); }); });