Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ScarletKuro committed May 6, 2024
1 parent a6b5027 commit eec9dfa
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
@namespace MudBlazor.UnitTests.TestComponents
<MudPopoverProvider></MudPopoverProvider>
<MudPopoverProvider/>

<MudDateRangePicker id="picker" @ref="_picker" Label="With action buttons" @bind-DateRange="DateRange">
<PickerActions>
<MudButton Class="mr-auto align-self-start" OnClick="@(() => _picker.Clear(@CloseOnClear))">Clear</MudButton>
<MudButton Class="mr-auto align-self-start" OnClick="@(() => _picker.ClearAsync(CloseOnClear))">Clear</MudButton>
</PickerActions>
</MudDateRangePicker>

@code {
MudDateRangePicker _picker;
[Parameter] public DateRange DateRange { get; set; }
[Parameter] public bool CloseOnClear { get; set; }
private MudDateRangePicker _picker;

[Parameter]
public DateRange DateRange { get; set; }

[Parameter]
public bool CloseOnClear { get; set; }
}
36 changes: 36 additions & 0 deletions src/MudBlazor.UnitTests/Components/DateRangePickerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -838,5 +838,41 @@ public void FormatLast_Should_RenderCorrectly()
comp.Markup.Should().Contain("2024 April 22");
comp.Markup.Should().Contain("2024 April 23");
}

[Test]
[TestCase(false)]
[TestCase(true)]
public void CheckCloseOnClearDateRangePicker(bool closeOnClear)
{
// Define a date range for comparison
var initialDateRange = new DateRange(
new DateTime(DateTime.Now.Year, DateTime.Now.Month, 01),
new DateTime(DateTime.Now.Year, DateTime.Now.Month, 02));

// Get access to the date range picker of the instance
var comp = Context.RenderComponent<DateRangePickerCloseOnClearTest>(
Parameter(nameof(DateRangePickerCloseOnClearTest.DateRange), initialDateRange),
Parameter(nameof(DateRangePickerCloseOnClearTest.CloseOnClear), closeOnClear));

// Open the date range picker
comp.Find("input").Click();

// Clicking day buttons to select a date range
comp
.FindAll("button.mud-button").First(x => x.TrimmedText().Equals("Clear")).Click();

// Check that the date range was cleared
comp.Instance.DateRange.Should().NotBe(initialDateRange);
if (closeOnClear)
{
// Check that the component is closed
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open"));
}
else
{
// Check that the component is open
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().Contain("mud-popover-open"));
}
}
}
}

0 comments on commit eec9dfa

Please sign in to comment.