Files
frontend-app-learner-dashboard/src/containers/CourseCard/components/CourseCardActions/ResumeButton.test.jsx
leangseu-edx 2ee19988b3 components unit test (#23)
Co-authored-by: Ben Warzeski <bwarzeski@edx.org>
2022-09-27 12:48:33 -04:00

57 lines
1.7 KiB
JavaScript

import { shallow } from 'enzyme';
import { hooks } from 'data/redux';
import ResumeButton from './ResumeButton';
jest.mock('data/redux', () => ({
hooks: {
useCardCourseRunData: jest.fn(),
useCardEnrollmentData: jest.fn(),
},
}));
describe('ResumeButton', () => {
const props = {
cardId: 'cardId',
};
hooks.useCardCourseRunData.mockReturnValue({
resumeUrl: 'resumeUrl',
});
describe('snapshot', () => {
test('renders default button when learner has access to the course', () => {
hooks.useCardEnrollmentData.mockReturnValueOnce({
hasAccess: true,
});
const wrapper = shallow(<ResumeButton {...props} />);
expect(wrapper).toMatchSnapshot();
});
test('renders disabled button when learner does not have access to the course', () => {
hooks.useCardEnrollmentData.mockReturnValueOnce({
hasAccess: false,
});
const wrapper = shallow(<ResumeButton {...props} />);
expect(wrapper).toMatchSnapshot();
});
});
describe('behavior', () => {
it('renders disabled button when audit access expired', () => {
hooks.useCardEnrollmentData.mockReturnValueOnce({
hasAccess: true,
isAudit: true,
isAuditAccessExpired: true,
});
const wrapper = shallow(<ResumeButton {...props} />);
expect(wrapper.prop('disabled')).toEqual(true);
});
it('renders enabled button when audit access not expired', () => {
hooks.useCardEnrollmentData.mockReturnValueOnce({
hasAccess: true,
isAudit: true,
isAuditAccessExpired: false,
});
const wrapper = shallow(<ResumeButton {...props} />);
expect(wrapper.prop('disabled')).toEqual(false);
});
});
});