diff --git a/src/views/AssessmentView/BaseAssessmentView/__snapshots__/index.test.jsx.snap b/src/views/AssessmentView/BaseAssessmentView/__snapshots__/index.test.jsx.snap deleted file mode 100644 index 1a9c696a..00000000 --- a/src/views/AssessmentView/BaseAssessmentView/__snapshots__/index.test.jsx.snap +++ /dev/null @@ -1,45 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` render default 1`] = ` -
-
- - -
-

- Self grading -

- -
-
- - - - children - - - - - - -
-
-`; diff --git a/src/views/AssessmentView/BaseAssessmentView/index.test.jsx b/src/views/AssessmentView/BaseAssessmentView/index.test.jsx index 8ef1e929..5ac3b97c 100644 --- a/src/views/AssessmentView/BaseAssessmentView/index.test.jsx +++ b/src/views/AssessmentView/BaseAssessmentView/index.test.jsx @@ -1,24 +1,121 @@ -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 messages from '../messages'; import BaseAssessmentView 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/Assessment', () => 'Assessment'); -jest.mock('components/Instructions', () => 'Instructions'); -jest.mock('components/ModalActions', () => 'ModalActions'); -jest.mock('components/StatusAlert', () => 'StatusAlert'); -jest.mock('components/StepProgressIndicator', () => 'StepProgressIndicator'); +jest.mock('components/Assessment', () => () =>
Assessment
); +jest.mock('components/Instructions', () => () =>
Instructions
); +jest.mock('components/ModalActions', () => () =>
Modal Actions
); +jest.mock('components/StatusAlert', () => () =>
Status Alert
); +jest.mock('components/StepProgressIndicator', () => (props) => ( +
Step Progress Indicator: {props.step}
+)); + +const renderWithIntl = (ui) => { + const testMessages = { + 'frontend-app-ora.selfAssessmentView.header': + messages[stepNames.self].defaultMessage, + 'frontend-app-ora.peerAssessmentView.header': + messages[stepNames.peer].defaultMessage, + 'frontend-app-ora.studentTrainingView.header': + messages[stepNames.studentTraining].defaultMessage, + }; + + return render( + + {ui} + , + ); +}; describe('', () => { - it('render default', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + it('renders with self assessment step', () => { useViewStep.mockReturnValue(stepNames.self); - const wrapper = shallow(children); - expect(wrapper.snapshot).toMatchSnapshot(); + renderWithIntl( + +
Test children content
+
, + ); + + expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent( + 'Self grading', + ); + expect(screen.getByText('Status Alert')).toBeInTheDocument(); + expect(screen.getByText('Instructions')).toBeInTheDocument(); + expect(screen.getByText('Modal Actions')).toBeInTheDocument(); + expect(screen.getByText('Assessment')).toBeInTheDocument(); + expect( + screen.getByText('Step Progress Indicator: self'), + ).toBeInTheDocument(); + expect(screen.getByText('Test children content')).toBeInTheDocument(); + }); + + it('renders with peer assessment step', () => { + useViewStep.mockReturnValue(stepNames.peer); + renderWithIntl( + +
Peer content
+
, + ); + + expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent( + 'Grade your peers', + ); + expect( + screen.getByText('Step Progress Indicator: peer'), + ).toBeInTheDocument(); + expect(screen.getByText('Peer content')).toBeInTheDocument(); + }); + + it('renders with student training step', () => { + useViewStep.mockReturnValue(stepNames.studentTraining); + renderWithIntl( + +
Training content
+
, + ); + + expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent( + 'Practice grading', + ); + expect( + screen.getByText('Step Progress Indicator: studentTraining'), + ).toBeInTheDocument(); + expect(screen.getByText('Training content')).toBeInTheDocument(); + }); + + it('renders all required components', () => { + useViewStep.mockReturnValue(stepNames.self); + renderWithIntl( + +
Child component
+
, + ); + + expect(screen.getByText('Status Alert')).toBeInTheDocument(); + expect(screen.getByText('Instructions')).toBeInTheDocument(); + expect(screen.getByText('Modal Actions')).toBeInTheDocument(); + expect(screen.getByText('Assessment')).toBeInTheDocument(); + expect( + screen.getByText('Step Progress Indicator: self'), + ).toBeInTheDocument(); + expect(screen.getByText('Child component')).toBeInTheDocument(); }); }); diff --git a/src/views/SubmissionView/SubmissionPrompts.test.jsx b/src/views/SubmissionView/SubmissionPrompts.test.jsx index a53c81ab..eb971c1b 100644 --- a/src/views/SubmissionView/SubmissionPrompts.test.jsx +++ b/src/views/SubmissionView/SubmissionPrompts.test.jsx @@ -1,88 +1,135 @@ -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 { - usePrompts, - useSubmissionConfig, -} from 'hooks/app'; +import { usePrompts, useSubmissionConfig } from 'hooks/app'; import SubmissionPrompts from './SubmissionPrompts'; +jest.unmock('@openedx/paragon'); +jest.unmock('react'); +jest.unmock('@edx/frontend-platform/i18n'); + jest.mock('hooks/app', () => ({ usePrompts: jest.fn(), useSubmissionConfig: jest.fn(), })); -jest.mock('components/Prompt', () => 'Prompt'); -jest.mock('components/TextResponse', () => 'TextResponse'); -jest.mock('./TextResponseEditor', () => 'TextResponseEditor'); + +/* eslint-disable react/prop-types */ +jest.mock('components/Prompt', () => ({ prompt }) => ( +
Prompt: {prompt}
+)); + +jest.mock('components/TextResponse', () => ({ response }) => ( +
Response: {response}
+)); + +jest.mock('./TextResponseEditor', () => ({ value, onChange, isInValid }) => ( +