* feat: add language selection chore: update tests so we have less error message test: update test * test: update tests * chore: remove duplicate translation * chore: lint for console * chore: remove comments * chore: make sure the affect url frame refresh after the language selection change * chore: add whole_course_translation and language to courseware meta (#1305) * feat: Add feedback widget UI mock Add unit tests Fix snapshot Clean Sequence component logEvent calls Clean unit test Put feedback widget behind whole course translation flag Fix useFeedbackWidget test * chore: add src and dest translation * feat: first iteration of plugin translation chore: update plugin instruction * feat: Connect FeedbackWidget with backend services (#1325) Connect FeedbackWidget with backend services Move feedback widget to unit translation plugin * feat: Add authentication to WCT feedback endpoints (#1329) * chore: add fetch config and move feedback widget for the plugin chore: rewrite and test the api request chore: rebase chore: update translation feedback chore: test chore: add more tests * chore: rebase * chore: update requested change * chore: update package * chore: upgrade frontend-lib-special-exams and frontend-lib-learning-assistant * chore: update tests * chore: remove unneeded package * chore: update example config * chore: add source-map-loader * fix: feedback widget render error after submit feedback (#1335) * fix: feedback widget render error after submit feedback * fix: widget logic --------- Co-authored-by: Rodrigo Martin <rodrigom_94@hotmail.com>
80 lines
2.5 KiB
JavaScript
80 lines
2.5 KiB
JavaScript
import React from 'react';
|
|
|
|
import { getEffects, mockUseKeyedState } from '@edx/react-unit-test-utils';
|
|
import { useModel } from '@src/generic/model-store';
|
|
|
|
import { modelKeys } from '../constants';
|
|
|
|
import useShouldDisplayHonorCode, { stateKeys } from './useShouldDisplayHonorCode';
|
|
|
|
jest.mock('react', () => ({
|
|
...jest.requireActual('react'),
|
|
useEffect: jest.fn(),
|
|
}));
|
|
jest.mock('@src/generic/model-store', () => ({
|
|
useModel: jest.fn(),
|
|
}));
|
|
|
|
const state = mockUseKeyedState(stateKeys);
|
|
|
|
const props = {
|
|
id: 'test-id',
|
|
courseId: 'test-course-id',
|
|
};
|
|
|
|
const mockModels = (graded, userNeedsIntegritySignature) => {
|
|
useModel.mockImplementation((key) => (
|
|
(key === modelKeys.units) ? { graded } : { userNeedsIntegritySignature }
|
|
));
|
|
};
|
|
|
|
describe('useShouldDisplayHonorCode hook', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
mockModels(false, false);
|
|
state.mock();
|
|
});
|
|
describe('behavior', () => {
|
|
it('initializes shouldDisplay to false', () => {
|
|
useShouldDisplayHonorCode(props);
|
|
state.expectInitializedWith(stateKeys.shouldDisplay, false);
|
|
});
|
|
describe('effect - on userNeedsIntegritySignature', () => {
|
|
describe('graded and needs integrity signature', () => {
|
|
it('sets shouldDisplay(true)', () => {
|
|
mockModels(true, true);
|
|
useShouldDisplayHonorCode(props);
|
|
const cb = getEffects([state.setState.shouldDisplay, true], React)[0];
|
|
cb();
|
|
expect(state.setState.shouldDisplay).toHaveBeenCalledWith(true);
|
|
});
|
|
});
|
|
describe('not graded', () => {
|
|
it('sets should not display', () => {
|
|
mockModels(true, false);
|
|
useShouldDisplayHonorCode(props);
|
|
const cb = getEffects([state.setState.shouldDisplay, false], React)[0];
|
|
cb();
|
|
expect(state.setState.shouldDisplay).toHaveBeenCalledWith(false);
|
|
});
|
|
});
|
|
describe('does not need integrity signature', () => {
|
|
it('sets should not display', () => {
|
|
mockModels(false, true);
|
|
useShouldDisplayHonorCode(props);
|
|
const cb = getEffects([state.setState.shouldDisplay, true], React)[0];
|
|
cb();
|
|
expect(state.setState.shouldDisplay).toHaveBeenCalledWith(false);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
describe('output', () => {
|
|
it('returns shouldDisplay value from state', () => {
|
|
const testValue = 'test-value';
|
|
state.mockVal(stateKeys.shouldDisplay, testValue);
|
|
expect(useShouldDisplayHonorCode(props)).toEqual(testValue);
|
|
});
|
|
});
|
|
});
|