Skip to content

Commit

Permalink
CON-3521 EAS Add Alert Filter (#221)
Browse files Browse the repository at this point in the history
* Handle Alert Filter

* Maintain Alert filter

* clean up

* Fix Build

* Upgrade package

Co-authored-by: Raj <reachash1@hotmail.com>
  • Loading branch information
kola-samuel and reachash authored Jun 25, 2021
1 parent 49c81aa commit b4eb1cc
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public async Task ShouldMapApiValues(
Assert.AreEqual(request.SelectedCourse, viewModel.FilterModel.SelectedCourse);
Assert.AreEqual(request.SelectedStatus, viewModel.FilterModel.SelectedStatus);
Assert.AreEqual(request.SelectedEndDate, viewModel.FilterModel.SelectedEndDate);
Assert.AreEqual(request.SelectedAlert, viewModel.FilterModel.SelectedAlert);
}

[Test, MoqAutoData]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ public void And_No_Search_And_SelectedEndDate_Then_SelectedEndDate(
filterModel.FiltersUsedMessage.Value.Should().Be($"matching <strong>{selectedEndDate.ToGdsFormatWithoutDay()}</strong>");
}


[Test, AutoData]
public void And_No_Search_And_SelectedStatus_Then_SelectedStatus(Alerts selectedAlert)
{
var filterModel = new ApprenticesFilterModel
{
SelectedAlert = selectedAlert
};

filterModel.FiltersUsedMessage.Value.Should().Be($"matching <strong>{selectedAlert.GetDescription()}</strong>");
}


[Test, AutoData]
public void And_Search_And_SelectedProvider_Then_SearchTerm_And_SelectedProvider(
string searchTerm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public void Then_Adds_PageLink_For_Every_Page()
SelectedProvider = "asdsad",
SelectedCourse = "iknjso",
SelectedStatus = ApprenticeshipStatus.WaitingToStart,
SelectedAlert = Alerts.ChangesForReview,
SelectedEndDate = DateTime.Today,
TotalNumberOfApprenticeshipsFound = Constants.ApprenticesSearch.NumberOfApprenticesPerSearchPage * 3,
SortField = "gsd",
Expand All @@ -39,6 +40,7 @@ public void Then_Adds_PageLink_For_Every_Page()
{nameof(filterModel.SelectedProvider), filterModel.SelectedProvider},
{nameof(filterModel.SelectedCourse), filterModel.SelectedCourse},
{nameof(filterModel.SelectedStatus), filterModel.SelectedStatus.ToString()},
{nameof(filterModel.SelectedAlert), filterModel.SelectedAlert.ToString()},
{nameof(filterModel.SelectedEndDate), filterModel.SelectedEndDate.Value.ToString("yyyy-MM-dd")},
{nameof(filterModel.SortField), filterModel.SortField},
{nameof(filterModel.ReverseSort), filterModel.ReverseSort.ToString()},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public void Then_Contains_Item_For_Each_Search_And_Filter_Value(
{nameof(filterModel.SelectedProvider), filterModel.SelectedProvider},
{nameof(filterModel.SelectedCourse), filterModel.SelectedCourse},
{nameof(filterModel.SelectedStatus), filterModel.SelectedStatus.ToString()},
{nameof(filterModel.SelectedAlert), filterModel.SelectedAlert.ToString()},
{nameof(filterModel.SelectedEndDate), filterModel.SelectedEndDate.Value.ToString("yyyy-MM-dd")}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,25 @@ public void And_Has_SelectedEndDate_Then_True()
filterModel.SearchOrFiltersApplied.Should().BeTrue();
}

[Test]
public void And_Has_SelectedAlert_Then_True()
{
var filterModel = new ApprenticesFilterModel
{
SelectedAlert = Alerts.IlrDataMismatch
};

filterModel.SearchOrFiltersApplied.Should().BeTrue();
}

[Test]
public void And_No_Search_Or_Filter_Then_False()
{
var filterModel = new ApprenticesFilterModel();

filterModel.SearchOrFiltersApplied.Should().BeFalse();
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Client" Version="7.35.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Shared" Version="7.35.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Types" Version="7.35.0" />
<PackageReference Include="SFA.DAS.Testing" Version="3.0.22" />
<PackageReference Include="SFA.DAS.Testing.AutoFixture" Version="3.0.121" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ private static IList<string> BuildUsedFilterList(ApprenticesFilterModel model)
filters.Add(model.SelectedEndDate.Value.ToGdsFormatWithoutDay());
}

if (model.SelectedAlert.HasValue)
{
filters.Add(model.SelectedAlert.Value.GetDescription());
}

return filters;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public async Task<DownloadViewModel> Map(DownloadRequest request)
CourseName = request.SelectedCourse,
Status = request.SelectedStatus,
EndDate = request.SelectedEndDate,
Alert = request.SelectedAlert,
PageNumber = 0
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public async Task<IndexViewModel> Map(IndexRequest source)
ProviderName = source.SelectedProvider,
CourseName = source.SelectedCourse,
Status = source.SelectedStatus,
EndDate = source.SelectedEndDate
EndDate = source.SelectedEndDate,
Alert = source.SelectedAlert
});

