Skip to content

Commit

Permalink
Add e2e tests for accepting rejecting cancelling cases (#826)
Browse files Browse the repository at this point in the history
* Added test class

* Added End to End tests for acceepting / rejecting / cancelling cases

* Amended to run tests for both change of name and change of date of birth scenarios
  • Loading branch information
hortha authored Sep 18, 2023
1 parent d521b4a commit e37bd98
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ private Host<Program> CreateHost() =>
services.AddSingleton<CurrentUserProvider>();
services.AddTransient<TestUsers.CreateUsersStartupTask>();
services.AddStartupTask<TestUsers.CreateUsersStartupTask>();
services.AddSingleton<TestData>();
services.AddFakeXrm();
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -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}')");
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using TeachingRecordSystem.Core.DataStore.Postgres.Models;
using TeachingRecordSystem.SupportUi.EndToEndTests.Infrastructure.Security;
using TeachingRecordSystem.TestCommon;

namespace TeachingRecordSystem.SupportUi.EndToEndTests;

Expand All @@ -14,6 +15,8 @@ public TestBase(HostFixture hostFixture)

public HostFixture HostFixture { get; }

public TestData TestData => HostFixture.Services.GetRequiredService<TestData>();

protected void SetCurrentUser(User user)
{
var currentUserProvider = HostFixture.Services.GetRequiredService<CurrentUserProvider>();
Expand Down

0 comments on commit e37bd98

Please sign in to comment.