-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1cd62b
commit c1bf245
Showing
3 changed files
with
21 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.