Skip to content

Commit

Permalink
Tests: Improve DebouncedTextFieldFormatChangeRerenderTest
Browse files Browse the repository at this point in the history
  • Loading branch information
henon committed Sep 13, 2023
1 parent cbae83f commit d9f8ee5
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/MudBlazor.UnitTests/Components/TextFieldTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -978,21 +978,19 @@ public async Task DebouncedTextFieldFormatChangeRerenderTest()
{
var comp = Context.RenderComponent<DebouncedTextFieldFormatChangeRerenderTest>();
var textField = comp.FindComponent<MudTextField<DateTime>>().Instance;
var input = comp.Find("input");
var delayedFormatChangeButton = comp.Find("button");
DateTime expectedFinalDateTime = default;
// ensure text is updated on initialize
textField.Text.Should().Be(comp.Instance.Date.Date.ToString(comp.Instance.Format, CultureInfo.InvariantCulture));
// trigger the format change
delayedFormatChangeButton.Click();
comp.Find("button").Click();
// imitate "typing in progress" by extending the debounce interval until component re-renders
var elapsedTime = 0;
var currentText = comp.Instance.Date.Date.ToString(comp.Instance.Format, CultureInfo.InvariantCulture);
while (elapsedTime < comp.Instance.RerenderDelay)
{
var delay = comp.Instance.DebounceInterval / 2;
currentText += "a";
input.Input(new ChangeEventArgs { Value = currentText });
comp.Find("input").Input(new ChangeEventArgs { Value = currentText });
await Task.Delay(delay);
elapsedTime += delay;
}
Expand Down

0 comments on commit d9f8ee5

Please sign in to comment.