var statusFilters = new[]
Expand All @@ -52,6 +53,13 @@ public async Task<IndexViewModel> Map(IndexRequest source)
ApprenticeshipStatus.Completed
};

var alertFilters = new[]
{
Alerts.ChangesForReview ,
Alerts.ChangesPending,
Alerts.ChangesRequested
};

var filterModel = new ApprenticesFilterModel
{
TotalNumberOfApprenticeships = response.TotalApprenticeships,
Expand All @@ -64,8 +72,10 @@ public async Task<IndexViewModel> Map(IndexRequest source)
SelectedProvider = source.SelectedProvider,
SelectedCourse = source.SelectedCourse,
SelectedStatus = source.SelectedStatus,
SelectedAlert = source.SelectedAlert,
SelectedEndDate = source.SelectedEndDate,
StatusFilters = statusFilters
StatusFilters = statusFilters,
AlertFilters = alertFilters
};

if (response.TotalApprenticeships >= Constants.ApprenticesSearch.NumberOfApprenticesRequiredForSearch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ public class ApprenticesFilterModel
public string SelectedCourse { get; set; }
public ApprenticeshipStatus? SelectedStatus { get; set; }
public DateTime? SelectedEndDate { get; set; }
public Alerts? SelectedAlert { get; set; }
public string SortField { get; set; }
public bool ReverseSort { get; set; }

public IEnumerable<string> ProviderFilters { get; set; } = new List<string>();
public IEnumerable<string> CourseFilters { get; set; } = new List<string>();
public IEnumerable<ApprenticeshipStatus> StatusFilters { get; set; } = new List<ApprenticeshipStatus>();
public IEnumerable<DateTime> EndDateFilters { get; set; } = new List<DateTime>();
public IEnumerable<Alerts> AlertFilters { get; set; } = new List<Alerts>();

private const int PageSize = Constants.ApprenticesSearch.NumberOfApprenticesPerSearchPage;
public int PagedRecordsFrom => TotalNumberOfApprenticeshipsFound == 0 ? 0 : (PageNumber - 1) * PageSize + 1;
Expand All @@ -37,7 +39,8 @@ public int PagedRecordsTo {
|| !string.IsNullOrWhiteSpace(SelectedProvider)
|| !string.IsNullOrWhiteSpace(SelectedCourse)
|| SelectedStatus.HasValue
|| SelectedEndDate.HasValue;
|| SelectedEndDate.HasValue
|| SelectedAlert.HasValue;

public HtmlString FiltersUsedMessage => this.GetFiltersUsedMessage();

Expand Down Expand Up @@ -131,6 +134,11 @@ private Dictionary<string, string> BuildRouteData()
routeData.Add(nameof(SelectedEndDate), SelectedEndDate.Value.ToString("yyyy-MM-dd"));
}

if (SelectedAlert.HasValue)
{
routeData.Add(nameof(SelectedAlert), SelectedAlert.Value.ToString());
}

return routeData;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class DownloadRequest
public string SelectedProvider { get; set; }
public string SelectedCourse { get; set; }
public ApprenticeshipStatus? SelectedStatus { get; set; }
public Alerts? SelectedAlert { get; set; }
public DateTime? SelectedEndDate { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ public int PageNumber
public DateTime? SelectedEndDate { get; set; }
public ApprenticeshipStatus? SelectedStatus { get; set; }
public bool FromSearch { get; set; }
public Alerts? SelectedAlert { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ else
</select>
</div>
</div>
</div><div class="govuk-grid-row">
</div>
<div class="govuk-grid-row">
<div class="govuk-grid-column-one-third">
<div class="govuk-form-group">
<label class="govuk-label" for="selectedStatus">Status</label>
Expand All @@ -117,6 +118,29 @@ else
</select>
</div>
</div>
<div class="govuk-grid-column-one-third">
<div class="govuk-form-group">
<label class="govuk-label" for="selectedStatus">Alerts</label>
<select class="govuk-select govuk-!-width-full" id="selectedAlert" name="selectedAlert">
<option label="All" aria-label="All statuses" value="">All</option>
@foreach (var alert in Model.FilterModel.AlertFilters)
{
if (alert == Model.FilterModel.SelectedAlert)
{
<option label="@alert.GetDescription()" value="@alert" selected="selected">@alert.GetDescription()</option>
}
else
{
<option label="@alert.GetDescription()" value="@alert">@alert.GetDescription()</option>
}
}
</select>
</div>
</div>




</div>
<button class="govuk-button govuk-!-margin-0" type="submit">Apply filters</button>
</div>
Expand Down

0 comments on commit b4eb1cc

Please sign in to comment.