Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
baseUrl: "http://localhost:3000",
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
17 changes: 17 additions & 0 deletions cypress/e2e/1-Increase-table-font-size​/table-font-size.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// <reference types="cypress" />

describe("1 - Increase table font size", () => {
beforeEach(() => {
cy.visit("/");
});

it("Establishment names and their ratings should have a font size of 20 pixels", () => {
// select table and test computed styles
cy.get(".establishment-table")
.then(($el) => {
return window.getComputedStyle($el[0]);
})
.invoke("getPropertyValue", "font-size")
.should("equal", "20px");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/// <reference types="cypress" />

describe("2 - Show loading text when waiting loading the next page of data", () => {
beforeEach(() => {
cy.visit("/");
cy.intercept("GET", "**/Establishments/basic/**").as("getEstablishments");
});

it("When user visits home page should see loading text", () => {
cy.get("table").contains("Loading ...").should("exist");
cy.wait("@getEstablishments").then(() => {
cy.get("table").contains("Loading ...").should("not.exist");
});
});
it("When user navigate to next page in table see loading text", () => {
cy.wait("@getEstablishments").then(() => {
cy.get("table").contains("Loading ...").should("not.exist");
cy.get("button").contains("+").click();
cy.get("table").contains("Loading ...").should("exist");
cy.wait("@getEstablishments").then(() => {
cy.get("table").contains("Loading ...").should("not.exist");
});
});
});
it("When user navigate to previous page in table see loading text", () => {
cy.wait("@getEstablishments").then(() => {
cy.get("table").contains("Loading ...").should("not.exist");
cy.get("button").contains("+").click();
cy.get("table").contains("Loading ...").should("exist");
cy.wait("@getEstablishments")
.then(() => {
cy.get("table").contains("Loading ...").should("not.exist");
cy.get("button").contains("-").click();
cy.get("table").contains("Loading ...").should("exist");
})
.then(() => {
cy.wait("@getEstablishments").then(() => {
cy.get("table").contains("Loading ...").should("not.exist");
});
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/// <reference types="cypress" />

describe("3-Filter-Establishments-by-Authority", () => {
beforeEach(() => {
cy.visit("/");
cy.intercept("GET", "**/Authorities/basic/").as("getAuthorities");
cy.intercept(
"GET",
"**/Establishments?pageNumber=1&localAuthorityId=**"
).as("getFilteredEstablishments");
});

it("When the user clicks the Authority drop-down box on home page there is a list of Authorities", () => {
cy.wait("@getAuthorities").then((xhr) => {
const responseDataToCheck = xhr.response?.body.authorities.map(
({ LocalAuthorityId, Name }) => [`${LocalAuthorityId}`, Name]
);
cy.get("select option").then((options) => {
const actual = [...options].map((o) => [o.value, o.textContent]);
expect(actual).to.deep.eq([
["Select authority...", "Select authority..."],
...responseDataToCheck,
]);
});
});
});

it("When the user has clicked the Authority drop-down box. Establishements are filtered by Authority", () => {
cy.get("select").select(2);
cy.get("select option:selected")
.invoke("attr", "value")
.then((selectedID) => {
cy.wait("@getFilteredEstablishments").then((xhr) => {
expect(xhr.request.url).to.include(
`/Establishments?pageNumber=1&localAuthorityId=${selectedID}`
);

const expetedDataInTable = xhr.response?.body.establishments.map(
({ BusinessName, RatingValue }) => [BusinessName, RatingValue, ""]
);
cy.get("table tbody")
.table()
.then((dataInTable) => {
expect(dataInTable).to.deep.equal(expetedDataInTable);
});
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/// <reference types="cypress" />
import { format } from "date-fns";

describe("4 Establishments link to their detail page", () => {
beforeEach(() => {
cy.visit("/");
cy.intercept("GET", "**/Establishments/basic/1/10").as("getEstablishments");
cy.intercept("GET", "**/Establishments/1549111").as(
"getEstablishmentDetail"
);
});

it("When the user clicks on an Establishment's name get redirected to detail page with title address rate and date.", () => {
cy.wait("@getEstablishments");
cy.get(".establishment-table a")
.first()
.should("have.attr", "href")
.and("include", `/establishment/`);
cy.get(".establishment-table a").first().click();

cy.wait("@getEstablishmentDetail").then((xhr) => {
const title = xhr.response?.body.BusinessName;
const FHRSID = xhr.response?.body.FHRSID;
const AddressLine1 = xhr.response?.body.AddressLine1;
const AddressLine2 = xhr.response?.body.AddressLine2;
const AddressLine3 = xhr.response?.body.AddressLine3;
const AddressLine4 = xhr.response?.body.AddressLine4;
const RatingValue = xhr.response?.body.RatingValue;
const RatingDate = xhr.response?.body.RatingDate;

cy.url().should(
"include",
`${Cypress.config("baseUrl")}/establishment/${FHRSID}`
);
cy.get("h1").should("exist").should("have.text", title);
cy.get("address")
.should("exist")
.should("contain.text", AddressLine1)
.should("contain.text", AddressLine2)
.should("contain.text", AddressLine3)
.should("contain.text", AddressLine4);
cy.get('[data-cy="rating"]')
.should("exist")
.should("contain.text", `Rating: ${RatingValue}`);
cy.get('[data-cy="rating-date"]')
.should("exist")
.should(
"contain.text",
`Date: ${format(new Date(RatingDate), "dd/MM/yy")}`
);
});
});

it("When the user clicks on an Establishment's name get redirected to detail page with back button.", () => {
cy.wait("@getEstablishments");
cy.get(".establishment-table a")
.first()
.should("have.attr", "href")
.and("include", `/establishment/`);
cy.get(".establishment-table a").first().click();
cy.url().should("include", `${Cypress.config("baseUrl")}/establishment/`);
cy.get("button").should("have.text", "Go Back").click();
cy.url().should("equal", `${Cypress.config("baseUrl")}/`);
});
});
74 changes: 74 additions & 0 deletions cypress/e2e/5-Favourites-table/favourites-table.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/// <reference types="cypress" />

describe("5-Favourites-table", () => {
beforeEach(() => {
cy.visit("/");
cy.intercept("GET", "**/Establishments/basic/1/10").as("getEstablishments");
cy.intercept("GET", "**/Establishments/1549111").as(
"getEstablishmentDetail"
);
});

it.skip("When the user check checkbox establishment is added to favourites if uncheck it is removed, remove button in favourite table removes item from favourites", () => {
cy.wait("@getEstablishments").then(() => {
cy.get("input[type=checkbox]").eq(0).click();
cy.get("input[type=checkbox]").eq(0).should("be.checked");
cy.get("input[type=checkbox]").eq(2).click();
cy.get("input[type=checkbox]").eq(2).should("be.checked");

cy.get("table tbody")
.eq(0)
.table(0, 0, 2)
.then((mainRows) => {
cy.get("table tbody")
.eq(1)
.table(0, 0, 2)
.then((favouriteRows) => {
expect(favouriteRows).to.deep.equal([mainRows[0], mainRows[2]]);
});
});

cy.get("input[type=checkbox]").eq(0).click();

cy.get("input[type=checkbox]").eq(0).should("not.be.checked");

cy.get("table tbody")
.eq(0)
.table(0, 0, 2)
.then((mainRows) => {
cy.get("table tbody")
.eq(1)
.table(0, 0, 2)
.then((favouriteRows) => {
expect(favouriteRows).to.deep.equal([mainRows[2]]);
});
});
cy.get("button").contains("Remove").click();
cy.get("table tbody")
.eq(1)
.table(0, 0, 2)
.then((favouriteRows) => {
expect(favouriteRows).to.deep.equal([]);
});

cy.get("input[type=checkbox]").eq(2).should("not.be.checked");
});
});

it("This table should appear on all subsequent pages", () => {
cy.wait("@getEstablishments");
cy.get("input[type=checkbox]").eq(0).click();
cy.get("table tbody")
.eq(0)
.table(0, 0, 2)
.then((mainRows) => {
cy.get(".establishment-table a").first().click();
cy.get("table tbody")
.eq(0)
.table(0, 0, 2)
.then((favouriteRows) => {
expect(favouriteRows).to.deep.equal([mainRows[0]]);
});
});
});
});
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
21 changes: 21 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import "./commands";
import "cypress-map";

// Alternatively you can use CommonJS syntax:
// require('./commands')
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@tanstack/react-query": "^5.28.2",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/jest": "^26.0.15",
"@types/node": "^12.0.0",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"date-fns": "^3.4.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.22.3",
"react-scripts": "^5.0.1",
"typescript": "^4.1.2",
"web-vitals": "^1.0.1"
},
Expand All @@ -21,6 +24,7 @@
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"e2e": "yarn cypress run --headed"
},
"eslintConfig": {
"extends": [
Expand All @@ -41,6 +45,8 @@
]
},
"devDependencies": {
"cypress": "^13.7.0",
"cypress-map": "^1.37.0",
"jest-fetch-mock": "^3.0.3"
}
}
Loading