This repository has been archived by the owner on Apr 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
450183d
commit bb09828
Showing
8 changed files
with
95 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<MudText Typo=Typo.h6 Color=_color Align=Align.Center> | ||
@_remainingTime | ||
</MudText> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Humanizer; | ||
using Humanizer.Localisation; | ||
using Microsoft.AspNetCore.Components; | ||
using MudBlazor; | ||
using System.Timers; | ||
using Timer = System.Timers.Timer; | ||
|
||
namespace DynamoLeagueBlazor.Client.Features.FreeAgents; | ||
|
||
public partial class BidCountdown | ||
{ | ||
[Parameter, EditorRequired] public DateTime DateTime { get; set; } | ||
|
||
private readonly Timer _timer = new(1000); | ||
private string _remainingTime = string.Empty; | ||
private Color _color = Color.Warning; | ||
|
||
protected override void OnInitialized() | ||
{ | ||
_timer.Elapsed += CountDown; | ||
_timer.Enabled = true; | ||
} | ||
|
||
private void CountDown(object? source, ElapsedEventArgs e) | ||
{ | ||
var remainingTime = DateTime - DateTime.Now; | ||
|
||
if (remainingTime <= TimeSpan.FromDays(1)) | ||
{ | ||
_color = Color.Error; | ||
|
||
if (remainingTime <= TimeSpan.Zero) | ||
{ | ||
_timer.Enabled = false; | ||
remainingTime = TimeSpan.Zero; | ||
} | ||
} | ||
|
||
_remainingTime = remainingTime.Humanize(4, maxUnit: TimeUnit.Day, minUnit: TimeUnit.Second); | ||
|
||
InvokeAsync(StateHasChanged); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using DynamoLeagueBlazor.Client.Features.FreeAgents; | ||
|
||
namespace DynamoLeagueBlazor.Tests.Features.FreeAgents; | ||
|
||
public class BidCountdownTests : UITestBase | ||
{ | ||
[Fact] | ||
public void CountsDownEverySecondUntilZero() | ||
{ | ||
var cut = RenderComponent<BidCountdown>(parameters => | ||
{ | ||
parameters.Add(p => p.DateTime, DateTime.Now.AddSeconds(4)); | ||
}); | ||
|
||
cut.WaitForState(() => cut.Markup.Contains("1 second"), TimeSpan.FromSeconds(4)); | ||
cut.WaitForState(() => cut.Markup.Contains("0 seconds")); | ||
|
||
cut.Render(); | ||
cut.Markup.Should().Contain("0 seconds"); | ||
} | ||
|
||
[Fact] | ||
public void GivenLessThanADayAway_ThenShowsRedText() | ||
{ | ||
var cut = RenderComponent<BidCountdown>(parameters => | ||
{ | ||
parameters.Add(p => p.DateTime, DateTime.Now.AddSeconds(1)); | ||
}); | ||
|
||
cut.Markup.Contains("mud-text-error"); | ||
} | ||
|
||
[Fact] | ||
public void GivenMoreThanADayAway_ThenShowsYellowText() | ||
{ | ||
var cut = RenderComponent<BidCountdown>(parameters => | ||
{ | ||
parameters.Add(p => p.DateTime, DateTime.Now.AddDays(1)); | ||
}); | ||
|
||
cut.Markup.Contains("mud-text-warning"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters