Skip to content

Commit

Permalink
chore: update failing and adds new integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
J05h-L committed Oct 15, 2024
1 parent 8662de3 commit e2d1bd1
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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" },
};

}
128 changes: 128 additions & 0 deletions web/tests/Web.Integration.Tests/Pages/Schools/WhenViewingResources.cs
Original file line number Diff line number Diff line change
@@ -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<SchoolBenchmarkingWebAppClient>(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<School>()
.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<RagRating>();

var otherRating = Fixture.Build<RagRating>()
.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<RagRating>()
.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<string> AllCostCategories =
[
Category.TeachingStaff,
Category.NonEducationalSupportStaff,
Category.EducationalSupplies,
Category.EducationalIct,
Category.PremisesStaffServices,
Category.Utilities,
Category.AdministrativeSupplies,
Category.CateringStaffServices,
Category.Other
];
}

Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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" },
};

}
1 change: 1 addition & 0 deletions web/tests/Web.Integration.Tests/Paths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
}

0 comments on commit e2d1bd1

Please sign in to comment.