Skip to content

Commit

Permalink
Merge branch 'master' into EAR-2546-cloud-script-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
farres1 authored Dec 9, 2024
2 parents 1da65ac + 4079f2b commit 7c066a0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
18 changes: 13 additions & 5 deletions eq-author/src/App/qcodes/QCodesTable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,25 @@ const Row = memo((props) => {

const handleBlur = useCallback(
(qCode) => {
const trimmedQcode = qCode.trim().replace(/\s+/g, " ");
setQcode(trimmedQcode);
if (qCode !== initialQcode) {
if (option) {
updateOption(mutationVariables({ id, qCode }));
updateOption(mutationVariables({ id, qCode: trimmedQcode }));
} else if (listAnswerType === DRIVING) {
// id represents the list collector page ID
updateListCollector(mutationVariables({ id, drivingQCode: qCode }));
updateListCollector(
mutationVariables({ id, drivingQCode: trimmedQcode })
);
} else if (listAnswerType === ANOTHER) {
updateListCollector(mutationVariables({ id, anotherQCode: qCode }));
updateListCollector(
mutationVariables({ id, anotherQCode: trimmedQcode })
);
} else {
updateAnswer(
mutationVariables({
id,
[secondary ? "secondaryQCode" : "qCode"]: qCode,
[secondary ? "secondaryQCode" : "qCode"]: trimmedQcode,
})
);
}
Expand All @@ -187,7 +193,9 @@ const Row = memo((props) => {

const handleBlurOptionValue = useCallback(
(value) => {
updateValue(mutationVariables({ id, value }));
const trimmedValue = value?.trim().replace(/\s+/g, " ");
setValue(trimmedValue);
updateValue(mutationVariables({ id, value: trimmedValue }));
},
[id, updateValue]
);
Expand Down
23 changes: 21 additions & 2 deletions eq-author/src/App/qcodes/QCodesTable/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -724,14 +724,33 @@ describe("Qcode Table", () => {

it("should save qCode for checkbox answer", () => {
fireEvent.change(utils.getByTestId("checkbox-answer-id-test-input"), {
target: { value: "123" },
target: { value: " test qcode " },
});

fireEvent.blur(utils.getByTestId("checkbox-answer-id-test-input"));

expect(mock).toHaveBeenCalledWith({
variables: {
input: { id: "checkbox-answer-id", qCode: "123" },
input: { id: "checkbox-answer-id", qCode: "test qcode" },
},
});
});

it("should save option value for checkbox answer", () => {
fireEvent.change(
utils.getByTestId("checkbox-option-1-id-value-test-input"),
{
target: { value: " test option value " },
}
);

fireEvent.blur(
utils.getByTestId("checkbox-option-1-id-value-test-input")
);

expect(mock).toHaveBeenCalledWith({
variables: {
input: { id: "checkbox-option-1-id", value: "test option value" },
},
});
});
Expand Down

0 comments on commit 7c066a0

Please sign in to comment.