From 3bd2110afa70d5c16f7d1a9d0755c9edf082608e Mon Sep 17 00:00:00 2001 From: Tej Powar Date: Mon, 8 Apr 2024 11:01:27 +0100 Subject: [PATCH 1/4] fix cypress tests --- ui/cypress/e2e/standards/list.cy.js | 261 ++++++++++++++-------------- 1 file changed, 128 insertions(+), 133 deletions(-) diff --git a/ui/cypress/e2e/standards/list.cy.js b/ui/cypress/e2e/standards/list.cy.js index 63932649..955f68f6 100644 --- a/ui/cypress/e2e/standards/list.cy.js +++ b/ui/cypress/e2e/standards/list.cy.js @@ -17,178 +17,173 @@ describe('Standards Listing Index', () => { // make sure main content area is loaded before injecting a11y checker cy.get('main'); // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(100); cy.injectAxe(); + //cy.wait(5000); + cy.debugger; cy.checkA11y(null, null, a11yLog); + cy.pause(); }); + it('Can filter by mandated, and remove filter (regression)', () => { + cy.visit('/published-standards'); + let results; - it('passes html validation', () => { - cy.visit(`/published-standards`); - cy.get('main'); - cy.htmlvalidate( - { - rules: { - 'valid-id': 'off', - 'require-sri': 'off', - }, - }, - { - include: ['body'], - } - ); - }); - describe('filters and pagination', () => { - it('Can change page', () => { - cy.visit('/published-standards'); - cy.get('.nhsuk-pagination').contains('a', 'Next').click(); - cy.url().should('contain', 'page=2'); - - cy.get('.nhsuk-pagination').contains('a', 'Next').click(); - cy.url().should('contain', 'page=3'); - - cy.get('.nhsuk-pagination').contains('a', 'Prev').click(); - cy.url().should('contain', 'page=2'); - - cy.get('.nhsuk-pagination').contains('a', 'Prev').click(); - cy.url().should('contain', 'page=1'); + cy.get('span[role="status"]').then($span => { + const text = $span.text() + results = parseInt(text.match(/\d+/)[0]) }); + cy.get('[title="Requirement"]').click(); + cy.get('[type="checkbox"]').check('nationally mandated'); + cy.get('.FilterSummary_filterSection__cz_Lu').contains('X National requirement'); + cy.get('span[role="status"]').then($span => { + const text = $span.text() + const filteredResults = parseInt(text.match(/\d+/)[0]); + expect(filteredResults).to.be.lessThan(results); - it('a11y when clicking into filters', () => { - cy.visit('/published-standards'); - cy.get('details[title="Care setting"]').click(); - cy.get('details[title="Topic"]').click(); - cy.injectAxe(); - cy.checkA11y(null, null, a11yLog); - cy.get('details[title="Care setting"] summary').click(); - cy.get('details[title="Topic"] summary').click(); - cy.checkA11y(null, null, a11yLog); }); + cy.get('#mandated').uncheck('nationally mandated') + cy.get('.FilterSummary_widget__RYAmB').should('not.exist'); + cy.get('span[role="status"]').then($span => { + const text = $span.text() + const filteredResults = parseInt(text.match(/\d+/)[0]); + expect(filteredResults).to.be.equal(results); - it('Can filter by mandated, and remove filter (regression)', () => { - cy.visit('/published-standards'); - let results; - - cy.get('span[role="status"]').then($span => { - const text = $span.text() - results = parseInt(text.match(/\d+/)[0]) - }); + }); + it('passes html validation', () => { + cy.visit(`/published-standards`); + cy.get('main'); + cy.htmlvalidate( + { + rules: { + 'valid-id': 'off', + 'require-sri': 'off', + }, + }, + { + include: ['body'], + } + ); + }); + describe('filters and pagination', () => { + it('Can change page', () => { + cy.visit('/published-standards'); + cy.get('.nhsuk-pagination').contains('a', 'Next').click(); + cy.url().should('contain', 'page=2'); - cy.get('[title="Requirement"]').click(); - cy.get('#mandated').scrollIntoView().click({ force: true }); + cy.get('.nhsuk-pagination').contains('a', 'Next').click(); + cy.url().should('contain', 'page=3'); - // wait added for api response - cy.wait(500); + cy.get('.nhsuk-pagination').contains('a', 'Prev').click(); + cy.url().should('contain', 'page=2'); - cy.get('span[role="status"]').then($span => { - const text = $span.text() - const filteredResults = parseInt(text.match(/\d+/)[0]); - expect(filteredResults).to.be.lessThan(results); + cy.get('.nhsuk-pagination').contains('a', 'Prev').click(); + cy.url().should('contain', 'page=1'); }); - cy.get('#mandated').click(); - - cy.wait(500); - - cy.get('span[role="status"]').then($span => { - const text = $span.text() - const filteredResults = parseInt(text.match(/\d+/)[0]); - expect(filteredResults).to.be.equal(results); + it('a11y when clicking into filters', () => { + cy.visit('/published-standards'); + cy.get('details[title="Care setting"]').click(); + cy.get('details[title="Topic"]').click(); + cy.injectAxe(); + cy.debugger; + cy.checkA11y(null, null, a11yLog); + cy.get('details[title="Care setting"] summary').click(); + cy.get('details[title="Topic"] summary').click(); + cy.checkA11y(null, null, a11yLog); }); - }); - - it('Resets page when filtered', () => { - cy.visit('/published-standards'); - cy.get('.nhsuk-pagination').contains('a', 'Next').click(); - cy.url().should('contain', 'page=2'); - - cy.get('[title="Requirement"]').click(); - cy.get('#mandated').scrollIntoView().click({ force: true }); - - cy.url().should('not.contain', 'page'); - cy.url().should('contain', 'mandated'); - }); - }); + it('Resets page when filtered', () => { + cy.visit('/published-standards'); + cy.get('.nhsuk-pagination').contains('a', 'Next').click(); + cy.url().should('contain', 'page=2'); - describe('Search', () => { - it('Can search by standard matching', () => { - cy.visit('/published-standards'); - cy.injectAxe(); - cy.doSearch('hospital'); - cy.get('#browse-results li').not('have.length', 0); + cy.get('[title="Requirement"]').click(); + cy.get('#mandated').scrollIntoView().click({ force: true }); - cy.checkA11y(null, null, a11yLog, failLevel); - }); + cy.url().should('not.contain', 'page'); + cy.url().should('contain', 'mandated'); + }); + describe('Search', () => { + it('Can search by standard matching', () => { + cy.visit('/published-standards'); + cy.injectAxe(); + cy.doSearch('hospital'); + cy.get('#browse-results li').not('have.length', 0); + + cy.checkA11y(null, null, a11yLog, failLevel); + }); - it('Can search by fuzzy match', () => { - cy.visit('/published-standards'); - cy.doSearch('hosptal'); + it('Can search by fuzzy match', () => { + cy.visit('/published-standards'); + cy.doSearch('hosptal'); - cy.get('#browse-results li').should('have.length.of.at.least', 1); - cy.contains('#browse-results li', 'hospital'); - }); + cy.get('#browse-results li').should('have.length.of.at.least', 1); + cy.contains('#browse-results li', 'hospital'); + }); - it('emboldens matches', () => { - cy.visit('/published-standards'); - cy.doSearch('medicine'); - cy.get('#browse-results li').eq(0).contains('strong', 'Medicine'); - }); + it('emboldens matches', () => { + cy.visit('/published-standards'); + cy.doSearch('medicine'); + cy.get('#browse-results li').eq(0).contains('strong', 'Medicine'); + }); - describe('Organisation mapping', () => { - it('Can search by organisation', () => { - cy.visit('/published-standards'); + describe('Organisation mapping', () => { + it('Can search by organisation', () => { + cy.visit('/published-standards'); - cy.doSearch('prsb'); + cy.doSearch('prsb'); - cy.get('#browse-results li').not('have.length', 0); - }); + cy.get('#browse-results li').not('have.length', 0); + }); - it('Displays org matches first', () => { - cy.visit('/published-standards'); - cy.doSearch('prsb'); + it('Displays org matches first', () => { + cy.visit('/published-standards'); + cy.doSearch('prsb'); - cy.get('#browse-results li a').eq(0).click(); + cy.get('#browse-results li a').eq(0).click(); - cy.contains('Core information standard'); - }); + cy.contains('Core information standard'); + }); - it('Matches various variations of prsb', () => { - cy.visit('/published-standards'); - cy.doSearch('prsb'); + it('Matches various variations of prsb', () => { + cy.visit('/published-standards'); + cy.doSearch('prsb'); - cy.get('#browse-results li a').eq(0).click(); + cy.get('#browse-results li a').eq(0).click(); - cy.contains('Community Pharmacy Information Standard'); + cy.contains('Community Pharmacy Information Standard'); - cy.visit('/published-standards'); - cy.doSearch('professional records standards body'); - cy.get('#browse-results li a').eq(0).click({ - force: true, - }); - cy.contains('dd', 'Professional Record Standards Body'); - }); + cy.visit('/published-standards'); + cy.doSearch('professional records standards body'); + cy.get('#browse-results li a').eq(0).click({ + force: true, + }); + cy.contains('dd', 'Professional Record Standards Body'); + }); - it('Matches various variations of nhs', () => { - cy.visit('/published-standards'); - cy.doSearch('nhsd'); + it('Matches various variations of nhs', () => { + cy.visit('/published-standards'); + cy.doSearch('nhsd'); - cy.get('#browse-results li a').eq(0).click(); + cy.get('#browse-results li a').eq(0).click(); - cy.contains('dd', 'NHS'); + cy.contains('dd', 'NHS'); - cy.visit('/published-standards'); + cy.visit('/published-standards'); - cy.doSearch('nhsx'); - cy.get('#browse-results li a').eq(0).click(); + cy.doSearch('nhsx'); + cy.get('#browse-results li a').eq(0).click(); - cy.contains('dd', 'NHS'); + cy.contains('dd', 'NHS'); - cy.visit('/published-standards'); + cy.visit('/published-standards'); - cy.doSearch('nhs digital'); - cy.get('#browse-results li a').eq(0).click(); + cy.doSearch('nhs digital'); + cy.get('#browse-results li a').eq(0).click(); - cy.contains('dd', 'NHS'); + cy.contains('dd', 'NHS'); + }); + }); }); }); }); + }); From a84000e84021e56dc0b8fd57d50a29318c345e74 Mon Sep 17 00:00:00 2001 From: Tej Powar Date: Mon, 8 Apr 2024 11:12:09 +0100 Subject: [PATCH 2/4] fixed linting issues --- ui/schema/future-standards/index.js | 2 +- ui/schema/index.js | 2 +- ui/schema/published-standards/index.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/schema/future-standards/index.js b/ui/schema/future-standards/index.js index 750b8df8..90d320e2 100644 --- a/ui/schema/future-standards/index.js +++ b/ui/schema/future-standards/index.js @@ -364,7 +364,7 @@ const schema = [ return ( val && ( - ), + ) )} }, trusted_by: { diff --git a/ui/schema/index.js b/ui/schema/index.js index a68de409..e7c890e0 100644 --- a/ui/schema/index.js +++ b/ui/schema/index.js @@ -359,7 +359,7 @@ const schema = [ return ( val && ( - ), + ) )} }, trusted_by: { diff --git a/ui/schema/published-standards/index.js b/ui/schema/published-standards/index.js index 332fcb91..e8157805 100644 --- a/ui/schema/published-standards/index.js +++ b/ui/schema/published-standards/index.js @@ -358,7 +358,7 @@ const schema = [ return ( val && ( - ), + ) )} }, trusted_by: { From 0fb87a46425014140e3cc66fb99bf5e1ea81ed44 Mon Sep 17 00:00:00 2001 From: Tej Powar Date: Mon, 8 Apr 2024 11:40:16 +0100 Subject: [PATCH 3/4] fixed linting on files changed --- ui/cypress/e2e/standards/list.cy.js | 23 +++++++++++------------ ui/schema/future-standards/index.js | 9 +++------ ui/schema/index.js | 9 +++------ ui/schema/published-standards/index.js | 9 +++------ 4 files changed, 20 insertions(+), 30 deletions(-) diff --git a/ui/cypress/e2e/standards/list.cy.js b/ui/cypress/e2e/standards/list.cy.js index 955f68f6..8af270d7 100644 --- a/ui/cypress/e2e/standards/list.cy.js +++ b/ui/cypress/e2e/standards/list.cy.js @@ -27,26 +27,26 @@ describe('Standards Listing Index', () => { cy.visit('/published-standards'); let results; - cy.get('span[role="status"]').then($span => { - const text = $span.text() - results = parseInt(text.match(/\d+/)[0]) + cy.get('span[role="status"]').then(($span) => { + const text = $span.text(); + results = parseInt(text.match(/\d+/)[0]); }); cy.get('[title="Requirement"]').click(); cy.get('[type="checkbox"]').check('nationally mandated'); - cy.get('.FilterSummary_filterSection__cz_Lu').contains('X National requirement'); - cy.get('span[role="status"]').then($span => { - const text = $span.text() + cy.get('.FilterSummary_filterSection__cz_Lu').contains( + 'X National requirement' + ); + cy.get('span[role="status"]').then(($span) => { + const text = $span.text(); const filteredResults = parseInt(text.match(/\d+/)[0]); expect(filteredResults).to.be.lessThan(results); - }); - cy.get('#mandated').uncheck('nationally mandated') + cy.get('#mandated').uncheck('nationally mandated'); cy.get('.FilterSummary_widget__RYAmB').should('not.exist'); - cy.get('span[role="status"]').then($span => { - const text = $span.text() + cy.get('span[role="status"]').then(($span) => { + const text = $span.text(); const filteredResults = parseInt(text.match(/\d+/)[0]); expect(filteredResults).to.be.equal(results); - }); it('passes html validation', () => { cy.visit(`/published-standards`); @@ -185,5 +185,4 @@ describe('Standards Listing Index', () => { }); }); }); - }); diff --git a/ui/schema/future-standards/index.js b/ui/schema/future-standards/index.js index 90d320e2..fe55141a 100644 --- a/ui/schema/future-standards/index.js +++ b/ui/schema/future-standards/index.js @@ -360,12 +360,9 @@ const schema = [ label: 'Legal authority', format: (val) => { let legalAuthorityTitles = val.legalAuthority.join(',
'); - const mdBlock = `${legalAuthorityTitles}

${val.legalAuthorityDescription}

` - return ( - val && ( - - ) - )} + const mdBlock = `${legalAuthorityTitles}

${val.legalAuthorityDescription}

`; + return val && ; + }, }, trusted_by: { hide_when_empty: true, diff --git a/ui/schema/index.js b/ui/schema/index.js index e7c890e0..45429dc8 100644 --- a/ui/schema/index.js +++ b/ui/schema/index.js @@ -355,12 +355,9 @@ const schema = [ label: 'Legal authority', format: (val) => { let legalAuthorityTitles = val.legalAuthority.join(',
'); - const mdBlock = `${legalAuthorityTitles}

${val.legalAuthorityDescription}

` - return ( - val && ( - - ) - )} + const mdBlock = `${legalAuthorityTitles}

${val.legalAuthorityDescription}

`; + return val && ; + }, }, trusted_by: { hide_when_empty: true, diff --git a/ui/schema/published-standards/index.js b/ui/schema/published-standards/index.js index e8157805..9e41a442 100644 --- a/ui/schema/published-standards/index.js +++ b/ui/schema/published-standards/index.js @@ -354,12 +354,9 @@ const schema = [ label: 'Legal authority', format: (val) => { let legalAuthorityTitles = val.legalAuthority.join(',
'); - const mdBlock = `${legalAuthorityTitles}

${val.legalAuthorityDescription}

` - return ( - val && ( - - ) - )} + const mdBlock = `${legalAuthorityTitles}

${val.legalAuthorityDescription}

`; + return val && ; + }, }, trusted_by: { hide_when_empty: true, From 82b9128c10b661f0588849c2acfb0dc78547bade Mon Sep 17 00:00:00 2001 From: Tej Powar Date: Wed, 10 Apr 2024 09:56:05 +0100 Subject: [PATCH 4/4] updated tests to reflect current ckan endpoint --- ui/cypress/e2e/home.cy.js | 99 ++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 54 deletions(-) diff --git a/ui/cypress/e2e/home.cy.js b/ui/cypress/e2e/home.cy.js index b42325d1..b2a36f12 100644 --- a/ui/cypress/e2e/home.cy.js +++ b/ui/cypress/e2e/home.cy.js @@ -3,11 +3,8 @@ import { a11yLog } from '../support/custom'; describe('Homepage', () => { it('should show home page and call to action', () => { cy.visit('/'); - cy.contains( - 'Find standards to record, handle and exchange data in England' - ); - cy.contains( - 'Use this directory to find nationally recognised data standards for use in health and adult social care.' + + cy.get('.nhsuk-body-l').contains('Use this service to find out about recognised published and future standards in health and adult social care.' ); }); @@ -23,63 +20,57 @@ describe('Homepage', () => { cy.doSearch('hospital'); cy.get('#browse-results li').not('have.length', 0); }); - it('Blank search returns results', () => { - cy.visit('/'); - cy.doSearch(' '); - cy.get('#browse-results li').not('have.length', 0); + describe('a11y', () => { + it('has sufficient contrast on focussed links', () => { + cy.visit('/'); + cy.get('main'); + cy.injectAxe(); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(100); + cy.get('.nhsuk-phase-banner__text a').focus(); + cy.checkA11y(null, null, a11yLog); + cy.get('#recent-standards a').first().focus(); + cy.checkA11y(null, null, a11yLog); + }); + + it('use a11y checker with wcag2aa', () => { + cy.visit('/'); + cy.injectAxe(); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(100); + cy.checkA11y(null, { + runOnly: { + type: 'tag', + values: ['wcag2aa', 'wcag21aa'], + }, + }); + }); }); - }); - describe('a11y', () => { - it('has sufficient contrast on focussed links', () => { + it('passes html validation', () => { cy.visit('/'); cy.get('main'); - cy.injectAxe(); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(100); - cy.get('.nhsuk-phase-banner__text a').focus(); - cy.checkA11y(null, null, a11yLog); - cy.get('#recent-standards a').first().focus(); - cy.checkA11y(null, null, a11yLog); + cy.htmlvalidate(); }); - it('use a11y checker with wcag2aa', () => { - cy.visit('/'); - cy.injectAxe(); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(100); - cy.checkA11y(null, { - runOnly: { - type: 'tag', - values: ['wcag2aa', 'wcag21aa'], - }, + describe('cookies', () => { + it('clicking approve removes banner, sets consent preference:true', () => { + cy.visit('/'); + cy.get('#nhsuk-cookie-banner').should('be.visible'); + cy.getCookie('localConsent').should('not.exist'); + cy.get('#nhsuk-cookie-banner__link_accept_analytics').click(); + cy.get('#nhsuk-cookie-banner').should('not.exist'); + cy.getCookie('localConsent').should('have.property', 'value', 'true'); }); - }); - }); - it('passes html validation', () => { - cy.visit('/'); - cy.get('main'); - cy.htmlvalidate(); - }); - - describe('cookies', () => { - it('clicking approve removes banner, sets consent preference:true', () => { - cy.visit('/'); - cy.get('#nhsuk-cookie-banner').should('be.visible'); - cy.getCookie('localConsent').should('not.exist'); - cy.get('#nhsuk-cookie-banner__link_accept_analytics').click(); - cy.get('#nhsuk-cookie-banner').should('not.exist'); - cy.getCookie('localConsent').should('have.property', 'value', 'true'); - }); - - it('clicking reject removes banner, sets consent preference:false', () => { - cy.visit('/'); - cy.get('#nhsuk-cookie-banner').should('be.visible'); - cy.getCookie('localConsent').should('not.exist'); - cy.get('#nhsuk-cookie-banner__link_reject').click(); - cy.get('#nhsuk-cookie-banner').should('not.exist'); - cy.getCookie('localConsent').should('have.property', 'value', 'false'); + it('clicking reject removes banner, sets consent preference:false', () => { + cy.visit('/'); + cy.get('#nhsuk-cookie-banner').should('be.visible'); + cy.getCookie('localConsent').should('not.exist'); + cy.get('#nhsuk-cookie-banner__link_reject').click(); + cy.get('#nhsuk-cookie-banner').should('not.exist'); + cy.getCookie('localConsent').should('have.property', 'value', 'false'); + }); }); }); });