Skip to content

Commit

Permalink
fix cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tejpowar committed Apr 8, 2024
1 parent 0b39088 commit 3bd2110
Showing 1 changed file with 128 additions and 133 deletions.
261 changes: 128 additions & 133 deletions ui/cypress/e2e/standards/list.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
});
});

});

0 comments on commit 3bd2110

Please sign in to comment.