Skip to content

Commit

Permalink
placeholders for deals
Browse files Browse the repository at this point in the history
  • Loading branch information
eebbesen committed Dec 18, 2024
1 parent 984a66b commit d2a47ca
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@inherits LayoutComponentBase
@using StpFoodBlazor.Models

<span id="deals_table_body_placeholder" class="placeholder-glow" aria-hidden="true">
@{var rowCounter = 0;}
@foreach (var deal in Enumerable.Range(1, 30))
{
<div class="row rounded@(rowCounter % 2 == 0 ? " bg-secondary opacity-25" : "")">
@if (string.IsNullOrEmpty(selectedDayOfWeek))
{
<span class="col-1 placeholder"></span>
}
<span class="col-3 placeholder"></span>
<span class="col placeholder"></span>
</div>
rowCounter++;
}
</span>

@code
{
[Parameter]
public string selectedDayOfWeek { get; set; }
}
18 changes: 7 additions & 11 deletions StpFoodBlazor/StpFoodBlazor/Components/Pages/Deals.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,20 @@
@attribute [StreamRendering]

<PageTitle>Deals</PageTitle>
<div class="container mb-5">
<DealFilterBar selectedDayOfWeek="@selectedDayOfWeek" OnSelectedDayChanged="OnSelectedDayChanged"
happyHour="@happyHour" OnHappyHourChanged="OnHappyHourChanged" />

<div class="container mb-5">
<DealTableHeader selectedDayOfWeek="@selectedDayOfWeek" />
@if (deals == null)
{
<div class="row">
<p><em>Loading...</em></p>
</div>
<DealTableBodyPlaceholder selectedDayOfWeek="@selectedDayOfWeek" />
}
else
{
<DealFilterBar selectedDayOfWeek="@selectedDayOfWeek" OnSelectedDayChanged="OnSelectedDayChanged"
happyHour="@happyHour" OnHappyHourChanged="OnHappyHourChanged" />

<DealTableHeader selectedDayOfWeek="@selectedDayOfWeek" />

<DealTableBody deals="@deals" selectedDayOfWeek="@selectedDayOfWeek" />
<DealTableBody deals="@deals" selectedDayOfWeek="@selectedDayOfWeek" />
}
</div>
</div>

@code {
private DealEvent[]? deals;
Expand Down
20 changes: 20 additions & 0 deletions StpFoodBlazor/StpFoodBlazorTest/Pages/DealsTest.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@
ctx.Services.AddSingleton<ITimeService>(timeService);
}

[Fact]
public void DealsShouldDisplayPlaceholderWhenLoading()
{
timeService.DayOfWeek = DayOfWeek.Wednesday.ToString();
TestDealService testDealService = new TestDealService();
testDealService.LongRunning = true;
ctx.Services.AddSingleton<IDealService>(testDealService);

var cut = ctx.Render(@<Deals />);
cut.WaitForElement("#deals_table_body_placeholder", TimeSpan.FromSeconds(5));
var elements = cut.Find("#deals_table_body_placeholder");

Assert.Equal(30, elements.ChildElementCount);
Assert.Equal("<span class=\"col-1 placeholder\"></span>" +
"<span class=\"col-3 placeholder\"></span>\n " +
"<span class=\"col placeholder\"></span>",
elements.Children[0].InnerHtml);
}

[Fact]
public void DealsShouldDisplayTwoColumnsWednesday()
{
Expand Down Expand Up @@ -77,6 +96,7 @@
ctx.Services.AddSingleton<ITimeService>(timeService);
var cut = ctx.Render(@<Deals />);
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);
}
Expand Down
6 changes: 6 additions & 0 deletions StpFoodBlazor/StpFoodBlazorTest/Services/TestDealService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DealEvent[]> GetDealsAsync()
{
if (LongRunning)
{
await Task.Delay(7000);
}

if (File.Exists(DEAL_FIXTURES_PATH))
{
string jsonContent = await File.ReadAllTextAsync(DEAL_FIXTURES_PATH);
Expand Down

0 comments on commit d2a47ca

Please sign in to comment.