Skip to content

Commit ecbafb0

Browse files
committed
Fixed reset of filter
1 parent c268d0c commit ecbafb0

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

LinkDotNet.Blog.UnitTests/Web/Shared/Admin/Dashboard/DateRangeSelectorTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,22 @@ public void ShouldSetEndDateWhenSet()
3939
filter.EndDate.Should().Be(new DateTime(2020, 1, 1));
4040
filter.StartDate.Should().BeNull();
4141
}
42+
43+
[Fact]
44+
public void ShouldReset()
45+
{
46+
Filter filter = null;
47+
var cut = RenderComponent<DateRangeSelector>(p => p.Add(s => s.FilterChanged, f =>
48+
{
49+
filter = f;
50+
}));
51+
cut.Find("#startDate").Change(new DateTime(2020, 1, 1));
52+
cut.Find("#endDate").Change(new DateTime(2020, 1, 1));
53+
54+
cut.Find("#startDate").Change(string.Empty);
55+
cut.Find("#endDate").Change(string.Empty);
56+
57+
filter.StartDate.Should().BeNull();
58+
filter.EndDate.Should().BeNull();
59+
}
4260
}

LinkDotNet.Blog.Web/Shared/Admin/Dashboard/DateRangeSelector.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121

2222
private async Task StartDateChanged(ChangeEventArgs args)
2323
{
24-
filter.StartDate = args.Value is string dateTime ? DateTime.Parse(dateTime) : null;
24+
filter.StartDate = args.Value is string { Length: >0 } dateTime ? DateTime.Parse(dateTime) : null;
2525
await ApplyFilters();
2626
}
2727

2828
private async Task EndDateChanged(ChangeEventArgs args)
2929
{
30-
filter.EndDate = args.Value is string dateTime ? DateTime.Parse(dateTime) : null;
30+
filter.EndDate = args.Value is string { Length: >0 } dateTime ? DateTime.Parse(dateTime) : null;
3131
await ApplyFilters();
3232
}
3333
}

0 commit comments

Comments
 (0)