-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Last E2E component tests (#501)
* fix: Test interstitial page content + replace all whitespaces * chore: remove empty line * tests: validate warning component + button with entry reference * chore: remove log command * feat: inset text validator + slight refactor * feat: Test nav link * docs: update components done
- Loading branch information
1 parent
1bd6d12
commit 38b729e
Showing
12 changed files
with
139 additions
and
61 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
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
41 changes: 36 additions & 5 deletions
41
tests/Dfe.PlanTech.Web.E2ETests/cypress/helpers/content-validators/button-validator.js
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,13 +1,44 @@ | ||
function ValidateButtonWithLink(content) { | ||
const classAssertion = content.fields.button.fields.isStartButton | ||
const button = validateBaseButton(content); | ||
|
||
button.should("have.attr", "href").and("include", content.fields.href); | ||
} | ||
|
||
function validateBaseButton(content) { | ||
const classAssertion = getClassAssertion(content); | ||
|
||
const button = cy | ||
.get("a.govuk-button") | ||
.contains(content.fields.button.fields.value); | ||
|
||
button.should(classAssertion, "govuk-button--start"); | ||
|
||
return button; | ||
} | ||
|
||
function ValidateButtonWithEntryReference(content) { | ||
const button = validateBaseButton(content); | ||
|
||
button.should("have.attr", "href").then((href) => { | ||
if (href.indexOf(content.fields.linkToEntry.fields.href) != -1) { | ||
expect(href).to.include(content.fields.linkToEntry.fields.href); | ||
} else if (href.indexOf("next-question") != -1) { | ||
expect(href).to.include("next-question"); | ||
} else { | ||
throw new Error( | ||
`Could not find button with HREF ${content.fields.linkToEntry.fields.href}` | ||
); | ||
} | ||
}); | ||
} | ||
|
||
function getClassAssertion(content) { | ||
return content.fields.button.fields.isStartButton | ||
? "have.class" | ||
: "not.have.class"; | ||
|
||
cy.get("a.govuk-button") | ||
.contains(content.fields.button.fields.value) | ||
.and(classAssertion, "govuk-button--start"); | ||
} | ||
|
||
export default { | ||
ValidateButtonWithLink, | ||
ValidateButtonWithEntryReference, | ||
}; |
13 changes: 0 additions & 13 deletions
13
tests/Dfe.PlanTech.Web.E2ETests/cypress/helpers/content-validators/button-validator.mjs
This file was deleted.
Oops, something went wrong.
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
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
7 changes: 7 additions & 0 deletions
7
tests/Dfe.PlanTech.Web.E2ETests/cypress/helpers/content-validators/inset-text-validator.js
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { ReplaceWhiteSpace } from "../text-helpers"; | ||
|
||
export default function ValidateInsetTextContent({ fields }) { | ||
cy.get("div.govuk-inset-text").contains( | ||
ReplaceWhiteSpace(fields.text).trim() | ||
); | ||
} |
8 changes: 8 additions & 0 deletions
8
tests/Dfe.PlanTech.Web.E2ETests/cypress/helpers/content-validators/nav-link-validator.js
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default function ValidateNavigationLink({ fields }) { | ||
cy.get( | ||
"ul.govuk-footer__inline-list li.govuk-footer__inline-list-item a.govuk-footer__link" | ||
) | ||
.contains(fields.displayText) | ||
.should("have.attr", "href") | ||
.and("include", fields.href); | ||
} |
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
5 changes: 5 additions & 0 deletions
5
tests/Dfe.PlanTech.Web.E2ETests/cypress/helpers/content-validators/warning-validator.js
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import ValidateRichTextContent from "./rich-text-content-validator"; | ||
|
||
export default function ValidateWarningComponent({ fields, sys }) { | ||
ValidateRichTextContent(fields.text.fields.richText); | ||
} |
11 changes: 10 additions & 1 deletion
11
tests/Dfe.PlanTech.Web.E2ETests/cypress/helpers/text-helpers.js
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,3 +1,12 @@ | ||
const ReplaceNonBreakingHyphen = (text) => text.replace("‑", "‑"); | ||
|
||
export { ReplaceNonBreakingHyphen }; | ||
const ReplaceWhiteSpace = (string) => | ||
string | ||
.replace(/\s/g, " ") | ||
.replace(/ /g, " ") | ||
.replace(/\s/g, " ") | ||
.replace(" ", " ") | ||
.replace(" ", " ") | ||
.replace(" ", " "); | ||
|
||
export { ReplaceNonBreakingHyphen, ReplaceWhiteSpace }; |
14 changes: 0 additions & 14 deletions
14
tests/Dfe.PlanTech.Web.E2ETests/cypress/helpers/warning-validator.js
This file was deleted.
Oops, something went wrong.