From d2a47ca37a5b7b3a088919476c75002b682efaf6 Mon Sep 17 00:00:00 2001 From: eebbesen Date: Tue, 17 Dec 2024 20:36:12 -0600 Subject: [PATCH 1/5] placeholders for deals --- .../Layout/DealTableBodyPlaceholder.razor | 24 +++++++++++++++++++ .../Components/Pages/Deals.razor | 18 ++++++-------- .../StpFoodBlazorTest/Pages/DealsTest.razor | 20 ++++++++++++++++ .../Services/TestDealService.cs | 6 +++++ 4 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 StpFoodBlazor/StpFoodBlazor/Components/Layout/DealTableBodyPlaceholder.razor diff --git a/StpFoodBlazor/StpFoodBlazor/Components/Layout/DealTableBodyPlaceholder.razor b/StpFoodBlazor/StpFoodBlazor/Components/Layout/DealTableBodyPlaceholder.razor new file mode 100644 index 0000000..4d29058 --- /dev/null +++ b/StpFoodBlazor/StpFoodBlazor/Components/Layout/DealTableBodyPlaceholder.razor @@ -0,0 +1,24 @@ +@inherits LayoutComponentBase +@using StpFoodBlazor.Models + + + +@code +{ + [Parameter] + public string selectedDayOfWeek { get; set; } +} diff --git a/StpFoodBlazor/StpFoodBlazor/Components/Pages/Deals.razor b/StpFoodBlazor/StpFoodBlazor/Components/Pages/Deals.razor index e3c2cd9..9f71672 100644 --- a/StpFoodBlazor/StpFoodBlazor/Components/Pages/Deals.razor +++ b/StpFoodBlazor/StpFoodBlazor/Components/Pages/Deals.razor @@ -11,24 +11,20 @@ @attribute [StreamRendering] Deals +
+ -
+ @if (deals == null) { -
-

Loading...

-
+ } else { - - - - - + } -
+
@code { private DealEvent[]? deals; diff --git a/StpFoodBlazor/StpFoodBlazorTest/Pages/DealsTest.razor b/StpFoodBlazor/StpFoodBlazorTest/Pages/DealsTest.razor index 08339f8..7452ec0 100644 --- a/StpFoodBlazor/StpFoodBlazorTest/Pages/DealsTest.razor +++ b/StpFoodBlazor/StpFoodBlazorTest/Pages/DealsTest.razor @@ -18,6 +18,25 @@ ctx.Services.AddSingleton(timeService); } + [Fact] + public void DealsShouldDisplayPlaceholderWhenLoading() + { + timeService.DayOfWeek = DayOfWeek.Wednesday.ToString(); + TestDealService testDealService = new TestDealService(); + testDealService.LongRunning = true; + ctx.Services.AddSingleton(testDealService); + + var cut = ctx.Render(@); + cut.WaitForElement("#deals_table_body_placeholder", TimeSpan.FromSeconds(5)); + var elements = cut.Find("#deals_table_body_placeholder"); + + Assert.Equal(30, elements.ChildElementCount); + Assert.Equal("" + + "\n " + + "", + elements.Children[0].InnerHtml); + } + [Fact] public void DealsShouldDisplayTwoColumnsWednesday() { @@ -77,6 +96,7 @@ ctx.Services.AddSingleton(timeService); var cut = ctx.Render(@); var dowSelect = (IHtmlSelectElement)cut.WaitForElement("#day-of-week-select"); + getElements(cut); // just to make sure table is rendered Assert.Equal(DateTime.Today.DayOfWeek.ToString(), dowSelect.Value); } diff --git a/StpFoodBlazor/StpFoodBlazorTest/Services/TestDealService.cs b/StpFoodBlazor/StpFoodBlazorTest/Services/TestDealService.cs index 15ea754..2c3f94b 100644 --- a/StpFoodBlazor/StpFoodBlazorTest/Services/TestDealService.cs +++ b/StpFoodBlazor/StpFoodBlazorTest/Services/TestDealService.cs @@ -11,9 +11,15 @@ namespace StpFoodBlazorTest.Services public class TestDealService : IDealService { private static readonly string DEAL_FIXTURES_PATH = Path.Combine(Directory.GetCurrentDirectory(), "fixtures", "deals.json"); + public Boolean LongRunning { get; set; } = false; public async Task GetDealsAsync() { + if (LongRunning) + { + await Task.Delay(7000); + } + if (File.Exists(DEAL_FIXTURES_PATH)) { string jsonContent = await File.ReadAllTextAsync(DEAL_FIXTURES_PATH); From 7653a2f4a1f64e8bab8efb20c54c752aa4d50da8 Mon Sep 17 00:00:00 2001 From: eebbesen Date: Wed, 18 Dec 2024 17:07:03 -0600 Subject: [PATCH 2/5] better placeholder --- .../Layout/DealTableBodyPlaceholder.razor | 17 +++-------------- .../StpFoodBlazor/Components/Pages/Deals.razor | 3 +-- .../StpFoodBlazorTest/Pages/DealsTest.razor | 4 +--- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/StpFoodBlazor/StpFoodBlazor/Components/Layout/DealTableBodyPlaceholder.razor b/StpFoodBlazor/StpFoodBlazor/Components/Layout/DealTableBodyPlaceholder.razor index 4d29058..182cd62 100644 --- a/StpFoodBlazor/StpFoodBlazor/Components/Layout/DealTableBodyPlaceholder.razor +++ b/StpFoodBlazor/StpFoodBlazor/Components/Layout/DealTableBodyPlaceholder.razor @@ -1,24 +1,13 @@ @inherits LayoutComponentBase @using StpFoodBlazor.Models -