|
1 | 1 | import React from "react";
|
2 | 2 | import { CRT } from "../../src/index";
|
3 | 3 |
|
4 |
| -const surveyJsonPath = "surveys/CRT/CRT.json"; |
5 |
| - |
6 | 4 | // Initialize an empty answers object
|
7 | 5 |
|
8 | 6 | const dummy = {
|
9 | 7 | set(response) {},
|
10 | 8 | };
|
11 | 9 |
|
12 |
| -describe("RMETTen", () => { |
| 10 | +describe("CRT", () => { |
13 | 11 | it("completes the survey", () => {
|
14 | 12 | cy.spy(dummy, "set").as("callback");
|
15 | 13 | cy.mount(<CRT onComplete={dummy.set} />);
|
16 | 14 | cy.viewport("macbook-11");
|
17 | 15 |
|
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 |
26 | 22 |
|
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 | + }); |
32 | 26 |
|
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(); |
35 | 30 | });
|
36 | 31 |
|
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"); |
43 | 33 |
|
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)); |
50 | 40 | });
|
51 | 41 | });
|
52 | 42 | });
|
0 commit comments