feat: Unenroll tests

This commit is contained in:
Ben Warzeski
2022-06-13 11:32:14 -04:00
parent b9420dabb3
commit 862ff2d0e2
8 changed files with 272 additions and 1 deletions

View File

@@ -3,7 +3,7 @@ const { createConfig } = require('@edx/frontend-build');
module.exports = createConfig('jest', {
setupFilesAfterEnv: [
'jest-expect-message',
'<rootDir>/src/setupTest.js',
'<rootDir>/src/setupTest.jsx',
],
modulePaths: ['<rootDir>/src/'],
snapshotSerializers: [

View File

@@ -0,0 +1,14 @@
import React from 'react';
import { shallow } from 'enzyme';
import { ConfirmPane } from './ConfirmPane';
describe('UnenrollConfirmModal ConfirmPane', () => {
test('snapshot', () => {
const props = {
handleClose: jest.fn().mockName('props.handleClose'),
handleConfirm: jest.fn().mockName('props.handleConfirm'),
};
expect(shallow(<ConfirmPane {...props} />)).toMatchSnapshot();
});
});

View File

@@ -0,0 +1,21 @@
import React from 'react';
import { shallow } from 'enzyme';
import { FinishedPane } from './FinishedPane';
describe('UnenrollConfirmModal FinishedPane', () => {
test('snapshot: gave reason', () => {
const props = {
gaveReason: true,
handleClose: jest.fn().mockName('props.handleClose'),
};
expect(shallow(<FinishedPane {...props} />)).toMatchSnapshot();
});
test('snapshot: did not give reason', () => {
const props = {
gaveReason: false,
handleClose: jest.fn().mockName('props.handleClose'),
};
expect(shallow(<FinishedPane {...props} />)).toMatchSnapshot();
});
});

View File

@@ -0,0 +1,23 @@
import React from 'react';
import { shallow } from 'enzyme';
import { ReasonPane } from './ReasonPane';
describe('UnenrollConfirmModal ReasonPane', () => {
const props = {
reason: {
value: 'props.reason.value',
skip: jest.fn().mockName('props.reason.skip'),
selectOption: jest.fn().mockName('props.reason.selectOption'),
customOption: {
value: 'props.reason.customOption.value',
onChange: jest.fn().mockName('props.reason.customOption.onChange'),
},
selected: 'props.reason.selected',
submit: jest.fn().mockName('props.reason.submit'),
},
};
test('snapshot', () => {
expect(shallow(<ReasonPane {...props} />)).toMatchSnapshot();
});
});

View File

@@ -0,0 +1,33 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`UnenrollConfirmModal ConfirmPane snapshot 1`] = `
<Fragment>
<h4>
<formatMessage
msg="Unenroll from course?"
/>
</h4>
<p>
<formatMessage
msg="Progress that you've made so far will not be saved"
/>
</p>
<ActionRow>
<Button
onClick={[MockFunction props.handleClose]}
variant="tertiary"
>
<formatMessage
msg="Nevermind"
/>
</Button>
<Button
onClick={[MockFunction props.handleConfirm]}
>
<formatMessage
msg="Unenroll"
/>
</Button>
</ActionRow>
</Fragment>
`;

View File

@@ -0,0 +1,52 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`UnenrollConfirmModal FinishedPane snapshot: did not give reason 1`] = `
<Fragment>
<h4>
<formatMessage
msg="You are unenrolled"
/>
</h4>
<p>
<formatMessage
msg="This course will be removed from your dashboard."
/>
</p>
<ActionRow>
<Button
onClick={[MockFunction props.handleClose]}
>
<formatMessage
msg="Return to dashboard"
/>
</Button>
</ActionRow>
</Fragment>
`;
exports[`UnenrollConfirmModal FinishedPane snapshot: gave reason 1`] = `
<Fragment>
<h4>
<formatMessage
msg="You are unenrolled"
/>
</h4>
<p>
<formatMessage
msg="Thank you for sharing your reason for unenrolling. "
/>
<formatMessage
msg="This course will be removed from your dashboard."
/>
</p>
<ActionRow>
<Button
onClick={[MockFunction props.handleClose]}
>
<formatMessage
msg="Return to dashboard"
/>
</Button>
</ActionRow>
</Fragment>
`;

View File

@@ -0,0 +1,119 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`UnenrollConfirmModal ReasonPane snapshot 1`] = `
<Fragment>
<h4>
<formatMessage
msg="What's your main reason for unenrolling?"
/>
</h4>
<Form.RadioSet
name="unenrollReason"
onChange={[MockFunction props.reason.selectOption]}
value="props.reason.selected"
>
<Form.Radio
key="prereqs"
value="prereqs"
>
<formatMessage
msg="I don't have the academic or language prerequisites"
/>
</Form.Radio>
<Form.Radio
key="difficulty"
value="difficulty"
>
<formatMessage
msg="The course material was too hard"
/>
</Form.Radio>
<Form.Radio
key="goals"
value="goals"
>
<formatMessage
msg="This won't help me reach my goals"
/>
</Form.Radio>
<Form.Radio
key="broken"
value="broken"
>
<formatMessage
msg="Something was broken"
/>
</Form.Radio>
<Form.Radio
key="time"
value="time"
>
<formatMessage
msg="I don't have the time"
/>
</Form.Radio>
<Form.Radio
key="browse"
value="browse"
>
<formatMessage
msg="I just wanted to browse the material"
/>
</Form.Radio>
<Form.Radio
key="support"
value="support"
>
<formatMessage
msg="I don't have enough support"
/>
</Form.Radio>
<Form.Radio
key="quality"
value="quality"
>
<formatMessage
msg="I am not happy with the quality of the content"
/>
</Form.Radio>
<Form.Radio
key="easy"
value="easy"
>
<formatMessage
msg="The course material was too easy"
/>
</Form.Radio>
<Form.Radio
value="custom"
>
<Form.Control
onChange={[MockFunction props.reason.customOption.onChange]}
placeholder={
<formatMessage
msg="Other"
/>
}
value="props.reason.customOption.value"
/>
</Form.Radio>
</Form.RadioSet>
<ActionRow>
<Button
onClick={[MockFunction props.reason.skip]}
variant="tertiary"
>
<formatMessage
msg="Skip"
/>
</Button>
<Button
onClick={[MockFunction props.reason.submit]}
>
<formatMessage
msg="Submit"
/>
</Button>
</ActionRow>
</Fragment>
`;

View File

@@ -23,6 +23,15 @@ jest.mock('@edx/frontend-platform/i18n', () => {
intlShape: PropTypes.shape({
formatMessage: PropTypes.func,
}),
useIntl: () => ({
formatMessage: (msg) => (
<formatMessage
msg={msg.defaultMessage}
{...(msg.values && { values: msg.values })}
/>
),
formatDate: jest.fn().mockName('useIntl.formatDate'),
}),
defineMessages: m => m,
FormattedMessage: () => 'FormattedMessage',
};