-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
edit start date page functionality and tests
- Loading branch information
Showing
6 changed files
with
215 additions
and
10 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
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
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
154 changes: 154 additions & 0 deletions
154
...System.SupportUi.Tests/PageTests/Persons/PersonDetail/EditInduction/EditStartDateTests.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,154 @@ | ||
using AngleSharp.Dom; | ||
using AngleSharp.Html.Dom; | ||
using TeachingRecordSystem.SupportUi.Pages.Persons.PersonDetail.EditInduction; | ||
|
||
namespace TeachingRecordSystem.SupportUi.Tests.PageTests.Persons.PersonDetail.EditInduction; | ||
|
||
public class EditStartDateTests(HostFixture hostFixture) : TestBase(hostFixture) | ||
{ | ||
[Fact] | ||
public async Task Get_WithStartDate_ShowsDate() | ||
{ | ||
// Arrange | ||
var dateValid = Clock.Today; | ||
var inductionStatus = InductionStatus.InProgress; | ||
var person = await TestData.CreatePersonAsync(p => p.WithQts()); | ||
var journeyInstance = await CreateJourneyInstanceAsync( | ||
person.PersonId, | ||
new EditInductionStateBuilder() | ||
.WithInitialisedState(inductionStatus, InductionJourneyPage.Status) | ||
.WithStartDate(dateValid) | ||
.Create()); | ||
|
||
var request = new HttpRequestMessage(HttpMethod.Get, $"/persons/{person.PersonId}/edit-induction/start-date?{journeyInstance.GetUniqueIdQueryParameter()}"); | ||
|
||
// Act | ||
var response = await HttpClient.SendAsync(request); | ||
|
||
// Assert | ||
var doc = await AssertEx.HtmlResponseAsync(response); | ||
var startDate = doc.QuerySelectorAll<IHtmlInputElement>("[type=text]"); | ||
Assert.Equal(dateValid.Day.ToString(), startDate.ElementAt(0).Value); | ||
Assert.Equal(dateValid.Month.ToString(), startDate.ElementAt(1).Value); | ||
Assert.Equal(dateValid.Year.ToString(), startDate.ElementAt(2).Value); | ||
} | ||
|
||
[Fact] | ||
public async Task Post_SetValidStartDate_PersistsStartDate() | ||
{ | ||
// Arrange | ||
var dateValid = Clock.Today; | ||
var inductionStatus = InductionStatus.InProgress; | ||
var person = await TestData.CreatePersonAsync(p => p.WithQts()); | ||
|
||
var journeyInstance = await CreateJourneyInstanceAsync( | ||
person.PersonId, | ||
new EditInductionStateBuilder() | ||
.WithInitialisedState(inductionStatus, InductionJourneyPage.Status) | ||
.Create()); | ||
|
||
var postRequest = new HttpRequestMessage(HttpMethod.Post, $"/persons/{person.PersonId}/edit-induction/start-date?{journeyInstance.GetUniqueIdQueryParameter()}") | ||
{ | ||
Content = new FormUrlEncodedContent(new Dictionary<string, string> | ||
{ | ||
["StartDate.Day"] = dateValid.Day.ToString(), | ||
["StartDate.Month"] = dateValid.Month.ToString(), | ||
["StartDate.Year"] = dateValid.Year.ToString() | ||
}) | ||
}; | ||
|
||
// Act | ||
var response = await HttpClient.SendAsync(postRequest); | ||
|
||
// Assert | ||
journeyInstance = await ReloadJourneyInstance(journeyInstance); | ||
Assert.Equal(dateValid, journeyInstance.State.StartDate); | ||
} | ||
|
||
[Fact] | ||
public async Task Post_NoStartDateIsEntered_ReturnsError() | ||
{ | ||
// Arrange | ||
var inductionStatus = InductionStatus.InProgress; | ||
var person = await TestData.CreatePersonAsync(p => p.WithQts()); | ||
var journeyInstance = await CreateJourneyInstanceAsync( | ||
person.PersonId, | ||
new EditInductionStateBuilder() | ||
.WithInitialisedState(inductionStatus, InductionJourneyPage.Status) | ||
.Create()); | ||
|
||
var postRequest = new HttpRequestMessage(HttpMethod.Post, $"/persons/{person.PersonId}/edit-induction/start-date?{journeyInstance.GetUniqueIdQueryParameter()}"); | ||
|
||
// Act | ||
var response = await HttpClient.SendAsync(postRequest); | ||
|
||
// Assert | ||
await AssertEx.HtmlResponseHasErrorAsync(response, "StartDate", "Enter an induction start date"); | ||
} | ||
|
||
[Fact] | ||
public async Task Post_StartDateIsInTheFuture_ReturnsError() | ||
{ | ||
// Arrange | ||
var dateTomorrow = Clock.Today.AddDays(1); | ||
var inductionStatus = InductionStatus.InProgress; | ||
var person = await TestData.CreatePersonAsync(p => p.WithQts()); | ||
var journeyInstance = await CreateJourneyInstanceAsync( | ||
person.PersonId, | ||
new EditInductionStateBuilder() | ||
.WithInitialisedState(inductionStatus, InductionJourneyPage.Status) | ||
.Create()); | ||
|
||
var postRequest = new HttpRequestMessage(HttpMethod.Post, $"/persons/{person.PersonId}/edit-induction/start-date?{journeyInstance.GetUniqueIdQueryParameter()}") | ||
{ | ||
Content = new FormUrlEncodedContent(new Dictionary<string, string> | ||
{ | ||
["StartDate.Day"] = dateTomorrow.Day.ToString(), | ||
["StartDate.Month"] = dateTomorrow.Month.ToString(), | ||
["StartDate.Year"] = dateTomorrow.Year.ToString() | ||
}) | ||
}; | ||
|
||
// Act | ||
var response = await HttpClient.SendAsync(postRequest); | ||
|
||
// Assert | ||
await AssertEx.HtmlResponseHasErrorAsync(response, "StartDate", "The induction start date cannot be in the future"); | ||
} | ||
|
||
[Fact] | ||
public async Task Post_StartDateIsTooEarly_ReturnsError() | ||
{ | ||
// Arrange | ||
var dateTooEarly = new DateOnly(1999,5,6); | ||
var inductionStatus = InductionStatus.InProgress; | ||
var person = await TestData.CreatePersonAsync(p => p.WithQts()); | ||
var journeyInstance = await CreateJourneyInstanceAsync( | ||
person.PersonId, | ||
new EditInductionStateBuilder() | ||
.WithInitialisedState(inductionStatus, InductionJourneyPage.Status) | ||
.Create()); | ||
|
||
var postRequest = new HttpRequestMessage(HttpMethod.Post, $"/persons/{person.PersonId}/edit-induction/start-date?{journeyInstance.GetUniqueIdQueryParameter()}") | ||
{ | ||
Content = new FormUrlEncodedContent(new Dictionary<string, string> | ||
{ | ||
["StartDate.Day"] = dateTooEarly.Day.ToString(), | ||
["StartDate.Month"] = dateTooEarly.Month.ToString(), | ||
["StartDate.Year"] = dateTooEarly.Year.ToString() | ||
}) | ||
}; | ||
|
||
// Act | ||
var response = await HttpClient.SendAsync(postRequest); | ||
|
||
// Assert | ||
await AssertEx.HtmlResponseHasErrorAsync(response, "StartDate", "The induction start date cannot be before 7th May 1999"); | ||
} | ||
|
||
private Task<JourneyInstance<EditInductionState>> CreateJourneyInstanceAsync(Guid personId, EditInductionState? state = null) => | ||
CreateJourneyInstance( | ||
JourneyNames.EditInduction, | ||
state ?? new EditInductionState(), | ||
new KeyValuePair<string, object>("personId", personId)); | ||
} |