-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5e7ba4
commit 04b3190
Showing
21 changed files
with
371 additions
and
94 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
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,85 @@ | ||
import { mocked } from 'ts-jest/utils'; | ||
|
||
import { usePageData } from 'data/services/lms/hooks/selectors'; | ||
import { updatePageData } from 'data/services/lms/hooks/actions'; | ||
|
||
jest.mock('data/services/lms/hooks/selectors'); | ||
jest.mock('data/services/lms/hooks/actions'); | ||
|
||
const mockedUsePageData = mocked(usePageData); | ||
const mockedUpdatePageData = mocked(updatePageData); | ||
|
||
import { useCriterionData } from './hooks'; | ||
|
||
describe('useCriterionData', () => { | ||
const criterion = { | ||
name: 'criterion-1', | ||
} | ||
|
||
const mutateFn = jest.fn(); | ||
|
||
mockedUsePageData.mockReturnValue({ | ||
rubric: { | ||
optionsSelected: { | ||
'criterion-1': 'option-1', | ||
'criterion-2': 'option-2', | ||
}, | ||
criterionFeedback: { | ||
'criterion-1': 'feedback-1', | ||
'criterion-2': 'feedback-2', | ||
}, | ||
}, | ||
} as any); | ||
|
||
mockedUpdatePageData.mockReturnValue({ | ||
mutate: mutateFn, | ||
} as any); | ||
|
||
it('should return radio and feedback values', () => { | ||
const { radio, feedback } = useCriterionData({ criterion }); | ||
|
||
expect(radio.value).toBe('option-1'); | ||
expect(radio.isInvalid).toBe(false); | ||
expect(feedback.value).toBe('feedback-1'); | ||
expect(feedback.isInvalid).toBe(false); | ||
}); | ||
|
||
test('radio onChange should call mutate with updated rubric', () => { | ||
const { radio } = useCriterionData({ criterion }); | ||
|
||
radio.onChange({ target: { value: 'option-3' } }); | ||
|
||
expect(mutateFn).toHaveBeenCalledWith({ | ||
rubric: { | ||
optionsSelected: { | ||
'criterion-1': 'option-3', | ||
'criterion-2': 'option-2', | ||
}, | ||
criterionFeedback: { | ||
'criterion-1': 'feedback-1', | ||
'criterion-2': 'feedback-2', | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
test('feedback onChange should call mutate with updated rubric', () => { | ||
const { feedback } = useCriterionData({ criterion }); | ||
|
||
feedback.onChange({ target: { value: 'feedback-3' } }); | ||
|
||
expect(mutateFn).toHaveBeenCalledWith({ | ||
rubric: { | ||
optionsSelected: { | ||
'criterion-1': 'option-1', | ||
'criterion-2': 'option-2', | ||
}, | ||
criterionFeedback: { | ||
'criterion-1': 'feedback-3', | ||
'criterion-2': 'feedback-2', | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
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,48 @@ | ||
import { usePageData } from 'data/services/lms/hooks/selectors'; | ||
import { updatePageData } from 'data/services/lms/hooks/actions'; | ||
|
||
export const useCriterionData = ({ | ||
criterion, | ||
}) => { | ||
const data = usePageData(); | ||
const mutation = updatePageData(); | ||
|
||
const updateRadio = ({ target }) => { | ||
mutation.mutate({ | ||
...data, | ||
rubric: { | ||
...data.rubric, | ||
optionsSelected: { | ||
...data.rubric.optionsSelected, | ||
[criterion.name]: target.value, | ||
} | ||
} | ||
} as any); | ||
}; | ||
|
||
const updateFeedback = ({ target }) => { | ||
mutation.mutate({ | ||
...data, | ||
rubric: { | ||
...data.rubric, | ||
criterionFeedback: { | ||
...data.rubric.criterionFeedback, | ||
[criterion.name]: target.value, | ||
} | ||
} | ||
} as any); | ||
}; | ||
|
||
return { | ||
radio: { | ||
value: data.rubric.optionsSelected[criterion.name], | ||
isInvalid: false, | ||
onChange: updateRadio, | ||
}, | ||
feedback: { | ||
value: data.rubric.criterionFeedback[criterion.name], | ||
isInvalid: false, | ||
onChange: updateFeedback, | ||
}, | ||
}; | ||
}; |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { usePageData, useRubricConfig } from 'data/services/lms/hooks/selectors'; | ||
import { updatePageData } from 'data/services/lms/hooks/actions'; | ||
|
||
export const useRubricData = ({ | ||
isGrading, | ||
}) => { | ||
const { feedbackConfig } = useRubricConfig(); | ||
const data = usePageData(); | ||
const mutation = updatePageData(); | ||
|
||
const onOverallFeedbackChange = ({ target }) => { | ||
mutation.mutate({ | ||
...data, | ||
rubric: { | ||
...data.rubric, | ||
overallFeedback: target.value, | ||
} | ||
} as any); | ||
}; | ||
|
||
return { | ||
feedbackPrompt: feedbackConfig.defaultText, | ||
value: data.rubric.overallFeedback, | ||
onChange: onOverallFeedbackChange, | ||
disabled: !isGrading, | ||
isInvalid: false, | ||
}; | ||
}; |
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
Oops, something went wrong.