Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #138 from MetadataWorks/functional-test
Browse files Browse the repository at this point in the history
Functional test
  • Loading branch information
davidmilward authored Mar 27, 2024
2 parents feb7679 + 6e05e19 commit c0d98ca
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 38 deletions.
4 changes: 2 additions & 2 deletions ui/components/Logo/index.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import styles from './logo.module.scss';

const onError = (event) => {
event.target.style.display = 'none';
event.target.style.display = 'none';
};

const Logo = ({ owner, image_url }) => {
return (
<>
{image_url && (
<div className={styles.logo}>
<img src={image_url} alt={`${owner} logo`} onError={onError}/>
<img src={image_url} alt={`${owner} logo`} onError={onError} />
</div>
)}
</>
Expand Down
2 changes: 1 addition & 1 deletion ui/components/MarkdownBlock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function replacer(matched) {

export default function MarkdownBlock({ md }) {
const linkRegex = /(?<=href=")[^"]+/g;
const mdString = Array.isArray(md) ? md.join("\n") : md;
const mdString = Array.isArray(md) ? md.join('\n') : md;
const decodedMd = mdString.replace(linkRegex, replacer);

return (
Expand Down
2 changes: 1 addition & 1 deletion ui/cypress/e2e/home.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Homepage', () => {
describe('Search', () => {
it('Can search from the homepage', () => {
cy.visit('/');
cy.doSearch('allergies');
cy.doSearch('hospital');
cy.get('#browse-results li').not('have.length', 0);
});
it('Blank search returns results', () => {
Expand Down
38 changes: 25 additions & 13 deletions ui/cypress/e2e/standards/list.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,31 @@ describe('Standards Listing Index', () => {
it('Can filter by mandated, and remove filter (regression)', () => {
cy.visit('/published-standards');
let results;
cy.get('span[role="status"]').should((el) => {
results = parseInt(el.text().replace(' Results', ''));

cy.get('span[role="status"]').then($span => {
const text = $span.text()
results = parseInt(text.match(/\d+/)[0])
});
cy.get('#mandated').click();

cy.get('span[role="status"]').should((el) => {
const filteredResults = parseInt(el.text().replace(' Results', ''));
cy.get('[title="Requirement"]').click();
cy.get('#mandated').scrollIntoView().click({ force: true });

// wait added for api response
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.lessThan(results);
});

cy.get('#mandated').click();

cy.get('span[role="status"]').should((el) => {
const filteredResults = parseInt(el.text().replace(' Results', ''));
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);
});
});
Expand All @@ -90,7 +101,8 @@ describe('Standards Listing Index', () => {
cy.get('.nhsuk-pagination').contains('a', 'Next').click();
cy.url().should('contain', 'page=2');

cy.get('#mandated').click();
cy.get('[title="Requirement"]').click();
cy.get('#mandated').scrollIntoView().click({ force: true });

cy.url().should('not.contain', 'page');
cy.url().should('contain', 'mandated');
Expand All @@ -101,18 +113,18 @@ describe('Standards Listing Index', () => {
it('Can search by standard matching', () => {
cy.visit('/published-standards');
cy.injectAxe();
cy.doSearch('allergies');
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('alergy');
cy.doSearch('hosptal');

cy.get('#browse-results li').should('have.length.of.at.least', 1);
cy.contains('#browse-results li', 'Allergy').click();
cy.contains('#browse-results li', 'hospital');
});

it('emboldens matches', () => {
Expand All @@ -136,7 +148,7 @@ describe('Standards Listing Index', () => {

cy.get('#browse-results li a').eq(0).click();

cy.contains('dd', 'Professional Record Standards Body');
cy.contains('Core information standard');
});

it('Matches various variations of prsb', () => {
Expand All @@ -145,7 +157,7 @@ describe('Standards Listing Index', () => {

cy.get('#browse-results li a').eq(0).click();

cy.contains('dd', 'Professional Record Standards Body');
cy.contains('Community Pharmacy Information Standard');

cy.visit('/published-standards');
cy.doSearch('professional records standards body');
Expand Down
2 changes: 1 addition & 1 deletion ui/cypress/e2e/static-page.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('Static page', () => {
cy.visit('/help-and-resources');
cy.injectAxe();
cy.checkA11y(null, null, a11yLog, failLevel);
cy.doSearch('allergies');
cy.doSearch('hospital');
cy.get('#browse-results li').should('have.length.of.at.least', 1);
});
});
Expand Down
17 changes: 0 additions & 17 deletions ui/helpers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,10 @@ export function serialise(obj = {}) {
}

export async function read({ id }) {
console.log('read() Request URL: ', `${CKAN_URL}/package_show?id=${id}`);
return callApi(`${CKAN_URL}/package_show?id=${id}`);
}

export async function getPages() {
console.log(
'getPages() Request URL: ',
`${PAGES_CKAN_URL}/ckanext_pages_list`
);
return callApi(`${PAGES_CKAN_URL}/ckanext_pages_list`);
}

Expand Down Expand Up @@ -151,25 +146,13 @@ export async function list(

const query = getSearchQuery(q);
const ckanQuery = stringify({ q: query, fq, rows, start, sort: sortstring });
console.log(
'list() Request URL: ',
`${CKAN_URL}/package_search?${ckanQuery}`
);
return callApi(`${CKAN_URL}/package_search?${ckanQuery}`);
}

export async function schema(dataset = 'dataset') {
console.log(
'schema() Request URL: ',
`${CKAN_URL}/scheming_dataset_schema_show?type=${dataset}`
);
return callApi(`${CKAN_URL}/scheming_dataset_schema_show?type=${dataset}`);
}

export async function filterSearch(query = '') {
console.log(
'filterSearch() Request URL: ',
`${CKAN_URL}/package_search${query}`
);
return callApi(`${CKAN_URL}/package_search${query}`);
}
9 changes: 9 additions & 0 deletions ui/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
const path = require('path');

const esModules = [
'rehype-raw',
'hast-util-raw',
'hast-util-from-parse5',
'hastscript',
'hast-util-parse-selector',
'hast-util-to-parse5',
'web-namespaces',
'zwitch',
'html-void-elements',
'react-markdown',
'vfile',
'unist-.+',
Expand Down
1 change: 0 additions & 1 deletion ui/schema/future-standards/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import upperFirst from 'lodash/upperFirst';
import {
Details,
Tag,
Link,
MarkdownBlock,
Paragraph,
Dl,
Expand Down
1 change: 0 additions & 1 deletion ui/schema/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import upperFirst from 'lodash/upperFirst';
import {
Details,
Tag,
Link,
MarkdownBlock,
Paragraph,
Dl,
Expand Down
1 change: 0 additions & 1 deletion ui/schema/published-standards/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import upperFirst from 'lodash/upperFirst';
import {
Details,
Tag,
Link,
MarkdownBlock,
Paragraph,
Dl,
Expand Down

0 comments on commit c0d98ca

Please sign in to comment.