chore: redux transform hooks
This commit is contained in:
13
src/data/redux/transforms.js
Normal file
13
src/data/redux/transforms.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import { StrictDict } from 'utils';
|
||||
import selectors from 'data/selectors';
|
||||
|
||||
export const grades = StrictDict({
|
||||
subsectionGrade: ({ gradeFormat, subsection }) => () => (
|
||||
selectors.grades.subsectionGrade[gradeFormat](subsection)
|
||||
),
|
||||
roundGrade: selectors.grades.roundGrade,
|
||||
});
|
||||
|
||||
export default StrictDict({
|
||||
grades,
|
||||
});
|
||||
38
src/data/redux/transforms.test.js
Normal file
38
src/data/redux/transforms.test.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import selectors from 'data/selectors';
|
||||
|
||||
import { GradeFormats } from 'data/constants/grades';
|
||||
import transforms from './transforms';
|
||||
|
||||
jest.mock('data/selectors', () => {
|
||||
const {
|
||||
GradeFormats: { absolute, percent },
|
||||
} = jest.requireActual('data/constants/grades');
|
||||
return {
|
||||
grades: {
|
||||
subsectionGrade: {
|
||||
[absolute]: jest.fn(v => ({ absolute: v })),
|
||||
[percent]: jest.fn(v => ({ percent: v })),
|
||||
},
|
||||
roundGrade: jest.fn(),
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
describe('redux transforms', () => {
|
||||
describe('grades transforms', () => {
|
||||
test('subsectionGrade', () => {
|
||||
const subsection = 'test-subsection';
|
||||
expect(transforms.grades.subsectionGrade({
|
||||
gradeFormat: GradeFormats.absolute,
|
||||
subsection,
|
||||
})()).toEqual(selectors.grades.subsectionGrade.absolute(subsection));
|
||||
expect(transforms.grades.subsectionGrade({
|
||||
gradeFormat: GradeFormats.percent,
|
||||
subsection,
|
||||
})()).toEqual(selectors.grades.subsectionGrade.percent(subsection));
|
||||
});
|
||||
test('roundGrade', () => {
|
||||
expect(transforms.grades.roundGrade).toEqual(selectors.grades.roundGrade);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user