Skip to content

Commit c1bf245

Browse files
Update CRT test
1 parent b1cd62b commit c1bf245

File tree

3 files changed

+21
-31
lines changed

3 files changed

+21
-31
lines changed

surveys/CRT/CRT.cy.jsx

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,42 @@
11
import React from "react";
22
import { CRT } from "../../src/index";
33

4-
const surveyJsonPath = "surveys/CRT/CRT.json";
5-
64
// Initialize an empty answers object
75

86
const dummy = {
97
set(response) {},
108
};
119

12-
describe("RMETTen", () => {
10+
describe("CRT", () => {
1311
it("completes the survey", () => {
1412
cy.spy(dummy, "set").as("callback");
1513
cy.mount(<CRT onComplete={dummy.set} />);
1614
cy.viewport("macbook-11");
1715

18-
cy.readFile(surveyJsonPath).then((surveyJson) => {
19-
surveyJson.pages.forEach((page) => {
20-
page.elements.forEach((element) => {
21-
const numberToEnter = 15;
22-
23-
cy.get(
24-
`[data-name="${element.name}"] input[type="${element.inputType}"]`
25-
).type(numberToEnter);
16+
cy.get('[data-name="drill_hammer"] input[type="number"]').type(15); // correct
17+
cy.get('[data-name="rachel"] input[type="number"]').type(19); // correct
18+
cy.get('[data-name="toaster"] input[type="number"]').type(125); // correct
19+
cy.get('[data-name="apples"] input[type="number"]').type(-3); // wrong
20+
cy.get('[data-name="eggs"] input[type="number"]').type("cat"); // wrong
21+
cy.get('[data-name="dog_cat"] input[type="number"]').type(100000000000); // wrong
2622

27-
cy.get(
28-
`[data-name="${element.name}"] input[type="${element.inputType}"]`
29-
).should("have.value", numberToEnter.toString());
30-
});
31-
});
23+
cy.screenshot("CRT/screenshot", {
24+
overwrite: true,
25+
});
3226

33-
cy.screenshot("CRT/screenshot", {
34-
overwrite: true,
27+
cy.get("form") // submit surveyJS form
28+
.then(($form) => {
29+
cy.wrap($form.find('input[type="button"][value="Complete"]')).click();
3530
});
3631

37-
cy.get("form") // submit surveyJS form
38-
.then(($form) => {
39-
cy.wrap($form.find('input[type="button"][value="Complete"]')).click();
40-
});
41-
42-
cy.get(".sv-body").should("not.exist");
32+
cy.get(".sv-body").should("not.exist");
4333

44-
cy.get("@callback").should("have.been.called");
45-
cy.get("@callback").then((spy) => {
46-
const spyCall = spy.getCall(-1).args[0];
47-
console.log(spyCall);
48-
expect(spyCall["result"]["score"]).to.eq(2.0);
49-
});
34+
cy.get("@callback").should("have.been.called");
35+
cy.get("@callback").then((spy) => {
36+
const spyCall = spy.getCall(-1).args[0];
37+
console.log(spyCall);
38+
expect(spyCall["result"]["score"]).to.eq(3);
39+
expect(spyCall["result"]["normScore"]).to.eq((0.5).toFixed(3));
5040
});
5141
});
5242
});

surveys/CRT/CRT.score.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ export default function scoreFunc(responses) {
2727
}
2828
});
2929

30-
return { score: score, maxScore: 6, minScore: 0, responses: responses };
30+
return { score: score, normScore: (score / 6).toFixed(3) };
3131
}

surveys/CRT/screenshot.png

-24.2 KB
Loading

0 commit comments

Comments
 (0)