Skip to content

Commit

Permalink
Merge pull request #968 from DFE-Digital/tests/247109/fix-dpv-bugs
Browse files Browse the repository at this point in the history
tests(247109): fix dpv bugs
  • Loading branch information
gilaineyo authored Mar 7, 2025
2 parents 8268d0b + 188269f commit 80f46d3
Show file tree
Hide file tree
Showing 31 changed files with 243 additions and 121 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { saveAndContinueButtonText } from "../helpers/constants";

const selectFirstRadioButton = () => {
const questionWithAnswer = {
question: "",
Expand Down Expand Up @@ -32,7 +34,7 @@ const selectFirstRadioButton = () => {
};

const saveAndContinue = () =>
cy.get("form button.govuk-button").contains("Save and continue").click();
cy.get("form button.govuk-button").contains(saveAndContinueButtonText).click();

Cypress.Commands.add("selectFirstRadioButton", selectFirstRadioButton);
Cypress.Commands.add("saveAndContinue", saveAndContinue);
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { submitToSelfAssessmentButtonText, submitToRecommendationsButtonText } from "../helpers/constants";

const navigateToRecommendationPage = () => {
cy.get('a[href*="/recommendation/"]').first().click();
};
Expand Down Expand Up @@ -38,8 +40,8 @@ const navigateThroughQuestions = (selectedQuestionsWithAnswers) => {
.then(() => cy.wrap(selectedQuestionsWithAnswers));
};

const submitAnswersAndGoToSelfAssessment = () => cy.get("button.govuk-button").contains("Submit and go to self-assessment topics").click();
const submitAnswersAndGoToRecommendation = () => cy.get("button.govuk-button").contains("Submit and view recommendation").click();
const submitAnswersAndGoToSelfAssessment = () => cy.get("button.govuk-button").contains(submitToSelfAssessmentButtonText).click();
const submitAnswersAndGoToRecommendation = () => cy.get("button.govuk-button").contains(submitToRecommendationsButtonText).click();

Cypress.Commands.add(
"navigateToRecommendationPage",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { inProgressText } from "../helpers/constants";

/**
* Click first section link on self-assessment page
*/

Cypress.Commands.add("checkSectionStatus", (sectionName, selfAssessmentSlug) => {
Cypress.Commands.add("checkSectionStatus", (sectionName, sectionSlug, selfAssessmentSlug) => {
let inProgress = false;
cy.visit(`${selfAssessmentSlug}`)
cy.get("a.govuk-link")
.contains(sectionName.trim())

cy.findSectionLink(sectionName, sectionSlug)
.parent()
.next()
.within(() => {
cy.get("strong.app-task-list__tag").invoke("text")
.then((text) => {
inProgress = text.includes("in progress");
inProgress = text.includes(inProgressText);
});
})
.then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,19 @@ export const clickFirstSection = () => {
.click();
}

Cypress.Commands.add("clickFirstSection", clickFirstSection);
/**
* Find link to section on self assessment page
*/

export const findSectionLink = (sectionName, sectionSlug) => {
cy.get(`a.govuk-link[href="/${sectionSlug}"]`)
.each(($el) => {
const linkText = $el.text().trim();
if (linkText === sectionName) {
return cy.wrap($el)
}
});
};

Cypress.Commands.add("clickFirstSection", clickFirstSection);
Cypress.Commands.add("findSectionLink", findSectionLink);
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,22 @@ export { getSubmissionTimeText } from "./time-helpers.js";
export { CleanText } from "../../../helpers/text-helpers";
export { ValidateContent } from "../../../helpers/content-validators/content-validator.js";
export { ValidatePage } from "../../../helpers/content-validators/page-validator.js";
export { FindPageForSlug, selfAssessmentSlug } from "../../../helpers/page-slugs.js";
export {
FindPageForSlug,
selfAssessmentSlug,
recommendationIntroFragment,
checkAnswersSlug,
recommendationSlug
} from "../../../helpers/page-slugs.js";
export {
startPageName,
submitToSelfAssessmentButtonText,
submitToRecommendationsButtonText,
viewRecommendationButtonText,
newTagText,
continueButtonText,
recommendationsSidebarTitle,
recommendationIntroTitle,
saveAndContinueButtonText,
changeAnswerText
} from "../../../helpers/constants.js";
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ describe("Sections and all-questions paths", { testIsolation: false }, () => {
(dataMapper?.mappedSections ?? []).forEach((section) => {
describe(`${section.name} self-assessment and question pages`, () => {
before(function () {
cy.checkSectionStatus(section.name, selfAssessmentSlug)
const sectionSlug = section.interstitialPage.fields.slug;
cy.checkSectionStatus(section.name, sectionSlug, selfAssessmentSlug)
.then((inProgress) => {
if (inProgress) {
console.log(`Skipping tests for section: ${section.name} (status is 'in progress')`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ describe("Remaining-answer paths", { testIsolation: false }, () => {
describe(`${section.name} recommendations`, { testIsolation: false }, () => {

before(function () {
cy.checkSectionStatus(section.name, selfAssessmentSlug)
const sectionSlug = section.interstitialPage.fields.slug;
cy.checkSectionStatus(section.name, sectionSlug, selfAssessmentSlug)
.then((inProgress) => {
if (inProgress) {
console.log(`Skipping tests for section: ${section.name} (status is 'in progress')`);
Expand All @@ -25,7 +26,7 @@ describe("Remaining-answer paths", { testIsolation: false }, () => {

section.pathInfo.pathsForAllPossibleAnswers.forEach((userJourney, index) => {
const { path, maturity } = userJourney
describe(`${section.name} should retrieve correct recommendations for additional path ${index + 1} of ${section.pathsForAllPossibleAnswers.length}`, () => {
describe(`${section.name} should retrieve correct recommendations for additional path ${index + 1} of ${section.pathInfo.pathsForAllPossibleAnswers.length}`, () => {
minimalSectionValidationForRecommendations(section, [path], maturity)
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ describe("Recommendations", { testIsolation: false }, () => {
() => {
// Establish section status using self-assessment page tag
before(function () {
cy.checkSectionStatus(
section.name,
selfAssessmentSlug
).then((inProgress) => {
const sectionSlug = section.interstitialPage.fields.slug;
cy.checkSectionStatus(section.name, sectionSlug, selfAssessmentSlug)
.then((inProgress) => {
if (inProgress) {
console.log(
`Skipping tests for section: ${section.name} (status is 'in progress')`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CleanText } from "../helpers/index.js";
import { CleanText, submitToSelfAssessmentButtonText, checkAnswersSlug } from "../helpers/index.js";

export const validateCheckAnswersPage = (path, section) => {

cy.url().should("include", `${section.interstitialPage.fields.slug}/check-answers`);
cy.url().should("include", `${section.interstitialPage.fields.slug}${checkAnswersSlug}`);

for (const question of path) {
cy.get("div.govuk-summary-list__row dt.govuk-summary-list__key.spacer")
Expand All @@ -11,5 +11,5 @@ export const validateCheckAnswersPage = (path, section) => {
.contains(CleanText(question.answer.text));
}

cy.get("button.govuk-button").contains("Save and continue").click();
}
cy.get("button.govuk-button").contains(submitToSelfAssessmentButtonText).click();
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
import { CleanText, getSubmissionTimeText } from "../helpers/index.js";
import { CleanText, getSubmissionTimeText, viewRecommendationButtonText, newTagText } from "../helpers/index.js";

export const validateCompletionTags = (section, introPage) => {
export const validateCompletionTags = (section) => {
const time = new Date();
const timePlusOneMinute = new Date(time).setMinutes(time.getMinutes() + 1);
const timeMinusOneMinute = new Date(time).setMinutes(time.getMinutes() - 1);
const lateTime = new Date(timePlusOneMinute);
const earlyTime = new Date(timeMinusOneMinute)


const expectedPath =
`/${section.name.trim()}/recommendation/${introPage.slug.trim()}`
.toLowerCase()
.replace(/ /g, "-");

cy.get("a.govuk-link")
.contains(section.name.trim())
.should("have.attr", "href").and("include", `${section.name.trim().toLowerCase().replace(/ /g, "-")}`);

cy.get("a.govuk-link")
.contains(section.name.trim())
const sectionSlug = section.interstitialPage.fields.slug;
cy.findSectionLink(section.name, sectionSlug)
.parent()
.next()
.within(() => {
cy.get("strong.app-task-list__tag").invoke("text")
.then((text) => {
cy.wrap(CleanText(text)).should("be.oneOf", [ getSubmissionTimeText(time), getSubmissionTimeText(lateTime) ]);
cy.wrap(CleanText(text)).should("be.oneOf", [ getSubmissionTimeText(time), getSubmissionTimeText(lateTime), getSubmissionTimeText(earlyTime) ]);
});
})

cy.get("a.govuk-link")
.contains(section.name.trim())

cy.findSectionLink(section.name, sectionSlug)
.parent().next().next()
.within(() => {
cy.get("strong.app-task-list__tag").should("include.text", "New").and("have.class", "govuk-tag--yellow");
cy.get("a.govuk-button").contains("View recommendation")
cy.get("strong.app-task-list__tag").should("include.text", newTagText).and("have.class", "govuk-tag--yellow");
cy.get("a.govuk-button").contains(viewRecommendationButtonText)
.should("have.attr", "href")
.and("include", expectedPath);
})
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { selfAssessmentSlug } from "../helpers/index.js";
import { selfAssessmentSlug, continueButtonText, submitToRecommendationsButtonText } from "../helpers/index.js";
import { validateAndTestRecommendations, validateQuestionPages } from "./index.js";

/**
Expand All @@ -18,18 +18,17 @@ export const minimalSectionValidationForRecommendations = (section, paths, matur
cy.visit(`/${selfAssessmentSlug}`);

// Navigate through interstitial page
cy.get("div.govuk-summary-list__row > dt a").contains(section.name).click();
cy.get("a.govuk-button.govuk-link").contains("Continue").click();
const sectionSlug = section.interstitialPage.fields.slug;
cy.findSectionLink(section.name, sectionSlug).click();
cy.get("a.govuk-button.govuk-link").contains(continueButtonText).click();

// Conduct self assessment according to path
validateQuestionPages(path, section)

// Navigate through Check Answers page and return to self assessment page
cy.url().should("include", `${section.interstitialPage.fields.slug}/check-answers`);
cy.get("button.govuk-button").contains("Save and continue").click();
cy.url().should("include", selfAssessmentSlug);
cy.url().should("include", `${sectionSlug}/check-answers`);
cy.get("button.govuk-button").contains(submitToRecommendationsButtonText).click();
});

// Validate recommendations
validateAndTestRecommendations(section, maturity, path);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ValidatePage } from "../helpers/index.js";
import { ValidatePage, startPageName } from "../helpers/index.js";

export const validateAndTestNonAuthorisedPages = (dataMapper) => {
Array.from(dataMapper?.pages ?? [])
.map(([, page]) => page)
.filter((page) => !page.fields.requiresAuthorisation)
.filter((page) => !page.fields.requiresAuthorisation && page.fields.internalName !== startPageName)
.forEach((page) => {
it(
"Should have correct content on non-authorised pages. Testing " +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { ValidateContent } from "../helpers/index.js";
import { ValidateContent, recommendationIntroFragment, recommendationsSidebarTitle, recommendationIntroTitle } from "../helpers/index.js";

export const validateRecommendationIntro = (introPage, recommendationUrl) => {
const { slug, header, content } = introPage;

cy.url().should("include", `${recommendationUrl}/${slug}`);

cy.get("h1.govuk-heading-xl").contains(header);
cy.get("h1.govuk-heading-xl").contains(header.fields.text);

cy.get("h2.dfe-vertical-nav__theme").contains("Recommendations").should("exist");
cy.get("h2.dfe-vertical-nav__theme").contains(recommendationsSidebarTitle).should("exist");

cy.get("ul.dfe-vertical-nav__section > li").eq(0).within(() => {
cy.get("a.dfe-vertical-nav__link")
.contains("Overview")
.should("have.attr", "href", "#overview")
.contains(recommendationIntroTitle)
.should("have.attr", "href", recommendationIntroFragment)
});

if (content) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CleanText } from "../helpers/index.js";
import { CleanText, saveAndContinueButtonText } from "../helpers/index.js";

export const validateQuestionPages = (path, section, validateAnswersHintAndUrl) => {

Expand All @@ -22,6 +22,6 @@ export const validateQuestionPages = (path, section, validateAnswersHintAndUrl)
cy.get("div.govuk-radios div.govuk-radios__item label.govuk-radios__label.govuk-label")
.contains(CleanText(question.answer.text))
.click();
cy.get("button.govuk-button").contains("Save and continue").click();
cy.get("button.govuk-button").contains(saveAndContinueButtonText).click();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { validateCompletionTags, validateRecommendationChunks, validateRecommendationIntro } from "./index.js";
import { recommendationSlug } from "../helpers/index.js";
import { validateRecommendationChunks, validateRecommendationIntro } from "./index.js";

/**
* Validates a recommendation for a specific maturity level.
Expand All @@ -10,6 +11,8 @@ import { validateCompletionTags, validateRecommendationChunks, validateRecommend


export const validateAndTestRecommendations = (section, maturity, path) => {
const sectionSlug = section.interstitialPage.fields.slug

const introPage = section.recommendation.intros.find(
(recommendation) => recommendation.maturity == maturity
);
Expand All @@ -23,20 +26,9 @@ export const validateAndTestRecommendations = (section, maturity, path) => {
// Get chunks for path
const chunks = section.recommendation.section.getChunksForPath(path)

const recommendationUrl = `${section.interstitialPage.fields.slug}/recommendation`

it(`${section.name} should should show recent completion tags on self-assessment page`, () => {
// Validate self-assessment page post-section completion
validateCompletionTags(section, introPage);
});
const recommendationUrl = `${sectionSlug}${recommendationSlug}`

it(`${section.name} should retrieve recommendation intro for ${maturity} maturity, with correct content`, () => {
cy.get("a.govuk-link")
.contains(section.name.trim())
.parent().next().next()
.within(() => {
cy.get("a.govuk-button").contains("View recommendation").click();
})
validateRecommendationIntro(introPage, recommendationUrl);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FindPageForSlug, selfAssessmentSlug, ValidatePage } from "../helpers/index.js";
import { validateQuestionPages, validateCheckAnswersPage, validateAnswersHintAndUrl } from "./index.js";
import { continueButtonText, FindPageForSlug, selfAssessmentSlug, ValidatePage } from "../helpers/index.js";
import { validateCompletionTags, validateQuestionPages, validateCheckAnswersPage, validateAnswersHintAndUrl } from "./index.js";

/**
* Validates sections using the given paths
Expand All @@ -12,22 +12,22 @@ import { validateQuestionPages, validateCheckAnswersPage, validateAnswersHintAnd
export const validateAndTestSections = (section, paths, dataMapper) => {

for (const path of paths) {

it(`${section.name} should have interstitial page with correct content`, () => {
cy.visit(`/${selfAssessmentSlug}`);
cy.visit(`${selfAssessmentSlug}`);

// Navigate through interstitial page
cy.get("div.govuk-summary-list__row > dt a").contains(section.name).click();
cy.url().should("include", section.interstitialPage.fields.slug);
const sectionSlug = section.interstitialPage.fields.slug;
cy.findSectionLink(section.name, sectionSlug).click();

cy.url().should("include", sectionSlug);

// Validate interstititial page content
const interstitialPage = FindPageForSlug({ slug: section.interstitialPage.fields.slug, dataMapper });
ValidatePage(section.interstitialPage.fields.slug, interstitialPage);
const interstitialPage = FindPageForSlug({ slug: sectionSlug, dataMapper });
ValidatePage(sectionSlug, interstitialPage);
});

it(`${section.name} should have every question with correct content`, () => {
// Conduct self assessment according to path
cy.get("a.govuk-button.govuk-link").contains("Continue").click();
cy.get("a.govuk-button.govuk-link").contains(continueButtonText).click();
validateQuestionPages(path, section, validateAnswersHintAndUrl);
});

Expand All @@ -36,5 +36,10 @@ export const validateAndTestSections = (section, paths, dataMapper) => {
validateCheckAnswersPage(path, section);
cy.url().should("include", selfAssessmentSlug);
});

it(`${section.name} should show recent completion tags on self-assessment page`, () => {
// Validate self-assessment page post-section completion
validateCompletionTags(section);
});
}
}
Loading

0 comments on commit 80f46d3

Please sign in to comment.