Skip to content

Commit

Permalink
Update CRT test
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesPHoughton committed Sep 16, 2024
1 parent b1cd62b commit c1bf245
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 31 deletions.
50 changes: 20 additions & 30 deletions surveys/CRT/CRT.cy.jsx
Original file line number Diff line number Diff line change
@@ -1,52 +1,42 @@
import React from "react";
import { CRT } from "../../src/index";

const surveyJsonPath = "surveys/CRT/CRT.json";

// Initialize an empty answers object

const dummy = {
set(response) {},
};

describe("RMETTen", () => {
describe("CRT", () => {
it("completes the survey", () => {
cy.spy(dummy, "set").as("callback");
cy.mount(<CRT onComplete={dummy.set} />);
cy.viewport("macbook-11");

cy.readFile(surveyJsonPath).then((surveyJson) => {
surveyJson.pages.forEach((page) => {
page.elements.forEach((element) => {
const numberToEnter = 15;

cy.get(
`[data-name="${element.name}"] input[type="${element.inputType}"]`
).type(numberToEnter);
cy.get('[data-name="drill_hammer"] input[type="number"]').type(15); // correct
cy.get('[data-name="rachel"] input[type="number"]').type(19); // correct
cy.get('[data-name="toaster"] input[type="number"]').type(125); // correct
cy.get('[data-name="apples"] input[type="number"]').type(-3); // wrong
cy.get('[data-name="eggs"] input[type="number"]').type("cat"); // wrong
cy.get('[data-name="dog_cat"] input[type="number"]').type(100000000000); // wrong

cy.get(
`[data-name="${element.name}"] input[type="${element.inputType}"]`
).should("have.value", numberToEnter.toString());
});
});
cy.screenshot("CRT/screenshot", {
overwrite: true,
});

cy.screenshot("CRT/screenshot", {
overwrite: true,
cy.get("form") // submit surveyJS form
.then(($form) => {
cy.wrap($form.find('input[type="button"][value="Complete"]')).click();
});

cy.get("form") // submit surveyJS form
.then(($form) => {
cy.wrap($form.find('input[type="button"][value="Complete"]')).click();
});

cy.get(".sv-body").should("not.exist");
cy.get(".sv-body").should("not.exist");

cy.get("@callback").should("have.been.called");
cy.get("@callback").then((spy) => {
const spyCall = spy.getCall(-1).args[0];
console.log(spyCall);
expect(spyCall["result"]["score"]).to.eq(2.0);
});
cy.get("@callback").should("have.been.called");
cy.get("@callback").then((spy) => {
const spyCall = spy.getCall(-1).args[0];
console.log(spyCall);
expect(spyCall["result"]["score"]).to.eq(3);
expect(spyCall["result"]["normScore"]).to.eq((0.5).toFixed(3));
});
});
});
2 changes: 1 addition & 1 deletion surveys/CRT/CRT.score.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ export default function scoreFunc(responses) {
}
});

return { score: score, maxScore: 6, minScore: 0, responses: responses };
return { score: score, normScore: (score / 6).toFixed(3) };
}
Binary file modified surveys/CRT/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c1bf245

Please sign in to comment.