update unit testing for reducers
This commit is contained in:
committed by
Ben Warzeski
parent
83701acc16
commit
21ec5fbbe5
@@ -7,55 +7,62 @@ const initialState = {
|
||||
errorFetching: false,
|
||||
};
|
||||
|
||||
const assignmentTypesData = ['Exam', 'Homework'];
|
||||
const testingState = {
|
||||
...initialState,
|
||||
results: ['Exam', 'Homework'],
|
||||
};
|
||||
|
||||
describe('assignmentTypes reducer', () => {
|
||||
it('has initial state', () => {
|
||||
expect(assignmentTypes(undefined, {})).toEqual(initialState);
|
||||
expect(
|
||||
assignmentTypes(undefined, {}),
|
||||
).toEqual(initialState);
|
||||
});
|
||||
|
||||
it('updates fetch assignmentTypes request state', () => {
|
||||
const expected = {
|
||||
...initialState,
|
||||
...testingState,
|
||||
startedFetching: true,
|
||||
};
|
||||
expect(assignmentTypes(undefined, actions.fetching.started()))
|
||||
.toEqual(expected);
|
||||
expect(
|
||||
assignmentTypes(testingState, actions.fetching.started()),
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
it('updates fetch assignmentTypes success state', () => {
|
||||
const expectedResults = ['Exam'];
|
||||
const expected = {
|
||||
...initialState,
|
||||
results: assignmentTypesData,
|
||||
...testingState,
|
||||
results: expectedResults,
|
||||
errorFetching: false,
|
||||
finishedFetching: true,
|
||||
};
|
||||
expect(
|
||||
assignmentTypes(undefined, actions.fetching.received(assignmentTypesData)),
|
||||
assignmentTypes(testingState, actions.fetching.received(expectedResults)),
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
it('updates fetch assignmentTypes failure state', () => {
|
||||
const expected = {
|
||||
...initialState,
|
||||
...testingState,
|
||||
errorFetching: true,
|
||||
finishedFetching: true,
|
||||
};
|
||||
expect(
|
||||
assignmentTypes(undefined, actions.fetching.error()),
|
||||
assignmentTypes(testingState, actions.fetching.error()),
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
it('updates areGradesFrozen success state', () => {
|
||||
const expectedAreGradesFrozen = true;
|
||||
const expected = {
|
||||
...initialState,
|
||||
...testingState,
|
||||
errorFetching: false,
|
||||
finishedFetching: true,
|
||||
areGradesFrozen: expectedAreGradesFrozen,
|
||||
};
|
||||
expect(
|
||||
assignmentTypes(undefined, actions.gotGradesFrozen(expectedAreGradesFrozen)),
|
||||
assignmentTypes(testingState, actions.gotGradesFrozen(expectedAreGradesFrozen)),
|
||||
).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -27,7 +27,9 @@ const cohortsData = [
|
||||
|
||||
describe('cohorts reducer', () => {
|
||||
it('has initial state', () => {
|
||||
expect(cohorts(undefined, {})).toEqual(initialState);
|
||||
expect(
|
||||
cohorts(undefined, {}),
|
||||
).toEqual(initialState);
|
||||
});
|
||||
|
||||
it('updates fetch cohorts request state', () => {
|
||||
@@ -52,6 +54,28 @@ describe('cohorts reducer', () => {
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
it('updates fetch cohorts success state with arbitrary objects', () => {
|
||||
const arbitraryCohortsData = [
|
||||
{
|
||||
a: 'cohort',
|
||||
another: 'COHort',
|
||||
},
|
||||
{
|
||||
b: 'cohort_b',
|
||||
another: 'cohORT_B',
|
||||
},
|
||||
];
|
||||
const expected = {
|
||||
...initialState,
|
||||
results: arbitraryCohortsData,
|
||||
errorFetching: false,
|
||||
finishedFetching: true,
|
||||
};
|
||||
expect(
|
||||
cohorts(undefined, actions.fetching.received(arbitraryCohortsData)),
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
it('updates fetch cohorts failure state', () => {
|
||||
const expected = {
|
||||
...initialState,
|
||||
|
||||
@@ -17,29 +17,9 @@ const testingState = {
|
||||
|
||||
describe('filter reducer group', () => {
|
||||
it('has initial state', () => {
|
||||
expect(filter(undefined, {})).toEqual(initialState);
|
||||
});
|
||||
|
||||
it('filter by assignment type', () => {
|
||||
const expected = {
|
||||
...testingState,
|
||||
assignmentType: expectedFilterType,
|
||||
};
|
||||
expect(filter(testingState, actions.update.assignmentType({
|
||||
filterType: expectedFilterType,
|
||||
}))).toEqual(expected);
|
||||
});
|
||||
|
||||
it('filter on not existed assignment type', () => {
|
||||
const notExistFilter = 'not exist filter';
|
||||
const expected = {
|
||||
...testingState,
|
||||
assignmentType: notExistFilter,
|
||||
assignment: '',
|
||||
};
|
||||
expect(filter(testingState, actions.update.assignmentType({
|
||||
filterType: notExistFilter,
|
||||
}))).toEqual(expected);
|
||||
expect(
|
||||
filter(undefined, {}),
|
||||
).toEqual(initialState);
|
||||
});
|
||||
|
||||
it('initialize', () => {
|
||||
@@ -61,12 +41,44 @@ describe('filter reducer group', () => {
|
||||
id: payload.assignment,
|
||||
},
|
||||
};
|
||||
expect(filter(undefined, actions.initialize(payload))).toEqual(expected);
|
||||
expect(
|
||||
filter(undefined, actions.initialize(payload)),
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
it('reset', () => {
|
||||
const payload = Object.keys(initialFilters);
|
||||
expect(filter(testingState, actions.reset(payload))).toEqual(initialFilters);
|
||||
expect(
|
||||
filter(testingState, actions.reset(payload)),
|
||||
).toEqual(initialFilters);
|
||||
});
|
||||
});
|
||||
|
||||
describe('handle actions.update.assignmentType', () => {
|
||||
it('get assignments for filtering with exist assignment type', () => {
|
||||
const expected = {
|
||||
...testingState,
|
||||
assignmentType: expectedFilterType,
|
||||
};
|
||||
expect(
|
||||
filter(testingState, actions.update.assignmentType({
|
||||
filterType: expectedFilterType,
|
||||
})),
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
it('clear the assignment if assignment type not existed', () => {
|
||||
const notExistFilter = 'not exist filter';
|
||||
const expected = {
|
||||
...testingState,
|
||||
assignmentType: notExistFilter,
|
||||
assignment: '',
|
||||
};
|
||||
expect(
|
||||
filter(testingState, actions.update.assignmentType({
|
||||
filterType: notExistFilter,
|
||||
})),
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
it('update assignment', () => {
|
||||
@@ -124,7 +136,7 @@ describe('filter reducer group', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('grade reducer group', () => {
|
||||
describe('handling of receiving grade action', () => {
|
||||
const expectedTrack = 'verified';
|
||||
const expectedCohortId = 5;
|
||||
const grades = [
|
||||
@@ -151,11 +163,13 @@ describe('grade reducer group', () => {
|
||||
cohort: expectedCohortId,
|
||||
};
|
||||
|
||||
expect(filter(testingState, gradeActions.received({
|
||||
grades,
|
||||
track: expectedTrack,
|
||||
cohort: expectedCohortId,
|
||||
}))).toEqual(expected);
|
||||
expect(
|
||||
filter(testingState, gradeActions.received({
|
||||
grades,
|
||||
track: expectedTrack,
|
||||
cohort: expectedCohortId,
|
||||
})),
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
it('grade receive with assignment type', () => {
|
||||
@@ -164,9 +178,11 @@ describe('grade reducer group', () => {
|
||||
track: expectedTrack,
|
||||
cohort: expectedCohortId,
|
||||
};
|
||||
expect(filter(testingState, gradeActions.received({
|
||||
track: expectedTrack,
|
||||
cohort: expectedCohortId,
|
||||
}))).toEqual(expected);
|
||||
expect(
|
||||
filter(testingState, gradeActions.received({
|
||||
track: expectedTrack,
|
||||
cohort: expectedCohortId,
|
||||
})),
|
||||
).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -63,7 +63,9 @@ const gradesData = [
|
||||
|
||||
describe('grades reducer group', () => {
|
||||
it('has initial state', () => {
|
||||
expect(grades(undefined, {})).toEqual(initialState);
|
||||
expect(
|
||||
grades(undefined, {}),
|
||||
).toEqual(initialState);
|
||||
});
|
||||
|
||||
it('updates fetch grades request state', () => {
|
||||
@@ -72,9 +74,11 @@ describe('grades reducer group', () => {
|
||||
startedFetching: true,
|
||||
showSpinner: true,
|
||||
};
|
||||
expect(grades(undefined, {
|
||||
type: actions.fetching.started.toString(),
|
||||
})).toEqual(expected);
|
||||
expect(
|
||||
grades(undefined, {
|
||||
type: actions.fetching.started.toString(),
|
||||
}),
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
it('updates fetch grades success state', () => {
|
||||
@@ -98,17 +102,19 @@ describe('grades reducer group', () => {
|
||||
filteredUsersCount: expectedFilterUsersCount,
|
||||
};
|
||||
|
||||
expect(grades(undefined, actions.received({
|
||||
grades: gradesData,
|
||||
headings: headingsData,
|
||||
next: expectedNext,
|
||||
prev: expectedPrev,
|
||||
track: expectedTrack,
|
||||
totalUsersCount: expectedTotalUsersCount,
|
||||
cohort: expectedCohortId,
|
||||
courseId,
|
||||
filteredUsersCount: expectedFilterUsersCount,
|
||||
}))).toEqual(expected);
|
||||
expect(
|
||||
grades(undefined, actions.received({
|
||||
grades: gradesData,
|
||||
headings: headingsData,
|
||||
next: expectedNext,
|
||||
prev: expectedPrev,
|
||||
track: expectedTrack,
|
||||
totalUsersCount: expectedTotalUsersCount,
|
||||
cohort: expectedCohortId,
|
||||
courseId,
|
||||
filteredUsersCount: expectedFilterUsersCount,
|
||||
})),
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
it('updates toggle grade format state success', () => {
|
||||
@@ -117,8 +123,9 @@ describe('grades reducer group', () => {
|
||||
...initialState,
|
||||
gradeFormat: formatTypeData,
|
||||
};
|
||||
expect(grades(undefined, actions.toggleGradeFormat(formatTypeData)))
|
||||
.toEqual(expected);
|
||||
expect(
|
||||
grades(undefined, actions.toggleGradeFormat(formatTypeData)),
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
it('updates filter columns state success', () => {
|
||||
@@ -128,10 +135,12 @@ describe('grades reducer group', () => {
|
||||
selectedAssignmentType: expectedSelectedAssignmentType,
|
||||
headings: headingsData,
|
||||
};
|
||||
expect(grades(undefined, filterActions.update.assignmentType({
|
||||
headings: headingsData,
|
||||
filterType: expectedSelectedAssignmentType,
|
||||
}))).toEqual(expected);
|
||||
expect(
|
||||
grades(undefined, filterActions.update.assignmentType({
|
||||
headings: headingsData,
|
||||
filterType: expectedSelectedAssignmentType,
|
||||
})),
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
it('updates fetch grades failure state', () => {
|
||||
@@ -140,7 +149,9 @@ describe('grades reducer group', () => {
|
||||
errorFetching: true,
|
||||
finishedFetching: true,
|
||||
};
|
||||
expect(grades(undefined, actions.fetching.error())).toEqual(expected);
|
||||
expect(
|
||||
grades(undefined, actions.fetching.error()),
|
||||
).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -151,7 +162,9 @@ describe('banner group', () => {
|
||||
...initialState,
|
||||
showSuccess: expectedShowSuccess,
|
||||
};
|
||||
expect(grades(undefined, actions.banner.open())).toEqual(expected);
|
||||
expect(
|
||||
grades(undefined, actions.banner.open()),
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
it('updates update_banner state fail', () => {
|
||||
@@ -160,7 +173,9 @@ describe('banner group', () => {
|
||||
...initialState,
|
||||
showSuccess: expectedShowSuccess,
|
||||
};
|
||||
expect(grades(undefined, actions.banner.close())).toEqual(expected);
|
||||
expect(
|
||||
grades(undefined, actions.banner.close()),
|
||||
).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -290,7 +305,8 @@ describe('viewing assignment group', () => {
|
||||
gradeOriginalPossibleGraded,
|
||||
...expected
|
||||
} = initialState;
|
||||
expect(grades(undefined, actions.doneViewingAssignment()))
|
||||
.toEqual(expected);
|
||||
expect(
|
||||
grades(undefined, actions.doneViewingAssignment()),
|
||||
).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,7 +7,9 @@ const initialState = {
|
||||
|
||||
describe('tracks reducer', () => {
|
||||
it('has initial state', () => {
|
||||
expect(roles(undefined, {})).toEqual(initialState);
|
||||
expect(
|
||||
roles(undefined, {}),
|
||||
).toEqual(initialState);
|
||||
});
|
||||
|
||||
it('updates canUserViewGradebook to true', () => {
|
||||
@@ -15,7 +17,9 @@ describe('tracks reducer', () => {
|
||||
...initialState,
|
||||
canUserViewGradebook: true,
|
||||
};
|
||||
expect(roles(undefined, actions.received(true))).toEqual(expected);
|
||||
expect(
|
||||
roles(undefined, actions.received(true)),
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
it('updates canUserViewGradebook to false', () => {
|
||||
@@ -23,7 +27,9 @@ describe('tracks reducer', () => {
|
||||
...initialState,
|
||||
canUserViewGradebook: false,
|
||||
};
|
||||
expect(roles(undefined, actions.received(false))).toEqual(expected);
|
||||
expect(
|
||||
roles(undefined, actions.received(false)),
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
it('updates fetch roles failure state', () => {
|
||||
@@ -31,6 +37,8 @@ describe('tracks reducer', () => {
|
||||
...initialState,
|
||||
canUserViewGradebook: false,
|
||||
};
|
||||
expect(roles(undefined, actions.errorFetching())).toEqual(expected);
|
||||
expect(
|
||||
roles(undefined, actions.errorFetching()),
|
||||
).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -33,7 +33,9 @@ const tracksData = [
|
||||
|
||||
describe('tracks reducer', () => {
|
||||
it('has initial state', () => {
|
||||
expect(tracks(undefined, {})).toEqual(initialState);
|
||||
expect(
|
||||
tracks(undefined, {}),
|
||||
).toEqual(initialState);
|
||||
});
|
||||
|
||||
it('updates fetch tracks request state', () => {
|
||||
@@ -41,7 +43,9 @@ describe('tracks reducer', () => {
|
||||
...initialState,
|
||||
startedFetching: true,
|
||||
};
|
||||
expect(tracks(undefined, actions.fetching.started())).toEqual(expected);
|
||||
expect(
|
||||
tracks(undefined, actions.fetching.started()),
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
it('updates fetch tracks success state', () => {
|
||||
@@ -51,7 +55,9 @@ describe('tracks reducer', () => {
|
||||
errorFetching: false,
|
||||
finishedFetching: true,
|
||||
};
|
||||
expect(tracks(undefined, actions.fetching.received(tracksData))).toEqual(expected);
|
||||
expect(
|
||||
tracks(undefined, actions.fetching.received(tracksData)),
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
it('updates fetch tracks failure state', () => {
|
||||
@@ -60,6 +66,8 @@ describe('tracks reducer', () => {
|
||||
errorFetching: true,
|
||||
finishedFetching: true,
|
||||
};
|
||||
expect(tracks(undefined, actions.fetching.error())).toEqual(expected);
|
||||
expect(
|
||||
tracks(undefined, actions.fetching.error()),
|
||||
).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user