From e2d1bd152b7e3813f20f247875c6e1e2cbae3bf9 Mon Sep 17 00:00:00 2001 From: Josh Langford Date: Fri, 11 Oct 2024 14:08:57 +0100 Subject: [PATCH] chore: update failing and adds new integration tests --- .../WhenViewingCustomDataSpending.cs | 12 +- .../Pages/Schools/WhenViewingResources.cs | 128 ++++++++++++++++++ .../Pages/Schools/WhenViewingSpending.cs | 12 +- web/tests/Web.Integration.Tests/Paths.cs | 1 + 4 files changed, 149 insertions(+), 4 deletions(-) create mode 100644 web/tests/Web.Integration.Tests/Pages/Schools/WhenViewingResources.cs diff --git a/web/tests/Web.Integration.Tests/Pages/Schools/CustomData/WhenViewingCustomDataSpending.cs b/web/tests/Web.Integration.Tests/Pages/Schools/CustomData/WhenViewingCustomDataSpending.cs index 3b007708f..f63cb42a5 100644 --- a/web/tests/Web.Integration.Tests/Pages/Schools/CustomData/WhenViewingCustomDataSpending.cs +++ b/web/tests/Web.Integration.Tests/Pages/Schools/CustomData/WhenViewingCustomDataSpending.cs @@ -33,7 +33,7 @@ public async Task CanNavigateUsingViewAllCategories() var categorySections = page.QuerySelectorAll("section"); - Assert.Equal(9, categorySections.Length); + Assert.Equal(8, categorySections.Length); var expectedUrl = Paths.SchoolComparisonCustomData(school.URN); @@ -155,6 +155,15 @@ private static void AssertPageLayout(IHtmlDocument page, School school) DocumentAssert.AssertPageUrl(page, Paths.SchoolSpendingCustomData(school.URN).ToAbsolute()); DocumentAssert.TitleAndH1(page, "Spending priorities for this school - Financial Benchmarking and Insights Tool - GOV.UK", "Spending priorities for this school"); + + var categorySections = page.QuerySelectorAll("section"); + + foreach (var section in categorySections) + { + var sectionHeading = section.QuerySelector("h3")?.TextContent; + + Assert.NotEqual(Category.Other, sectionHeading); + } } private RagRating[] CreateRagRatings(string urn) @@ -201,7 +210,6 @@ private RagRating[] CreateRagRatings(string urn) { "Utilities", "utilities" }, { "Administrative supplies", "administrative-supplies" }, { "Catering staff and supplies", "catering-staff-and-supplies" }, - { "Other costs", "other-costs" }, }; } \ No newline at end of file diff --git a/web/tests/Web.Integration.Tests/Pages/Schools/WhenViewingResources.cs b/web/tests/Web.Integration.Tests/Pages/Schools/WhenViewingResources.cs new file mode 100644 index 000000000..dc119ef96 --- /dev/null +++ b/web/tests/Web.Integration.Tests/Pages/Schools/WhenViewingResources.cs @@ -0,0 +1,128 @@ +using System.Net; +using AngleSharp.Dom; +using AngleSharp.Html.Dom; +using AngleSharp.XPath; +using AutoFixture; +using Web.App.Domain; +using Xunit; + +namespace Web.Integration.Tests.Pages.Schools; + +public class WhenViewingResources(SchoolBenchmarkingWebAppClient client) : PageBase(client) +{ + [Fact] + public async Task CanDisplay() + { + var (page, school, rating) = await SetupNavigateInitPage(); + + AssertPageLayout(page, school, rating); + } + + [Fact] + public async Task CanDisplayNotFound() + { + const string urn = "12345"; + var page = await Client.SetupEstablishmentWithNotFound() + .Navigate(Paths.SchoolResources(urn)); + + PageAssert.IsNotFoundPage(page); + DocumentAssert.AssertPageUrl(page, Paths.SchoolResources(urn).ToAbsolute(), HttpStatusCode.NotFound); + } + + [Fact] + public async Task CanDisplayProblemWithService() + { + const string urn = "12345"; + var page = await Client.SetupEstablishmentWithException() + .Navigate(Paths.SchoolResources(urn)); + + PageAssert.IsProblemPage(page); + DocumentAssert.AssertPageUrl(page, Paths.SchoolResources(urn).ToAbsolute(), HttpStatusCode.InternalServerError); + } + + private async Task<(IHtmlDocument page, School school, RagRating[] rating)> SetupNavigateInitPage() + { + var school = Fixture.Build() + .With(x => x.URN, "12345") + .Create(); + + Assert.NotNull(school.URN); + var rating = CreateRagRatings(school.URN); + + var page = await Client.SetupEstablishment(school) + .SetupMetricRagRating(rating) + .SetupInsights() + .SetupExpenditure(school) + .SetupUserData() + .Navigate(Paths.SchoolResources(school.URN)); + + return (page, school, rating); + } + + private static void AssertPageLayout(IHtmlDocument page, School school, RagRating[] rating) + { + DocumentAssert.AssertPageUrl(page, Paths.SchoolResources(school.URN).ToAbsolute()); + DocumentAssert.TitleAndH1(page, "Find ways to spend less - Financial Benchmarking and Insights Tool - GOV.UK", + "Find ways to spend less"); + + var recommended = page.GetElementById("recommended"); + + Assert.NotNull(recommended); + + var categorySections = recommended.QuerySelectorAll(".govuk-grid-column-two-thirds h2.govuk-heading-s"); + + var expectedCount = rating.Count(x => x.RAG is "red" or "amber" && x.Category is not Category.Other); + + Assert.Equal(expectedCount, categorySections.Length); + + foreach (var section in categorySections) + { + var sectionHeading = section.TextContent.Trim(); + + Assert.NotEqual(Category.Other, sectionHeading); + } + } + + private RagRating[] CreateRagRatings(string urn) + { + var random = new Random(); + + var statusKeys = Lookups.StatusPriorityMap.Keys.ToList(); + + var ratings = new List(); + + var otherRating = Fixture.Build() + .With(r => r.Category, Category.Other) + .With(r => r.RAG, "red") + .With(r => r.URN, urn) + .Create(); + + ratings.Add(otherRating); + + foreach (var category in AllCostCategories.Where(x => x != Category.Other)) + { + var rating = Fixture.Build() + .With(r => r.Category, category) + .With(r => r.RAG, () => statusKeys[random.Next(statusKeys.Count)]) + .With(r => r.URN, urn) + .Create(); + ratings.Add(rating); + } + + return ratings.ToArray(); + } + + private static readonly List AllCostCategories = + [ + Category.TeachingStaff, + Category.NonEducationalSupportStaff, + Category.EducationalSupplies, + Category.EducationalIct, + Category.PremisesStaffServices, + Category.Utilities, + Category.AdministrativeSupplies, + Category.CateringStaffServices, + Category.Other + ]; +} + diff --git a/web/tests/Web.Integration.Tests/Pages/Schools/WhenViewingSpending.cs b/web/tests/Web.Integration.Tests/Pages/Schools/WhenViewingSpending.cs index 2a7213d9a..67ef7f127 100644 --- a/web/tests/Web.Integration.Tests/Pages/Schools/WhenViewingSpending.cs +++ b/web/tests/Web.Integration.Tests/Pages/Schools/WhenViewingSpending.cs @@ -28,7 +28,7 @@ public async Task CanNavigateUsingViewAllCategories(string financeType) var categorySections = page.QuerySelectorAll("section"); - Assert.Equal(9, categorySections.Length); + Assert.Equal(8, categorySections.Length); var expectedUrl = Paths.SchoolComparison(school.URN); @@ -116,6 +116,15 @@ private static void AssertPageLayout(IHtmlDocument page, School school) DocumentAssert.AssertPageUrl(page, Paths.SchoolSpending(school.URN).ToAbsolute()); DocumentAssert.TitleAndH1(page, "Spending priorities for this school - Financial Benchmarking and Insights Tool - GOV.UK", "Spending priorities for this school"); + + var categorySections = page.QuerySelectorAll("section"); + + foreach (var section in categorySections) + { + var sectionHeading = section.QuerySelector("h3")?.TextContent; + + Assert.NotEqual(Category.Other, sectionHeading); + } } private RagRating[] CreateRagRatings(string urn) @@ -162,7 +171,6 @@ private RagRating[] CreateRagRatings(string urn) { "Utilities", "utilities" }, { "Administrative supplies", "administrative-supplies" }, { "Catering staff and supplies", "catering-staff-and-supplies" }, - { "Other costs", "other-costs" }, }; } \ No newline at end of file diff --git a/web/tests/Web.Integration.Tests/Paths.cs b/web/tests/Web.Integration.Tests/Paths.cs index d08e49f53..d1894b16c 100644 --- a/web/tests/Web.Integration.Tests/Paths.cs +++ b/web/tests/Web.Integration.Tests/Paths.cs @@ -98,5 +98,6 @@ public static string SchoolFinancialPlanningTotalEducationSupport(string? urn, i public static string ApiCensus(string id, string type, string category, string dimension) => $"api/census?id={id}&type={type}&category={category}&dimension={dimension}"; public static string LocalAuthorityHome(string? code) => $"/local-authority/{code}"; public static string LocalAuthorityResources(string? code) => $"/local-authority/{code}/find-ways-to-spend-less"; + public static string SchoolResources(string? urn) => $"/school/{urn}/find-ways-to-spend-less"; public static string ToAbsolute(this string path) => $"https://localhost{path}"; } \ No newline at end of file