diff --git a/StpFoodBlazor/StpFoodBlazor/Helpers/DealSorter.cs b/StpFoodBlazor/StpFoodBlazor/Helpers/DealSorter.cs index a8a76e2..0295143 100644 --- a/StpFoodBlazor/StpFoodBlazor/Helpers/DealSorter.cs +++ b/StpFoodBlazor/StpFoodBlazor/Helpers/DealSorter.cs @@ -5,7 +5,10 @@ namespace StpFoodBlazor.Helpers public static class DealSorter { public static DealEvent[] Sort(DealEvent[] deals){ - return [.. deals.OrderBy(deal => deal.Name).ThenBy(deal => deal.Deal)]; + return deals.OrderBy(deal => + string.IsNullOrEmpty(deal.Day) ? DayOfWeek.Sunday : Enum.Parse(typeof(DayOfWeek), deal.Day) + ).ThenBy(deal => deal.Name). + ThenBy(deal => deal.Deal).ToArray(); } } } diff --git a/StpFoodBlazor/StpFoodBlazorTest/Helpers/DealFilterTest.cs b/StpFoodBlazor/StpFoodBlazorTest/Helpers/DealFilterTest.cs index 96632e0..a9296d3 100644 --- a/StpFoodBlazor/StpFoodBlazorTest/Helpers/DealFilterTest.cs +++ b/StpFoodBlazor/StpFoodBlazorTest/Helpers/DealFilterTest.cs @@ -28,7 +28,7 @@ public void ShouldReturnInputWhenNoFilterConditions() { DealEvent[] filteredDeals = filter.Filter(); - Assert.Equal(324, dealsLength); + Assert.Equal(299, dealsLength); Assert.Equal(dealsLength, filteredDeals.Length); } @@ -88,7 +88,7 @@ public void ShouldReturnFilteredByAlcoholFalse() { DealEvent[] filteredDeals = filter.Filter(); - Assert.Equal(215, filteredDeals.Length); + Assert.Equal(190, filteredDeals.Length); Array.ForEach(filteredDeals, deal => { Assert.True(string.IsNullOrEmpty(deal.Alcohol)); }); @@ -110,7 +110,7 @@ public void ShouldReturnFilteredByHappyHourFalse() { DealEvent[] filteredDeals = filter.Filter(); - Assert.Equal(133, filteredDeals.Length); + Assert.Equal(108, filteredDeals.Length); Array.ForEach(filteredDeals, deal => Assert.True(string.IsNullOrWhiteSpace(deal.HappyHour))); } diff --git a/StpFoodBlazor/StpFoodBlazorTest/Pages/DealsTest.razor b/StpFoodBlazor/StpFoodBlazorTest/Pages/DealsTest.razor index 5e976c3..278010a 100644 --- a/StpFoodBlazor/StpFoodBlazorTest/Pages/DealsTest.razor +++ b/StpFoodBlazor/StpFoodBlazorTest/Pages/DealsTest.razor @@ -98,6 +98,20 @@ } } + [Fact] + public void DealsShouldSortByDay() + { + var cut = ctx.Render(@); + var dowSelect = (IHtmlSelectElement)cut.WaitForElement("#day-of-week-select"); + + dowSelect.Change(""); // All value in the select is "" + + var elements = getElements(cut); + Assert.Equal(299, elements.ChildElementCount); + Assert.Equal("Sunday", elements.Children[0].Children[0].InnerHtml); + Assert.Equal("Saturday", elements.Children[298].Children[0].InnerHtml); + } + private IElement getElements(IRenderedFragment cut) { cut.WaitForElement("#deals_table_body", TimeSpan.FromSeconds(5)); diff --git a/StpFoodBlazor/StpFoodBlazorTest/fixtures/deals.json b/StpFoodBlazor/StpFoodBlazorTest/fixtures/deals.json index fb1d7f6..0bbf1bd 100644 --- a/StpFoodBlazor/StpFoodBlazorTest/fixtures/deals.json +++ b/StpFoodBlazor/StpFoodBlazorTest/fixtures/deals.json @@ -2689,230 +2689,5 @@ "Address": "444 Cedar St Ste 201 Ste 201, St Paul, MN 55101", "Happy Hour": null, "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null - }, - { - "PlaceID": "", - "Day": "", - "Name": "#VALUE!", - "Deal": "", - "Address": "#VALUE!", - "Happy Hour": null, - "Alcohol": null } ]