fix remove problem placeholder answer text (#215)

* refactor: rename hook correctly

* fix: problem templates
This commit is contained in:
Jesper Hodge
2023-01-25 15:02:35 -05:00
committed by GitHub
parent 2d669cbe3e
commit 83acc741f5
8 changed files with 19 additions and 20 deletions

View File

@@ -28,7 +28,7 @@ export const AnswerOption = ({
const dispatch = useDispatch();
const removeAnswer = hooks.removeAnswer({ answer, dispatch });
const setAnswer = hooks.setAnswer({ answer, hasSingleAnswer, dispatch });
const { isFeedbackVisible, toggleFeedback } = hooks.prepareFeedback(answer);
const { isFeedbackVisible, toggleFeedback } = hooks.useFeedback(answer);
return (
<Collapsible.Advanced

View File

@@ -36,16 +36,16 @@ describe('Answer Options Hooks', () => {
describe('state hooks', () => {
state.testGetter(state.keys.isFeedbackVisible);
});
describe('prepareFeedback hook', () => {
describe('useFeedback hook', () => {
beforeEach(() => { state.mock(); });
afterEach(() => { state.restore(); });
test('test default state is false', () => {
output = module.prepareFeedback(answerWithOnlyFeedback);
output = module.useFeedback(answerWithOnlyFeedback);
expect(output.isFeedbackVisible).toBeFalsy();
});
test('when useEffect triggers, isFeedbackVisible is set to true', () => {
const key = state.keys.isFeedbackVisible;
output = module.prepareFeedback(answerWithOnlyFeedback);
output = module.useFeedback(answerWithOnlyFeedback);
expect(state.setState[key]).not.toHaveBeenCalled();
const [cb, prereqs] = useEffect.mock.calls[0];
expect(prereqs[0]).toStrictEqual(answerWithOnlyFeedback);

View File

@@ -16,7 +16,7 @@ export const setAnswer = ({ answer, hasSingleAnswer, dispatch }) => (payload) =>
dispatch(actions.problem.updateAnswer({ id: answer.id, hasSingleAnswer, ...payload }));
};
export const prepareFeedback = (answer) => {
export const useFeedback = (answer) => {
const [isFeedbackVisible, setIsFeedbackVisible] = module.state.isFeedbackVisible(false);
useEffect(() => {
// Show feedback fields if feedback is present
@@ -55,5 +55,5 @@ export const useAnswerContainer = ({ answers, updateField }) => {
};
export default {
state, removeAnswer, setAnswer, prepareFeedback, isSingleAnswerProblem, useAnswerContainer,
state, removeAnswer, setAnswer, useFeedback, isSingleAnswerProblem, useAnswerContainer,
};

View File

@@ -3,11 +3,11 @@ export const dropdown = `<problem>
<optionresponse>
<p>Enter your question</p>
<optioninput>
<option correct="False">an incorrect answer</option>
<option correct="True">the correct answer</option>
<option correct="False">an incorrect answer</option>
<option correct="True"></option>
<option correct="False"></option>
<option correct="False"></option>
</optioninput>
</optionresponse>
</problem>`
export default dropdown;
export default dropdown;

View File

@@ -3,10 +3,9 @@
<choiceresponse>
<p>Enter your question</p>
<checkboxgroup>
<choice correct="true">a correct answer</choice>
<choice correct="false">an incorrect answer</choice>
<choice correct="false">an incorrect answer</choice>
<choice correct="true">a correct answer</choice>
<choice correct="true"></choice>
<choice correct="false"></choice>
<choice correct="false"></choice>
</checkboxgroup>
</choiceresponse>
</problem>`

View File

@@ -1,6 +1,6 @@
/* eslint-disable */
export const numeric = `<problem>
<numericalresponse answer="100">
<numericalresponse>
<p>Enter your question</p>
<responseparam type="tolerance" default="5"/>
<formulaequationinput/>

View File

@@ -3,9 +3,9 @@ export const singleSelect = `<problem>
<multiplechoiceresponse>
<p>Enter your question</p>
<choicegroup>
<choice correct="false">an incorrect answer</choice>
<choice correct="true">the correct answer</choice>
<choice correct="false">an incorrect answer</choice>
<choice correct="true"></choice>
<choice correct="false"></choice>
<choice correct="false"></choice>
</choicegroup>
</multiplechoiceresponse>
</problem>`

View File

@@ -1,8 +1,8 @@
/* eslint-disable */
const textInput =`<problem>
<stringresponse answer="the correct answer" type="ci">
<stringresponse type="ci">
<p>Enter your question</p>
<additional_answer answer="optional acceptable variant of the correct answer"/>
<additional_answer />
<textline size="20"/>
</stringresponse>
</problem>`