diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.EndToEndTests/CaseTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.EndToEndTests/CaseTests.cs new file mode 100644 index 000000000..f4221baaf --- /dev/null +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.EndToEndTests/CaseTests.cs @@ -0,0 +1,141 @@ +using TeachingRecordSystem.TestCommon; + +namespace TeachingRecordSystem.SupportUi.EndToEndTests; + +public class CaseTests : TestBase +{ + public CaseTests(HostFixture hostFixture) + : base(hostFixture) + { + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public async Task SelectCaseAndApprove(bool isNameChange) + { + var createPersonResult = await TestData.CreatePerson(); + string caseReference; + if (isNameChange) + { + var createIncidentResult = await TestData.CreateNameChangeIncident(b => b.WithCustomerId(createPersonResult.ContactId)); + caseReference = createIncidentResult.TicketNumber; + } + else + { + var createIncidentResult = await TestData.CreateDateOfBirthChangeIncident(b => b.WithCustomerId(createPersonResult.ContactId)); + caseReference = createIncidentResult.TicketNumber; + } + + await using var context = await HostFixture.CreateBrowserContext(); + var page = await context.NewPageAsync(); + + await page.GoToHomePage(); + + await page.ClickOpenCasesLinkInNavigationBar(); + + await page.AssertOnOpenCasesPage(); + + await page.ClickCaseReferenceLinkOpenCasesPage(caseReference); + + await page.AssertOnCaseDetailPage(caseReference); + + await page.ClickAcceptChangeButton(); + + await page.AssertOnAcceptCasePage(caseReference); + + await page.ClickConfirmButton(); + + await page.AssertOnOpenCasesPage(); + + await page.AssertFlashMessage("The request has been accepted"); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public async Task SelectCaseAndReject(bool isNameChange) + { + var createPersonResult = await TestData.CreatePerson(); + string caseReference; + if (isNameChange) + { + var createIncidentResult = await TestData.CreateNameChangeIncident(b => b.WithCustomerId(createPersonResult.ContactId)); + caseReference = createIncidentResult.TicketNumber; + } + else + { + var createIncidentResult = await TestData.CreateDateOfBirthChangeIncident(b => b.WithCustomerId(createPersonResult.ContactId)); + caseReference = createIncidentResult.TicketNumber; + } + + await using var context = await HostFixture.CreateBrowserContext(); + var page = await context.NewPageAsync(); + + await page.GoToHomePage(); + + await page.ClickOpenCasesLinkInNavigationBar(); + + await page.AssertOnOpenCasesPage(); + + await page.ClickCaseReferenceLinkOpenCasesPage(caseReference); + + await page.AssertOnCaseDetailPage(caseReference); + + await page.ClickRejectChangeButton(); + + await page.AssertOnRejectCasePage(caseReference); + + await page.CheckAsync("label:text-is('Request and proof don’t match')"); + + await page.ClickConfirmButton(); + + await page.AssertOnOpenCasesPage(); + + await page.AssertFlashMessage("The request has been rejected"); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public async Task SelectCaseAndCancel(bool isNameChange) + { + var createPersonResult = await TestData.CreatePerson(); + string caseReference; + if (isNameChange) + { + var createIncidentResult = await TestData.CreateNameChangeIncident(b => b.WithCustomerId(createPersonResult.ContactId)); + caseReference = createIncidentResult.TicketNumber; + } + else + { + var createIncidentResult = await TestData.CreateDateOfBirthChangeIncident(b => b.WithCustomerId(createPersonResult.ContactId)); + caseReference = createIncidentResult.TicketNumber; + } + + await using var context = await HostFixture.CreateBrowserContext(); + var page = await context.NewPageAsync(); + + await page.GoToHomePage(); + + await page.ClickOpenCasesLinkInNavigationBar(); + + await page.AssertOnOpenCasesPage(); + + await page.ClickCaseReferenceLinkOpenCasesPage(caseReference); + + await page.AssertOnCaseDetailPage(caseReference); + + await page.ClickRejectChangeButton(); + + await page.AssertOnRejectCasePage(caseReference); + + await page.CheckAsync("label:text-is('Change no longer required')"); + + await page.ClickConfirmButton(); + + await page.AssertOnOpenCasesPage(); + + await page.AssertFlashMessage("The request has been cancelled"); + } +} diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.EndToEndTests/HostFixture.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.EndToEndTests/HostFixture.cs index 401748f08..e9b130649 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.EndToEndTests/HostFixture.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.EndToEndTests/HostFixture.cs @@ -71,6 +71,8 @@ private Host CreateHost() => services.AddSingleton(); services.AddTransient(); services.AddStartupTask(); + services.AddSingleton(); + services.AddFakeXrm(); }); }); diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.EndToEndTests/PageExtensions.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.EndToEndTests/PageExtensions.cs new file mode 100644 index 000000000..e271d7bc5 --- /dev/null +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.EndToEndTests/PageExtensions.cs @@ -0,0 +1,65 @@ +using Microsoft.Playwright; + +namespace TeachingRecordSystem.SupportUi.EndToEndTests; + +public static class PageExtensions +{ + public static Task WaitForUrlPathAsync(this IPage page, string path) => + page.WaitForURLAsync(url => + { + var asUri = new Uri(url); + return asUri.LocalPath == path; + }); + + public static async Task GoToHomePage(this IPage page) + { + await page.GotoAsync("/"); + } + + public static async Task ClickOpenCasesLinkInNavigationBar(this IPage page) + { + await page.ClickAsync("a:text-is('Open cases')"); + } + + public static async Task AssertOnOpenCasesPage(this IPage page) + { + await page.WaitForUrlPathAsync("/cases"); + } + + public static async Task ClickCaseReferenceLinkOpenCasesPage(this IPage page, string caseReference) + { + await page.ClickAsync($"a:text-is('{caseReference}')"); + } + + public static async Task AssertOnCaseDetailPage(this IPage page, string caseReference) + { + await page.WaitForUrlPathAsync($"/cases/{caseReference}"); + } + + public static async Task AssertOnAcceptCasePage(this IPage page, string caseReference) + { + await page.WaitForUrlPathAsync($"/cases/{caseReference}/accept"); + } + + public static async Task AssertOnRejectCasePage(this IPage page, string caseReference) + { + await page.WaitForUrlPathAsync($"/cases/{caseReference}/reject"); + } + + public static async Task AssertFlashMessage(this IPage page, string expectedHeader) + { + Assert.Equal(expectedHeader, await page.InnerTextAsync($".govuk-notification-banner__heading:text-is('{expectedHeader}')")); + } + + public static Task ClickAcceptChangeButton(this IPage page) + => ClickButton(page, "Accept change"); + + public static Task ClickRejectChangeButton(this IPage page) + => ClickButton(page, "Reject change"); + + public static Task ClickConfirmButton(this IPage page) + => ClickButton(page, "Confirm"); + + private static Task ClickButton(this IPage page, string text) => + page.ClickAsync($".govuk-button:text-is('{text}')"); +} diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.EndToEndTests/TestBase.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.EndToEndTests/TestBase.cs index 662df465f..8f842c193 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.EndToEndTests/TestBase.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.EndToEndTests/TestBase.cs @@ -1,5 +1,6 @@ using TeachingRecordSystem.Core.DataStore.Postgres.Models; using TeachingRecordSystem.SupportUi.EndToEndTests.Infrastructure.Security; +using TeachingRecordSystem.TestCommon; namespace TeachingRecordSystem.SupportUi.EndToEndTests; @@ -14,6 +15,8 @@ public TestBase(HostFixture hostFixture) public HostFixture HostFixture { get; } + public TestData TestData => HostFixture.Services.GetRequiredService(); + protected void SetCurrentUser(User user) { var currentUserProvider = HostFixture.Services.GetRequiredService();