-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for Redux selectors (#180)
* test: add selector tests * refactor: remove unused typeOfSelectedAssignment * chore: bump version to 1.4.26 Co-authored-by: Ben Warzeski <[email protected]>
- Loading branch information
1 parent
0c242ab
commit 807a57d
Showing
11 changed files
with
728 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import selectors from './assignmentTypes'; | ||
|
||
describe('areGradesFrozen', () => { | ||
it('selects areGradesFrozen from state', () => { | ||
const testValue = 'THX 1138'; | ||
const areGradesFrozen = selectors.areGradesFrozen({ assignmentTypes: { areGradesFrozen: testValue } }); | ||
expect(areGradesFrozen).toEqual(testValue); | ||
}); | ||
}); | ||
|
||
describe('allAssignmentTypes', () => { | ||
it('returns assignment types', () => { | ||
const testAssignmentTypes = ['assignment', 'labs']; | ||
const allAssignmentTypes = selectors.allAssignmentTypes({ assignmentTypes: { results: testAssignmentTypes } }); | ||
expect(allAssignmentTypes).toEqual(testAssignmentTypes); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import selectors from './cohorts'; | ||
|
||
const testCohorts = [ | ||
{ | ||
id: '1', | ||
name: 'Cohort 1', | ||
}, | ||
{ | ||
id: '9000', | ||
name: 'Cohort 9000', | ||
}, | ||
]; | ||
|
||
const nonMatchingId = '9001'; | ||
|
||
const testState = { cohorts: { results: testCohorts } }; | ||
|
||
describe('getCohortById', () => { | ||
it('returns cohort when a match is found', () => { | ||
const cohort = selectors.getCohortById(testState, testCohorts[0].id); | ||
expect(cohort).toEqual(testCohorts[0]); | ||
}); | ||
it('returns undefined when no match is found', () => { | ||
const cohort = selectors.getCohortById(testState, nonMatchingId); | ||
expect(cohort).toEqual(undefined); | ||
}); | ||
}); | ||
|
||
describe('getCohortNameById', () => { | ||
it('returns a cohort name when cohort matching ID is found', () => { | ||
const cohortName = selectors.getCohortNameById(testState, testCohorts[1].id); | ||
expect(cohortName).toEqual(testCohorts[1].name); | ||
}); | ||
it('returns undefined when no matching cohort is found', () => { | ||
const cohortName = selectors.getCohortNameById(testState, nonMatchingId); | ||
expect(cohortName).toEqual(undefined); | ||
}); | ||
}); | ||
|
||
describe('allCohorts', () => { | ||
it('selects cohorts from state', () => { | ||
const allCohorts = selectors.allCohorts(testState); | ||
expect(allCohorts).toEqual(testCohorts); | ||
}); | ||
it('returns an empty array when no cohort results present in state', () => { | ||
const allCohorts = selectors.allCohorts({ cohorts: {} }); | ||
expect(allCohorts).toEqual([]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import selectors from './filters'; | ||
|
||
const selectedAssignmentInfo = { | ||
category: 'Homework', | ||
id: 'block-v1:edX+type@sequential+block@abcde', | ||
label: 'HW 01', | ||
subsectionLabel: 'Example Week 1: Getting Started', | ||
}; | ||
|
||
const filters = { | ||
assignment: selectedAssignmentInfo, | ||
assignmentGradeMax: '100', | ||
assignmentGradeMin: '0', | ||
assignmentType: 'Homework', | ||
cohort: 'Spring Term', | ||
courseGradeMax: '100', | ||
courseGradeMin: '0', | ||
includeCourseRoleMembers: false, | ||
track: 'masters', | ||
}; | ||
|
||
const noFilters = { | ||
assignment: undefined, | ||
assignmentGradeMax: '100', | ||
assignmentGradeMin: '0', | ||
assignmentType: 'All', | ||
cohort: '', | ||
courseGradeMax: '100', | ||
courseGradeMin: '0', | ||
includeCourseRoleMembers: false, | ||
track: '', | ||
}; | ||
|
||
const sectionBreakdowns = [ | ||
{ | ||
subsection_name: 'Example Week 1: Getting Started', | ||
score_earned: 1, | ||
score_possible: 1, | ||
percent: 1, | ||
displayed_value: '1.00', | ||
grade_description: '(0.00/0.00)', | ||
module_id: 'block-v1:edX+type@sequential+block@abcde', | ||
label: 'HW 01', | ||
category: 'Homework', | ||
}, | ||
{ | ||
subsection_name: 'Example Week 2: Going Deeper', | ||
score_earned: 1, | ||
score_possible: 42, | ||
percent: 0, | ||
displayed_value: '0.02', | ||
grade_description: '(0.00/0.00)', | ||
module_id: 'block-v1:edX+type@sequential+block@bcdef', | ||
label: 'LAB 01', | ||
category: 'Labs', | ||
}, | ||
]; | ||
|
||
const gradesData = { results: [{ section_breakdown: sectionBreakdowns }] }; | ||
|
||
const testState = { | ||
filters, | ||
grades: gradesData, | ||
}; | ||
|
||
describe('allFilters', () => { | ||
it('selects all filters from state', () => { | ||
const allFilters = selectors.allFilters(testState); | ||
expect(allFilters).toEqual(filters); | ||
}); | ||
it('returns an empty object when no filters are in state', () => { | ||
const allFilters = selectors.allFilters({}); | ||
expect(allFilters).toEqual({}); | ||
}); | ||
}); | ||
|
||
describe('selectedAssignmentId', () => { | ||
it('gets filtered assignment ID when available', () => { | ||
const assignmentId = selectors.selectedAssignmentId(testState); | ||
expect(assignmentId).toEqual(filters.assignment.id); | ||
}); | ||
it('returns undefined when assignment ID unavailable', () => { | ||
const assignmentId = selectors.selectedAssignmentId({ filters: { assignment: undefined } }); | ||
expect(assignmentId).toEqual(undefined); | ||
}); | ||
}); | ||
|
||
describe('selectedAssignmentLabel', () => { | ||
it('gets filtered assignment label when available', () => { | ||
const assignmentLabel = selectors.selectedAssignmentLabel(testState); | ||
expect(assignmentLabel).toEqual(filters.assignment.label); | ||
}); | ||
it('returns undefined when assignment label is unavailable', () => { | ||
const assignmentLabel = selectors.selectedAssignmentLabel({ filters: { assignment: undefined } }); | ||
expect(assignmentLabel).toEqual(undefined); | ||
}); | ||
}); | ||
|
||
describe('selectableAssignmentLabels', () => { | ||
it('gets assignment data for sections matching selected type filters', () => { | ||
const selectableAssignmentLabels = selectors.selectableAssignmentLabels(testState); | ||
expect(selectableAssignmentLabels).toEqual([filters.assignment]); | ||
}); | ||
}); | ||
|
||
describe('selectableAssignments', () => { | ||
it('returns all graded assignments when no assignment type filtering is applied', () => { | ||
const selectableAssignments = selectors.selectableAssignments({ grades: gradesData, filters: noFilters }); | ||
expect(selectableAssignments).toEqual(sectionBreakdowns); | ||
}); | ||
it('gets assignments of the selected category when assignment type filtering is applied', () => { | ||
const selectableAssignments = selectors.selectableAssignments(testState); | ||
expect(selectableAssignments).toEqual([sectionBreakdowns[0]]); | ||
}); | ||
}); | ||
|
||
describe('chooseRelevantAssignmentData', () => { | ||
it('maps label, subsection, category, and ID from assignment data', () => { | ||
const assignmentData = selectors.chooseRelevantAssignmentData(sectionBreakdowns[0]); | ||
expect(assignmentData).toEqual(selectedAssignmentInfo); | ||
}); | ||
}); | ||
|
||
describe('getAssignmentsFromResultsSubstate', () => { | ||
it('gets section breakdowns from state', () => { | ||
const assignments = selectors.getAssignmentsFromResultsSubstate(gradesData.results); | ||
expect(assignments).toEqual(sectionBreakdowns); | ||
}); | ||
it('returns an empty array when results are not supplied', () => { | ||
const assignments = selectors.getAssignmentsFromResultsSubstate([]); | ||
expect(assignments).toEqual([]); | ||
}); | ||
it('returns an empty array when section breakdowns are not supplied', () => { | ||
const assignments = selectors.getAssignmentsFromResultsSubstate([{}]); | ||
expect(assignments).toEqual([]); | ||
}); | ||
}); |
Oops, something went wrong.