-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update failing and adds new integration tests
- Loading branch information
Showing
4 changed files
with
149 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
web/tests/Web.Integration.Tests/Pages/Schools/WhenViewingResources.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
]; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters