Skip to content

Commit

Permalink
sort by day of week, name, deal
Browse files Browse the repository at this point in the history
  • Loading branch information
eebbesen committed Nov 2, 2024
1 parent a5ebea2 commit da1d91c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 229 deletions.
5 changes: 4 additions & 1 deletion StpFoodBlazor/StpFoodBlazor/Helpers/DealSorter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
6 changes: 3 additions & 3 deletions StpFoodBlazor/StpFoodBlazorTest/Helpers/DealFilterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void ShouldReturnInputWhenNoFilterConditions() {

DealEvent[] filteredDeals = filter.Filter();

Assert.Equal(324, dealsLength);
Assert.Equal(299, dealsLength);
Assert.Equal(dealsLength, filteredDeals.Length);
}

Expand Down Expand Up @@ -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));
});
Expand All @@ -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)));
}
Expand Down
14 changes: 14 additions & 0 deletions StpFoodBlazor/StpFoodBlazorTest/Pages/DealsTest.razor
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@
}
}

[Fact]
public void DealsShouldSortByDay()
{
var cut = ctx.Render(@<Deals />);
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));
Expand Down
225 changes: 0 additions & 225 deletions StpFoodBlazor/StpFoodBlazorTest/fixtures/deals.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]

0 comments on commit da1d91c

Please sign in to comment.