Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

James crt test updates #195

Merged
merged 17 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 41 additions & 29 deletions surveys/CRT/CRT.cy.jsx
Original file line number Diff line number Diff line change
@@ -1,52 +1,64 @@
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", () => {
it("completes the survey", () => {
describe("CRT", () => {
it("fail if not entered correctly", () => {
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="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}"]`
).type(numberToEnter);

cy.get(
`[data-name="${element.name}"] input[type="${element.inputType}"]`
).should("have.value", numberToEnter.toString());
});
cy.get("form") // submit surveyJS form
.then(($form) => {
cy.wrap($form.find('input[type="button"][value="Complete"]')).click();
});

cy.screenshot("CRT/screenshot", {
overwrite: true,
});
cy.get(".sv-body").should("exist");

cy.get("@callback").should("not.have.been.called");
});

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

cy.get("form") // submit surveyJS form
.then(($form) => {
cy.wrap($form.find('input[type="button"][value="Complete"]')).click();
});
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(10); // wrong
cy.get('[data-name="dog_cat"] input[type="number"]').type(100000000000); // wrong

cy.get(".sv-body").should("not.exist");
cy.screenshot("CRT/screenshot", {
overwrite: true,
});

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("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("@callback").should("have.been.called");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are typing a string into a number field and still getting completion? That shouldn't be possible. I can see from the screenshot also that the field is empty when the test inputs cat

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other words, this part of the test should fail?

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));
});
});
});
Loading
Loading