Skip to content

Commit

Permalink
Add calculated summary negative demo (#1219)
Browse files Browse the repository at this point in the history
* add an extra variable to verify values are correct on the summary page

* test signed commits

* verify that all values in the summary are correct

* add tests that were temporarily removed

* Add a minimum value to the schema for the first answer

* add tests to verify negative values are accepted in the first answer

* Add a minimum value to the schema for the second answers

* add tests to verify negative values are accepted by the second answers

* Add a minimum value to the schema for the third answer

* add tests to verify negative values are accepted by the third answer

* add tests to verify negative values are accepted in all answer sections

---------

Co-authored-by: Viraj Patel <[email protected]>
  • Loading branch information
VirajP1002 and Viraj Patel authored Oct 2, 2023
1 parent 5f14275 commit f0a7de8
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 9 deletions.
24 changes: 20 additions & 4 deletions schemas/test/en/test_calculated_summary.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@
"mandatory": true,
"type": "Currency",
"currency": "GBP",
"decimal_places": 2
"decimal_places": 2,
"minimum": {
"value": -1000,
"exclusive": false
}
}
]
}
Expand All @@ -70,7 +74,11 @@
"mandatory": true,
"type": "Currency",
"currency": "GBP",
"decimal_places": 2
"decimal_places": 2,
"minimum": {
"value": -1000,
"exclusive": false
}
},
{
"id": "second-number-answer-unit-total",
Expand All @@ -86,7 +94,11 @@
"mandatory": false,
"type": "Currency",
"currency": "GBP",
"decimal_places": 2
"decimal_places": 2,
"minimum": {
"value": -1000,
"exclusive": false
}
}
]
}
Expand All @@ -105,7 +117,11 @@
"mandatory": true,
"type": "Currency",
"currency": "GBP",
"decimal_places": 2
"decimal_places": 2,
"minimum": {
"value": -1000,
"exclusive": false
}
}
]
}
Expand Down
24 changes: 20 additions & 4 deletions schemas/test/en/test_new_calculated_summary.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@
"mandatory": true,
"type": "Currency",
"currency": "GBP",
"decimal_places": 2
"decimal_places": 2,
"minimum": {
"value": -1000,
"exclusive": false
}
}
]
}
Expand All @@ -70,7 +74,11 @@
"mandatory": true,
"type": "Currency",
"currency": "GBP",
"decimal_places": 2
"decimal_places": 2,
"minimum": {
"value": -1000,
"exclusive": false
}
},
{
"id": "second-number-answer-unit-total",
Expand All @@ -86,7 +94,11 @@
"mandatory": false,
"type": "Currency",
"currency": "GBP",
"decimal_places": 2
"decimal_places": 2,
"minimum": {
"value": -1000,
"exclusive": false
}
}
]
}
Expand All @@ -105,7 +117,11 @@
"mandatory": true,
"type": "Currency",
"currency": "GBP",
"decimal_places": 2
"decimal_places": 2,
"minimum": {
"value": -1000,
"exclusive": false
}
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,30 @@ describe("Feature: Calculated Summary", () => {
CalculatedSummaryTestCase.testCrossSectionDependencies("test_new_calculated_summary_cross_section_dependencies.json");
});
});

