Skip to content

Commit

Permalink
Amended MQ provider to be selected via an autocomplete rather than ra…
Browse files Browse the repository at this point in the history
…dio buttons (#953)

Fixed failing tests now that provider is selected via autocomplete

Fixed failing tests

Removed commented out code
  • Loading branch information
hortha authored Dec 8, 2023
1 parent 0242716 commit bdcdc4d
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
@page "/mqs/add/provider"
@model TeachingRecordSystem.SupportUi.Pages.Mqs.AddMq.ProviderModel
@addTagHelper *, Joonasw.AspNetCore.SecurityHeaders
@{
ViewBag.Title = "Training Provider";
ViewBag.Title = "Training provider";
}

@section Styles {
<link rel="stylesheet" href="~/Styles/Components/accessible-autocomplete.min.css" asp-append-version="true" />
}

@section Scripts {
<script src="~/Scripts/Components/accessible-autocomplete.min.js"></script>
<script asp-add-nonce="true">
window.onload = function () {
accessibleAutocomplete.enhanceSelectElement({
defaultValue: '',
selectElement: document.querySelector('#@nameof(Model.MqEstablishmentValue)')
})
}
</script>
}

@section BeforeContent {
<govuk-back-link href="@LinkGenerator.PersonQualifications(Model.PersonId)">Back</govuk-back-link>
}

<span class="govuk-caption-l">Add a mandatory qualification - @Model.PersonName</span>
<h1 class="govuk-heading-l" data-testid="title">@ViewBag.Title</h1>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<form action="@LinkGenerator.MqAddProvider(Model.PersonId, Model.JourneyInstance!.InstanceId)" method="post">
<govuk-radios asp-for="MqEstablishmentValue" data-testid="provider-list">
@if (Model.MqEstablishments is not null)
<govuk-select asp-for="MqEstablishmentValue" label-class="govuk-label--l">
<govuk-select-label is-page-heading="true">Training provider</govuk-select-label>
<govuk-select-item value=""></govuk-select-item>
@foreach (var establishment in Model.MqEstablishments!)
{
@foreach (var establishment in Model.MqEstablishments)
{
<govuk-radios-item value="@establishment.dfeta_Value">
@establishment.dfeta_name
</govuk-radios-item>
}
<govuk-select-item value="@establishment.dfeta_Value">@establishment.dfeta_name</govuk-select-item>
}
</govuk-radios>
</govuk-select>

<div class="govuk-button-group">
<govuk-button type="submit">Continue</govuk-button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ProviderModel(
public string? PersonName { get; set; }

[BindProperty]
[Display(Name = "Training Provider")]
[Display(Name = "Training provider")]
public string? MqEstablishmentValue { get; set; }

public dfeta_mqestablishment[]? MqEstablishments { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
@page "/mqs/{qualificationId}/provider/{handler?}"
@model TeachingRecordSystem.SupportUi.Pages.Mqs.EditMq.Provider.IndexModel
@addTagHelper *, Joonasw.AspNetCore.SecurityHeaders
@{
ViewBag.Title = "Training Provider";
ViewBag.Title = "Training provider";
}

@section Styles {
<link rel="stylesheet" href="~/Styles/Components/accessible-autocomplete.min.css" asp-append-version="true" />
}

@section Scripts {
<script src="~/Scripts/Components/accessible-autocomplete.min.js"></script>
<script asp-add-nonce="true">
window.onload = function () {
accessibleAutocomplete.enhanceSelectElement({
defaultValue: '',
selectElement: document.querySelector('#@nameof(Model.MqEstablishmentValue)')
})
}
</script>
}

@section BeforeContent {
<govuk-back-link href="@LinkGenerator.PersonQualifications(Model.PersonId!.Value)">Back</govuk-back-link>
}

<span class="govuk-caption-l">Change a mandatory qualification - @Model.PersonName</span>
<h1 class="govuk-heading-l" data-testid="title">@ViewBag.Title</h1>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<form action="@LinkGenerator.MqEditProvider(Model.QualificationId, Model.JourneyInstance!.InstanceId)" method="post">
<govuk-radios asp-for="MqEstablishmentValue" data-testid="provider-list">
@if (Model.MqEstablishments is not null)
<govuk-select asp-for="MqEstablishmentValue" label-class="govuk-label--l">
<govuk-select-label is-page-heading="true">Training provider</govuk-select-label>
<govuk-select-item value=""></govuk-select-item>
@foreach (var establishment in Model.MqEstablishments!)
{
@foreach (var establishment in Model.MqEstablishments)
{
<govuk-radios-item value="@establishment.dfeta_Value">
@establishment.dfeta_name
</govuk-radios-item>
}
<govuk-select-item value="@establishment.dfeta_Value">@establishment.dfeta_name</govuk-select-item>
}
</govuk-radios>
</govuk-select>

<div class="govuk-button-group">
<govuk-button type="submit">Continue</govuk-button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public async Task AddMq()

await page.AssertOnAddMqProviderPage();

await page.CheckAsync($"label:text-is('{mqEstablishment.dfeta_name}')");
await page.FillAsync($"label:text-is('Training provider')", mqEstablishment.dfeta_name);

await page.FocusAsync("button:text-is('Continue')");
await page.ClickContinueButton();

await page.AssertOnAddMqSpecialismPage();
Expand Down Expand Up @@ -84,10 +85,9 @@ public async Task EditMqProvider()

await page.AssertOnEditMqProviderPage(qualificationId);

await page.IsCheckedAsync($"label:text-is('{oldMqEstablishment.dfeta_name}')");

await page.CheckAsync($"label:text-is('{newMqEstablishment.dfeta_name}')");
await page.FillAsync($"label:text-is('Training provider')", newMqEstablishment.dfeta_name);

await page.FocusAsync("button:text-is('Continue')");
await page.ClickContinueButton();

await page.AssertOnEditMqProviderConfirmPage(qualificationId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using AngleSharp.Html.Dom;
using FormFlow;
using TeachingRecordSystem.SupportUi.Pages.Mqs.AddMq;

Expand Down Expand Up @@ -62,11 +63,9 @@ public async Task Get_ValidRequestWithPopulatedDataInJourneyState_PopulatesModel

// Assert
var doc = await response.GetDocument();
var providerList = doc.GetElementByTestId("provider-list");
var radioButtons = providerList!.GetElementsByTagName("input");
var selectedProvider = radioButtons.SingleOrDefault(r => r.HasAttribute("checked"));
var selectedProvider = doc.GetElementById("MqEstablishmentValue") as IHtmlSelectElement;
Assert.NotNull(selectedProvider);
Assert.Equal(mqEstablishmentValue, selectedProvider.GetAttribute("value"));
Assert.Equal(mqEstablishmentValue, selectedProvider.Value);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using AngleSharp.Html.Dom;
using FormFlow;
using TeachingRecordSystem.Core.Dqt.Models;
using TeachingRecordSystem.SupportUi.Pages.Mqs.EditMq.Provider;
Expand Down Expand Up @@ -46,11 +47,9 @@ public async Task Get_ValidRequestWithUninitializedJourneyState_PopulatesModelFr
Assert.Equal(StatusCodes.Status200OK, (int)response.StatusCode);

var doc = await response.GetDocument();
var providerList = doc.GetElementByTestId("provider-list");
var radioButtons = providerList!.GetElementsByTagName("input");
var selectedProvider = radioButtons.SingleOrDefault(r => r.HasAttribute("checked"));
var selectedProvider = doc.GetElementById("MqEstablishmentValue") as IHtmlSelectElement;
Assert.NotNull(selectedProvider);
Assert.Equal(databaseMqEstablishmentValue, selectedProvider.GetAttribute("value"));
Assert.Equal(databaseMqEstablishmentValue, selectedProvider.Value);
}

[Fact]
Expand Down Expand Up @@ -81,11 +80,9 @@ public async Task Get_ValidRequestWithInitializedJourneyState_PopulatesModelFrom
Assert.Equal(StatusCodes.Status200OK, (int)response.StatusCode);

var doc = await response.GetDocument();
var providerList = doc.GetElementByTestId("provider-list");
var radioButtons = providerList!.GetElementsByTagName("input");
var selectedProvider = radioButtons.SingleOrDefault(r => r.HasAttribute("checked"));
var selectedProvider = doc.GetElementById("MqEstablishmentValue") as IHtmlSelectElement;
Assert.NotNull(selectedProvider);
Assert.Equal(journeyMqEstablishmentValue, selectedProvider.GetAttribute("value"));
Assert.Equal(journeyMqEstablishmentValue, selectedProvider.Value);
}

[Fact]
Expand Down

0 comments on commit bdcdc4d

Please sign in to comment.