Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor references to examStore to use the useDispatch and useSelector hooks API. #131

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { examRequiresAccessToken, store } from './data';

export function isExam() {
const { exam } = store.getState().examState;
const { exam } = store.getState().specialExams;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[comment] I like the renaming to specialExams!

return !!exam?.id;
}

export function getExamAccess() {
const { exam, examAccessToken } = store.getState().examState;
const { exam, examAccessToken } = store.getState().specialExams;
if (!exam) {
return '';
}
return examAccessToken.exam_access_token;
}

export async function fetchExamAccess() {
const { exam } = store.getState().examState;
const { exam } = store.getState().specialExams;
const { dispatch } = store;
if (!exam) {
return Promise.resolve();
Expand Down
4 changes: 2 additions & 2 deletions src/api.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('External API integration tests', () => {
jest.mock('./data');
const mockExam = Factory.build('exam', { attempt: Factory.build('attempt') });
const mockToken = Factory.build('examAccessToken');
const mockState = { examState: { exam: mockExam, examAccessToken: mockToken } };
const mockState = { specialExams: { exam: mockExam, examAccessToken: mockToken } };
store.getState = jest.fn().mockReturnValue(mockState);
});

Expand All @@ -35,7 +35,7 @@ describe('External API integration tests', () => {
describe('Test isExam without exam', () => {
beforeAll(() => {
jest.mock('./data');
const mockState = { examState: { exam: null, examAccessToken: null } };
const mockState = { specialExams: { exam: null, examAccessToken: null } };
store.getState = jest.fn().mockReturnValue(mockState);
});

Expand Down
2 changes: 1 addition & 1 deletion src/core/ExamStateProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const StateProvider = ({ children, ...state }) => {
);
};

const mapStateToProps = (state) => ({ ...state.examState });
const mapStateToProps = (state) => ({ ...state.specialExams });

const ExamStateProvider = withExamStore(
StateProvider,
Expand Down
4 changes: 2 additions & 2 deletions src/core/OuterExamTimer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('OuterExamTimer', () => {
attempt_status: ExamStatus.STARTED,
});
store.getState = () => ({
examState: {
specialExams: {
activeAttempt: attempt,
exam: {
time_limit_mins: 60,
Expand All @@ -45,7 +45,7 @@ describe('OuterExamTimer', () => {

it('does not render timer if there is no exam in progress', () => {
store.getState = () => ({
examState: {
specialExams: {
activeAttempt: {},
exam: {},
},
Expand Down
2 changes: 1 addition & 1 deletion src/data/__factories__/examState.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import './exam.factory';
import './proctoringSettings.factory';
import './examAccessToken.factory';

Factory.define('examState')
Factory.define('specialExams')
.attr('proctoringSettings', Factory.build('proctoringSettings'))
.attr('exam', Factory.build('exam'))
.attr('examAccessToken', Factory.build('examAccessToken'))
Expand Down
8 changes: 4 additions & 4 deletions src/data/__snapshots__/redux.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Object {

exports[`Data layer integration tests Test getExamAttemptsData Should get, and save exam and attempt 1`] = `
Object {
"examState": Object {
"specialExams": Object {
"activeAttempt": Object {
"attempt_code": "",
"attempt_id": 1,
Expand Down Expand Up @@ -93,7 +93,7 @@ Object {

exports[`Data layer integration tests Test getLatestAttemptData with edx-proctoring as a backend (no EXAMS_BASE_URL) Should get, and save latest attempt 1`] = `
Object {
"examState": Object {
"specialExams": Object {
"activeAttempt": Object {
"attempt_code": "",
"attempt_id": 1,
Expand Down Expand Up @@ -245,7 +245,7 @@ Object {

exports[`Data layer integration tests Test resetExam Should reset exam attempt 1`] = `
Object {
"examState": Object {
"specialExams": Object {
"activeAttempt": null,
"allowProctoringOptOut": false,
"apiErrorMsg": "",
Expand Down Expand Up @@ -314,7 +314,7 @@ Object {

exports[`Data layer integration tests Test resetExam with edx-proctoring as backend (no EXAMS_BASE_URL) Should reset exam attempt 1`] = `
Object {
"examState": Object {
"specialExams": Object {
"activeAttempt": null,
"allowProctoringOptOut": false,
"apiErrorMsg": "",
Expand Down
1 change: 1 addition & 0 deletions src/data/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export {
createProctoredExamAttempt,
getExamAttemptsData,
getLatestAttemptData,
getProctoringSettings,
Expand Down
Loading
Loading