Skip to content

Commit

Permalink
chore(EMS-2414): Add enctype to all forms (#1517)
Browse files Browse the repository at this point in the history
* chore(EMS-2414): add enctype to all forms

* chore(EMS-2414): update core page checks to check for form attributes

* chore(EMS-2414): fix/update e2e tests
  • Loading branch information
ttbarnes authored Dec 15, 2023
1 parent 9a8ff5d commit 0e4af91
Show file tree
Hide file tree
Showing 99 changed files with 135 additions and 109 deletions.
25 changes: 18 additions & 7 deletions e2e-tests/commands/core-page-checks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { BUTTONS, LINKS, ORGANISATION } from '../content-strings';
import { backLink as backLinkSelector, heading, submitButton } from '../pages/shared';
import {
backLink as backLinkSelector,
form,
heading,
submitButton,
} from '../pages/shared';

// const lighthouseAudit = (lightHouseThresholds = {}) => {
// cy.lighthouse({
Expand Down Expand Up @@ -58,9 +63,9 @@ const checkPageTitleAndHeading = (pageTitle) => {
* @param {String} pageTitle - Expected page title
* @param {String} currentHref - Expected page HREF
* @param {String} backLink - Expected "back" HREF
* @param {Boolean} assertSubmitButton - Should check submit button (some pages don't have a submit button)
* @param {Boolean} hasAForm - Flag for if a page has a form, to check check form attributes and submit button (some paged do not have a form)
* @param {String} submitButtonCopy - Expected submit button copy
* @param {Boolean} assertBackLink - Should check "back" link (some pages don't have a back link)
* @param {Boolean} assertBackLink - Should check "back" link (some pages do not have a back link)
* @param {Boolean} isInsurancePage - If page is an insurance page or otherwise
* @param {Boolean} assertServiceHeading - Should check service heading is for insurance or quote
* @param {Object} lightHouseThresholds - Custom expected lighthouse thresholds
Expand All @@ -69,7 +74,7 @@ const corePageChecks = ({
pageTitle,
currentHref,
backLink,
assertSubmitButton = true,
hasAForm = true,
submitButtonCopy = BUTTONS.CONTINUE,
assertBackLink = true,
assertAuthenticatedHeader = true,
Expand Down Expand Up @@ -109,9 +114,15 @@ const corePageChecks = ({
// check page title and heading
checkPageTitleAndHeading(pageTitle);

if (assertSubmitButton) {
// check submit button
submitButton().should('exist');
/**
* If the page has a form,
* 1) Assert form attributes
* 2) Assert submit button.
*/
if (hasAForm) {
form().should('have.attr', 'method', 'POST');
form().should('have.attr', 'enctype', 'application/x-www-form-urlencoded');
form().should('have.attr', 'novalidate');

cy.checkText(submitButton(), submitButtonCopy);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ context('Accessibility statement page - Insurance - Signed in', () => {
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: ROUTES.INSURANCE.ACCESSIBILITY_STATEMENT,
backLink: dashboardUrl,
assertSubmitButton: false,
hasAForm: false,
assertAuthenticatedHeader: true,
isInsurancePage: true,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ context('Accessibility statement page - Insurance', () => {
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: ROUTES.INSURANCE.ACCESSIBILITY_STATEMENT,
backLink: startRoute,
assertSubmitButton: false,
hasAForm: false,
assertAuthenticatedHeader: false,
isInsurancePage: true,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ context('Insurance - Account - Create - Confirm email page - expired token - As
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: verificationUrl,
backLink: `${CONFIRM_EMAIL}?id=${account.id}`,
assertSubmitButton: false,
hasAForm: false,
assertAuthenticatedHeader: false,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ context('Insurance - Account - Create - Confirm email page - invalid link - As a
currentHref: verifyEmailUrl,
assertBackLink: false,
assertAuthenticatedHeader: false,
assertSubmitButton: false,
hasAForm: false,
});

cy.checkText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ context('Insurance - Account - Create - Confirm email page - As an Exporter I wa
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: `${CONFIRM_EMAIL}?id=${account.id}`,
backLink: YOUR_DETAILS,
assertSubmitButton: false,
hasAForm: false,
assertAuthenticatedHeader: false,
lightHouseThresholds: {
performance: 69,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ context('Insurance - Account - Create - Resend confirm email page - As an Export
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: url,
backLink: `${CONFIRM_EMAIL}?id=${account.id}`,
assertSubmitButton: false,
hasAForm: false,
assertAuthenticatedHeader: false,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ context('Insurance - Account - Manage - As an Exporter, I want the service to ha
currentHref: MANAGE,
backLink: DASHBOARD,
assertBackLink: true,
assertSubmitButton: false,
hasAForm: false,
assertAuthenticatedHeader: true,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ context('Insurance - Account - Password reset - expired link page', () => {
currentHref: EXPIRED_LINK,
assertBackLink: false,
assertAuthenticatedHeader: false,
assertSubmitButton: false,
hasAForm: false,
});

cy.checkText(linkExpiredPage.passwordNotReset(), CONTENT_STRINGS.PASSWORD_NOT_RESET);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ context('Insurance - Account - Password reset - link sent page - As an Exporter,
currentHref: LINK_SENT,
backLink: PASSWORD_RESET_ROOT,
assertAuthenticatedHeader: false,
assertSubmitButton: false,
hasAForm: false,
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ context('Insurance - Account - Password reset - success page - I want to reset m
currentHref: successUrl,
assertBackLink: false,
assertAuthenticatedHeader: false,
assertSubmitButton: false,
hasAForm: false,
});

cy.checkLink(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ context('Insurance - Account - Reactivated page', () => {
currentHref: REACTIVATED_ROOT,
assertBackLink: false,
assertAuthenticatedHeader: false,
assertSubmitButton: false,
hasAForm: false,
});

cy.checkText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ context('Insurance - Account - Signed out - As an Exporter I want the system to
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: SIGNED_OUT,
assertBackLink: false,
assertSubmitButton: false,
hasAForm: false,
assertAuthenticatedHeader: false,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ context('Insurance - Account - Suspended page - As an Exporter, I want to reacti
currentHref: accountSuspendedUrl,
assertBackLink: false,
assertAuthenticatedHeader: false,
assertSubmitButton: false,
hasAForm: false,
});

cy.checkText(suspendedPage.body(), CONTENT_STRINGS.BODY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ context('Insurance - Account - Suspended - Email sent page - As an Exporter, I w
currentHref: EMAIL_SENT,
backLink: `${SUSPENDED_ROOT}?id=${account.id}`,
assertAuthenticatedHeader: false,
assertSubmitButton: false,
hasAForm: false,
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ context('Insurance - Account - Suspended - Verify email - Visit with an invalid
currentHref: verifyEmailUrl,
assertBackLink: false,
assertAuthenticatedHeader: false,
assertSubmitButton: false,
hasAForm: false,
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ context('Insurance - All sections - new application', () => {
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: `${ROUTES.INSURANCE.ROOT}/${referenceNumber}${ROUTES.INSURANCE.ALL_SECTIONS}`,
backLink: ROUTES.INSURANCE.ELIGIBILITY.ELIGIBLE_TO_APPLY_ONLINE,
assertSubmitButton: false,
hasAForm: false,
assertBackLink: false,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ context('Insurance - application submitted page', () => {
currentHref: `${INSURANCE_ROOT}/${referenceNumber}${APPLICATION_SUBMITTED}`,
backLink: `${INSURANCE_ROOT}/${referenceNumber}${HOW_YOUR_DATA_WILL_BE_USED}`,
assertBackLink: false,
assertSubmitButton: false,
hasAForm: false,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ context('Insurance - apply offline exit page', () => {
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: APPLY_OFFLINE,
backLink: BUYER_COUNTRY,
assertSubmitButton: false,
hasAForm: false,
assertAuthenticatedHeader: false,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ context('Insurance - Check your answers - Need to start new application page', (
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: url,
backLink: eligibilityUrl,
assertSubmitButton: false,
hasAForm: false,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ context('Insurance - Complete other sections page', () => {
cy.corePageChecks({
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: `${INSURANCE_ROOT}/${referenceNumber}${COMPLETE_OTHER_SECTIONS}`,
assertSubmitButton: false,
hasAForm: false,
assertBackLink: false,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ context('Contact us page - Insurance', () => {
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: ROUTES.INSURANCE.CONTACT_US,
backLink: ROUTES.INSURANCE.START,
assertSubmitButton: false,
hasAForm: false,
assertAuthenticatedHeader: false,
isInsurancePage: true,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ context('Cookies saved page - Insurance', () => {
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: COOKIES_SAVED,
backLink: COOKIES,
assertSubmitButton: false,
hasAForm: false,
assertAuthenticatedHeader: false,
isInsurancePage: true,
assertCookies: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ context('Insurance - Dashboard - new application - As an Exporter, I want to acc
cy.corePageChecks({
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: DASHBOARD,
assertSubmitButton: false,
hasAForm: false,
assertBackLink: false,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ context('Insurance Eligibility - Cannot apply exit page', () => {
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: CANNOT_APPLY,
backLink: BUYER_COUNTRY,
assertSubmitButton: false,
hasAForm: false,
assertAuthenticatedHeader: false,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ context('Insurance - Feedback confirmation page - Signed in', () => {

it('renders core page elements', () => {
cy.corePageChecks({
hasAForm: false,
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: url,
submitButtonCopy: BUTTONS.BACK_TO_SERVICE,
assertAuthenticatedHeader: true,
assertBackLink: false,
});
});

it('renders a "submit button"/link', () => {
cy.navigateToUrl(url);

cy.checkText(submitButton(), BUTTONS.BACK_TO_SERVICE);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ context('Insurance - Feedback Confirmation page', () => {

it('renders core page elements', () => {
cy.corePageChecks({
hasAForm: false,
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: url,
submitButtonCopy: BUTTONS.BACK_TO_SERVICE,
assertAuthenticatedHeader: false,
assertBackLink: false,
});
Expand All @@ -44,5 +44,11 @@ context('Insurance - Feedback Confirmation page', () => {
it('should render text confirming feedback', () => {
cy.checkText(feedbackConfirmation.feedbackConfirmation(), CONTENT_STRINGS.FEEDBACK_TEXT);
});

it('renders a "submit button"/link', () => {
cy.navigateToUrl(url);

cy.checkText(submitButton(), BUTTONS.BACK_TO_SERVICE);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ context('Insurance - no access to application when application is submitted', ()
cy.corePageChecks({
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: NO_ACCESS_APPLICATION_SUBMITTED,
assertSubmitButton: false,
hasAForm: false,
backLink: expectedUrl,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ context('Insurance - no access to application page - signed out', () => {
cy.corePageChecks({
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: NO_ACCESS_TO_APPLICATION,
assertSubmitButton: false,
hasAForm: false,
assertBackLink: false,
assertAuthenticatedHeader: false,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ context('Insurance - page not found - signed out', () => {
cy.corePageChecks({
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: invalidUrl,
assertSubmitButton: false,
hasAForm: false,
assertBackLink: false,
assertAuthenticatedHeader: false,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ context('Insurance - page not found', () => {
cy.corePageChecks({
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: invalidUrl,
assertSubmitButton: false,
hasAForm: false,
assertBackLink: false,
assertAuthenticatedHeader: true,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ context('Problem with service page - Insurance', () => {
cy.corePageChecks({
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: url,
assertSubmitButton: false,
hasAForm: false,
assertAuthenticatedHeader: false,
assertBackLink: false,
isInsurancePage: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ context('Insurance - speak to UKEF EFM exit page', () => {
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: SPEAK_TO_UKEF_EFM,
backLink: INSURED_PERIOD,
assertSubmitButton: false,
hasAForm: false,
assertAuthenticatedHeader: false,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ context("Insurance - Your business - Companies house unavailable page - I want t
currentHref: `${ROOT}/${referenceNumber}${COMPANIES_HOUSE_UNAVAILABLE}`,
backLink: null,
assertBackLink: false,
assertSubmitButton: false,
hasAForm: false,
});
});

Expand Down
2 changes: 2 additions & 0 deletions e2e-tests/pages/shared/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ukGoodsOrServicesPage from './ukGoodsOrServices';
import field from './field';

const backLink = () => cy.get('[data-cy="back-link"]');
const form = () => cy.get('[data-cy="form"]');
const heading = () => cy.get('[data-cy="heading"]');
const headingCaption = () => cy.get('[data-cy="heading-caption"]');
const yesNoRadioHint = () => cy.get('[data-cy="yes-no-input-hint"]');
Expand Down Expand Up @@ -35,6 +36,7 @@ const singleInputField = (fieldId) => ({

export {
backLink,
form,
heading,
headingCaption,
yesNoRadioHint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ context('404 Page not found', () => {
cy.corePageChecks({
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: '/test',
assertSubmitButton: false,
hasAForm: false,
assertBackLink: false,
assertAuthenticatedHeader: false,
isInsurancePage: false,
Expand Down
Loading

0 comments on commit 0e4af91

Please sign in to comment.