Skip to content

Commit

Permalink
added tests for the search page
Browse files Browse the repository at this point in the history
  • Loading branch information
mikestock-nimble committed Jan 23, 2024
1 parent b382bda commit 832cf1f
Show file tree
Hide file tree
Showing 9 changed files with 297 additions and 16 deletions.
8 changes: 4 additions & 4 deletions DfE.FindInformationAcademiesTrusts/Pages/Search.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@
<ul class="govuk-list">
@foreach (var trust in Model.Trusts)
{
<li class="govuk-!-margin-bottom-6">
<a asp-page="./Trusts/Details" asp-route-uid="@trust.Uid" class="govuk-!-font-weight-bold govuk-link govuk-!-font-size-24">@Html.DisplayFor(modelItem => trust.Name)</a>
<li class="govuk-!-margin-bottom-6" data-testid="trust-result">
<a asp-page="./Trusts/Details" asp-route-uid="@trust.Uid" class="govuk-!-font-weight-bold govuk-link govuk-!-font-size-24" data-testid="trust-name">@Html.DisplayFor(modelItem => trust.Name)</a>
<dl class="govuk-summary-list govuk-summary-list--no-border app-search-results-summary-list">
<div class="govuk-summary-list__row govuk-body app-search-results-summary-list__row">
<dt class="govuk-summary-list__key app-search-results-summary-list__key app-search-results-summary-list__item">
Address:
</dt>
<dd class="govuk-summary-list__value app-search-results-summary-list__item">
<dd class="govuk-summary-list__value app-search-results-summary-list__item" data-testid="address">
@Html.DisplayFor(modelItem => trust.Address)
</dd>
</div>
<div class="govuk-summary-list__row govuk-body app-search-results-summary-list__row">
<dt class="govuk-summary-list__key app-search-results-summary-list__key app-search-results-summary-list__item">
Group ID/TRN:
</dt>
<dd class="govuk-summary-list__value app-search-results-summary-list__item">
<dd class="govuk-summary-list__value app-search-results-summary-list__item" data-testid="trn">
@Html.DisplayFor(modelItem => trust.GroupId)
</dd>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@if (Model.PageStatus.HasPreviousPage)
{
<div class="govuk-pagination__prev">
<a class="govuk-link govuk-pagination__link" asp-page="@("/" + Model.PageName)" asp-all-route-data="@Model.PaginationRouteData" asp-route-PageNumber="@(Model.PageStatus.PageIndex - 1)" rel="prev">
<a class="govuk-link govuk-pagination__link" asp-page="@("/" + Model.PageName)" asp-all-route-data="@Model.PaginationRouteData" asp-route-PageNumber="@(Model.PageStatus.PageIndex - 1)" rel="prev" data-testid="previous-page">
<svg class="govuk-pagination__icon govuk-pagination__icon--prev" xmlns="http://www.w3.org/2000/svg" height="13" width="15" aria-hidden="true" focusable="false" viewBox="0 0 15 13">
<path d="m6.5938-0.0078125-6.7266 6.7266 6.7441 6.4062 1.377-1.449-4.1856-3.9768h12.896v-2h-12.984l4.2931-4.293-1.414-1.414z"></path>
</svg>
Expand All @@ -18,7 +18,7 @@
@if (Model.PageStatus.PageIndex != 1)
{
<li class="govuk-pagination__item">
<a class="govuk-link govuk-pagination__link" asp-page="@("/" + Model.PageName)" asp-all-route-data="@Model.PaginationRouteData" asp-route-PageNumber="1" aria-label="Page 1">
<a class="govuk-link govuk-pagination__link" asp-page="@("/" + Model.PageName)" asp-all-route-data="@Model.PaginationRouteData" asp-route-PageNumber="1" aria-label="Page 1" data-testid="page-1">
1
</a>
</li>
Expand All @@ -32,22 +32,22 @@
@if (Model.PageStatus.HasPreviousPage && Model.PageStatus.PageIndex - 1 != 1)
{
<li class="govuk-pagination__item">
<a class="govuk-link govuk-pagination__link" asp-page="@("/" + Model.PageName)" asp-all-route-data="@Model.PaginationRouteData" asp-route-PageNumber="@(Model.PageStatus.PageIndex - 1)" aria-label="Page @(Model.PageStatus.PageIndex - 1)">
<a class="govuk-link govuk-pagination__link" asp-page="@("/" + Model.PageName)" asp-all-route-data="@Model.PaginationRouteData" asp-route-PageNumber="@(Model.PageStatus.PageIndex - 1)" aria-label="Page @(Model.PageStatus.PageIndex - 1)" data-testid="page-@(Model.PageStatus.PageIndex - 1)">
@(Model.PageStatus.PageIndex - 1)
</a>
</li>
}
@* Current page *@
<li class="govuk-pagination__item govuk-pagination__item--current">
<a class="govuk-link govuk-pagination__link" href="#" aria-label="Page @Model.PageStatus.PageIndex" aria-current="page">
<a class="govuk-link govuk-pagination__link" href="#" aria-label="Page @Model.PageStatus.PageIndex" aria-current="page" data-testid="[email protected]">
@Model.PageStatus.PageIndex
</a>
</li>
@* Next Page *@
@if (Model.PageStatus.PageIndex != Model.PageStatus.TotalPages && Model.PageStatus.PageIndex + 1 != Model.PageStatus.TotalPages)
{
<li class="govuk-pagination__item">
<a class="govuk-link govuk-pagination__link" asp-page="@("/" + Model.PageName)" asp-all-route-data="@Model.PaginationRouteData" asp-route-PageNumber="@(Model.PageStatus.PageIndex + 1)" aria-label="Page @(Model.PageStatus.PageIndex + 1)">
<a class="govuk-link govuk-pagination__link" asp-page="@("/" + Model.PageName)" asp-all-route-data="@Model.PaginationRouteData" asp-route-PageNumber="@(Model.PageStatus.PageIndex + 1)" aria-label="Page @(Model.PageStatus.PageIndex + 1)" data-testid="page-@(Model.PageStatus.PageIndex + 1)">
@(Model.PageStatus.PageIndex + 1)
</a>
</li>
Expand All @@ -61,7 +61,7 @@
@if (Model.PageStatus.PageIndex != Model.PageStatus.TotalPages)
{
<li class="govuk-pagination__item">
<a class="govuk-link govuk-pagination__link" asp-page="@("/" + Model.PageName)" asp-all-route-data="@Model.PaginationRouteData" asp-route-PageNumber="@(Model.PageStatus.TotalPages)" aria-label="Page @(Model.PageStatus.TotalPages)">
<a class="govuk-link govuk-pagination__link" asp-page="@("/" + Model.PageName)" asp-all-route-data="@Model.PaginationRouteData" asp-route-PageNumber="@(Model.PageStatus.TotalPages)" aria-label="Page @(Model.PageStatus.TotalPages)" data-testid="[email protected]">
@(Model.PageStatus.TotalPages)
</a>
</li>
Expand All @@ -71,7 +71,7 @@
@if (Model.PageStatus.HasNextPage)
{
<div class="govuk-pagination__next">
<a class="govuk-link govuk-pagination__link" asp-page="@("/" + Model.PageName)" asp-all-route-data="@Model.PaginationRouteData" asp-route-PageNumber="@(Model.PageStatus.PageIndex + 1)">
<a class="govuk-link govuk-pagination__link" asp-page="@("/" + Model.PageName)" asp-all-route-data="@Model.PaginationRouteData" asp-route-PageNumber="@(Model.PageStatus.PageIndex + 1)" data-testid="next-page">
<span class="govuk-pagination__link-title">Next</span>
<svg class="govuk-pagination__icon govuk-pagination__icon--next" xmlns="http://www.w3.org/2000/svg" height="13" width="15" aria-hidden="true" focusable="false" viewBox="0 0 15 13">
<path d="m8.107-0.0078125-1.4136 1.414 4.2926 4.293h-12.986v2h12.896l-4.1855 3.9766 1.377 1.4492 6.7441-6.4062-6.7246-6.7266z"></path>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ describe("Testing cookies on the site", () => {

footerLinks.viewCookies();

cy.excuteAccessibilityTests();

cookiesPage
.hasConsent("accept")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("Checking the details of a trust that does not have any information", (
it("Should be able to find the trust and verify the empty information", () => {
searchTrustPage
.enterSearchText("The empty trust")
.withOption("The empty trust")
.getOption("The empty trust")
.then((option) => {
option
.hasName("The empty trust")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import { Logger } from "cypress/common/logger";
import paginationComponent from "cypress/pages/paginationComponent";
import searchTrustPage from "cypress/pages/searchTrustPage";
import trustPage from "cypress/pages/trustPage";

describe("Testing the search trust functionality", () => {
beforeEach(() => {
cy.login();
});

it("Should return no results found when searching for a trust that doesn't exist", () => {
searchTrustPage
.enterSearchText("The missing trust")
.getOption("No results found");

searchTrustPage.search();

searchTrustPage
.hasNumberOfResults(`0 results for "the missing trust"`);

cy.excuteAccessibilityTests();
});

it("Should return results when there is only one page of results", () => {

Logger.log("Ensure that the search shows the results that match the search string");

searchTrustPage
.enterSearchText("St Mary")
.getOption("ST MARY'S ACADEMY TRUST")
.then((option) => {
option
.hasName("ST MARY'S ACADEMY TRUST")
.hasHint("150 Madison Ville, Lempi Junction, Darrellport, HR52 1BO");
});

searchTrustPage
.getOption("ST MARY'S ANGLICAN ACADEMY")
.then((option) => {
option
.hasName("ST MARY'S ANGLICAN ACADEMY")
.hasHint("054 Kendrick Summit, South Michele, EP37 6WY");
});

searchTrustPage
.getOption("ST MARY'S CATHOLIC PRIMARY SCHOOL")
.then((option) => {
option
.hasName("ST MARY'S CATHOLIC PRIMARY SCHOOL")
.hasHint("82929 Reynold Key, DV28 0EM");
});

searchTrustPage.search();

searchTrustPage.hasNumberOfResults(`17 results for "st mary"`);

cy.excuteAccessibilityTests();

Logger.log("Checking a selection of the results");

searchTrustPage
.getSearchResult("ST MARY'S ACADEMY TRUST")
.then((result) => {
result
.hasName("ST MARY'S ACADEMY TRUST")
.hasAddress("150 Madison Ville, Lempi Junction, Darrellport, HR52 1BO")
.hasTrn("TR1471")
.hasUid("1283")
});

searchTrustPage
.getSearchResult("ST MARY'S ANGLICAN ACADEMY")
.then((result) => {
result
.hasName("ST MARY'S ANGLICAN ACADEMY")
.hasAddress("054 Kendrick Summit, South Michele, EP37 6WY")
.hasTrn("TR1464")
.hasUid("1284")
});

searchTrustPage
.getSearchResult("ST MARY'S CATHOLIC PRIMARY SCHOOL")
.then((result) => {
result
.hasName("ST MARY'S CATHOLIC PRIMARY SCHOOL")
.hasAddress("82929 Reynold Key, DV28 0EM")
.hasTrn("TR3814")
.hasUid("1286")
.select();
});

trustPage
.hasName("ST MARY'S CATHOLIC PRIMARY SCHOOL")
.hasType("Single-academy trust");
});

it.only("should pagination the results when there is a large number of matches", () => {
searchTrustPage
.enterSearchText("trust")
.search();

searchTrustPage.hasNumberOfResults(`69 results for "trust"`);

let trustsPageOne: Array<string> = [];
let trustsPageTwo: Array<string> = [];

searchTrustPage.getAllTrustResults()
.then((trusts) => {
trustsPageOne = trusts;

expect(trustsPageOne.length).to.equal(20);

paginationComponent.hasNoPrevious();

paginationComponent.isCurrentPage("1");
paginationComponent.goToPage("2");
return searchTrustPage.getAllTrustResults();
})
.then((trusts) => {
trustsPageTwo = trusts;

expect(trustsPageTwo.length).to.equal(20);

paginationComponent.isCurrentPage("2");

paginationComponent.previous();

return searchTrustPage.getAllTrustResults();
})
.then((trusts) => {

paginationComponent.isCurrentPage("1");

expect(trusts).to.deep.equal(trustsPageOne);

paginationComponent.next();

return searchTrustPage.getAllTrustResults();
})
.then((trusts) => {
paginationComponent.isCurrentPage("2");

expect(trustsPageTwo).to.deep.equal(trusts);

paginationComponent.goToPage("4");

return searchTrustPage.getAllTrustResults();
})
.then((trusts) => {
paginationComponent.isCurrentPage("4");

paginationComponent.hasNoNext();

expect(trusts.length).to.equal(9);
})

});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("Searching for a trust and checking information", () => {

searchTrustPage
.enterSearchText("St Mary's")
.withOption("ST MARY'S ACADEMY TRUST")
.getOption("ST MARY'S ACADEMY TRUST")
.then((option) => {
option
.hasName("ST MARY'S ACADEMY TRUST")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Logger } from "../common/logger";

export class CookiesPage {
public withConsent(consent: string): this {
cy.getById(`cookies-${consent.toLowerCase()}`).check();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Logger } from "cypress/common/logger";

export class PaginationComponent {
constructor() {

}

public next(): this {
cy.getByTestId(`next-page`).click();

return this;
}

public hasNoNext(): this {
cy.getByTestId("next-page").should("not.exist");

return this;
}

public previous(): this {
cy.getByTestId(`previous-page`).click();

return this;
}

public hasNoPrevious(): this {
cy.getByTestId("previous-page").should("not.exist");

return this;
}

public goToPage(pageNumber: string) {
Logger.log(`Moving to page ${pageNumber}`);

cy.getByTestId(`page-${pageNumber}`).click();

return this;
}

public isCurrentPage(pageNumber: string): this {
cy.getByTestId(`page-${pageNumber}`).parent().should("have.class", "govuk-pagination__item--current");

return this;
}
}

const paginationComponent = new PaginationComponent();

export default paginationComponent;
Loading

0 comments on commit 832cf1f

Please sign in to comment.