describe("Feature: Calculated Summary with negative values", () => {
describe("Given I enter a negative value in the first section", () => {
CalculatedSummaryTestCase.testNegative("test_calculated_summary.json", -1, 2, 3, 0, "£4.00", ["-£1.00", "£2.00", "£3.00", "£0.00"]);
});
describe("Given I enter a negative value in the second section ", () => {
CalculatedSummaryTestCase.testNegative("test_calculated_summary.json", 12, -2, 1, 0, "£11.00", ["£12.00", "-£2.00", "£1.00", "£0.00"]);
});
describe("Given I enter a negative value in the third section ", () => {
CalculatedSummaryTestCase.testNegative("test_calculated_summary.json", 3, 2, -6, 0, "-£1.00", ["£3.00", "£2.00", "-£6.00", "£0.00"]);
});
describe("Given I enter negative values in every currency field ", () => {
CalculatedSummaryTestCase.testNegative("test_calculated_summary.json", -1, -2, -3, 0, "-£6.00", ["-£1.00", "-£2.00", "-£3.00", "£0.00"]);
});
describe("Given I enter a negative value in the first section", () => {
CalculatedSummaryTestCase.testNegative("test_new_calculated_summary.json", -1, 2, 3, 0, "£4.00", ["-£1.00", "£2.00", "£3.00", "£0.00"]);
});
describe("Given I enter a negative value in the second section ", () => {
CalculatedSummaryTestCase.testNegative("test_new_calculated_summary.json", 12, -2, 1, 0, "£11.00", ["£12.00", "-£2.00", "£1.00", "£0.00"]);
});
describe("Given I enter a negative value in the third section ", () => {
CalculatedSummaryTestCase.testNegative("test_new_calculated_summary.json", 3, 2, -6, 0, "-£1.00", ["£3.00", "£2.00", "-£6.00", "£0.00"]);
});
describe("Given I enter negative values in every currency field ", () => {
CalculatedSummaryTestCase.testNegative("test_new_calculated_summary.json", -1, -2, -3, 0, "-£6.00", ["-£1.00", "-£2.00", "-£3.00", "£0.00"]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import SectionSummarySectionOne from "../../../generated_pages/calculated_summar
import SectionSummarySectionTwo from "../../../generated_pages/calculated_summary_cross_section_dependencies/calculated-summary-section-summary.page";
import DependencyQuestionSectionTwo from "../../../generated_pages/calculated_summary_cross_section_dependencies/mutually-exclusive-checkbox.page";
import MinMaxSectionTwo from "../../../generated_pages/calculated_summary_cross_section_dependencies/set-min-max-block.page";
import { click } from "../../../helpers";
import { assertSummaryValues, click } from "../../../helpers";
import { expect } from "@wdio/globals";

class TestCase {
Expand Down Expand Up @@ -422,6 +422,49 @@ class TestCase {
);
});
}

testNegative(schema, firstAnswerValue, secondAnswerValue, thirdAnswerValue, fourthAnswerValue, expectedTotalValue, expectedAnswerValues) {
before("Get to Calculated Summary", async () => {
await browser.openQuestionnaire(schema);

await $(FirstNumberBlockPage.firstNumber()).setValue(firstAnswerValue);
await click(FirstNumberBlockPage.submit());

await $(SecondNumberBlockPage.secondNumber()).setValue(secondAnswerValue);
await $(SecondNumberBlockPage.secondNumberUnitTotal()).setValue(789);
await $(SecondNumberBlockPage.secondNumberAlsoInTotal()).setValue(0);
await click(SecondNumberBlockPage.submit());

await $(ThirdNumberBlockPage.thirdNumber()).setValue(thirdAnswerValue);
await click(ThirdNumberBlockPage.submit());
await $(ThirdAndAHalfNumberBlockPage.thirdAndAHalfNumberUnitTotal()).setValue(678);
await click(ThirdAndAHalfNumberBlockPage.submit());

await $(SkipFourthBlockPage.no()).click();
await click(SkipFourthBlockPage.submit());

await $(FourthNumberBlockPage.fourthNumber()).setValue(fourthAnswerValue);
await click(FourthNumberBlockPage.submit());
await $(FourthAndAHalfNumberBlockPage.fourthAndAHalfNumberAlsoInTotal()).setValue(0);
await click(FourthAndAHalfNumberBlockPage.submit());

await $(FifthNumberBlockPage.fifthPercent()).setValue(56);
await $(FifthNumberBlockPage.fifthNumber()).setValue(78.91);
await click(FifthNumberBlockPage.submit());

await $(SixthNumberBlockPage.sixthPercent()).setValue(23);
await $(SixthNumberBlockPage.sixthNumber()).setValue(45);
await click(SixthNumberBlockPage.submit());

await expect(browser).toHaveUrlContaining(CurrencyTotalPlaybackPage.pageName);
});
it("Given I have entered a range of positive and negative values, When I reach the calculated summary, Then the total is correct", async () => {
assertSummaryValues(expectedAnswerValues);
await expect(await $(CurrencyTotalPlaybackPage.calculatedSummaryTitle()).getText()).toContain(
`We calculate the total of currency values entered to be ${expectedTotalValue}. Is this correct?`,
);
});
}
}

export const CalculatedSummaryTestCase = new TestCase();

0 comments on commit f0a7de8

Please sign in to comment.