Skip to content

Commit

Permalink
Fix Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mckaragoz committed Oct 24, 2023
1 parent c4c458a commit e7d6a3d
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions CodeBeam.MudBlazor.Extensions.UnitTests/Components/ComboboxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,41 +342,50 @@ public async Task ComboBoxTest_KeyboardNavigation_SingleSelect()
var combobox = comp.FindComponent<MudComboBox<string>>().Instance;

await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
comp.Render();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("d-none"));

await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "Escape", Type = "keydown", }));
comp.Render();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().Contain("d-none"));

await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = " ", Type = "keydown", }));
comp.Render();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("d-none"));
//If we didn't select an item with mouse or arrow keys yet, value should remains null.
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = " ", Type = "keydown", }));
comp.Render();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().Contain("d-none"));
comp.WaitForAssertion(() => combobox.Value.Should().Be(null));

await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "ArrowDown", AltKey = true, Type = "keydown", }));
comp.Render();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("d-none"));

await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "ArrowUp", AltKey = true, Type = "keydown", }));
comp.Render();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().Contain("d-none"));
//If dropdown is closed, arrow key should not set a value.
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "ArrowDown", Type = "keydown", }));
comp.Render();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("d-none"));
comp.WaitForAssertion(() => combobox.Value.Should().Be(null));
// If no item is hiligted, enter should only close popover, not select any item and value
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "Escape", Type = "keydown", }));
comp.Render();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().Contain("d-none"));
comp.WaitForAssertion(() => combobox.Value.Should().Be(null));

await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
comp.Render();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("d-none"));

await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "ArrowDown", Type = "keydown", }));
comp.WaitForAssertion(() => combobox.Value.Should().BeNull());

await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "ArrowDown", Type = "keydown", }));
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
comp.WaitForAssertion(() => combobox.Value.Should().Be("2"));
comp.WaitForAssertion(() => combobox.Value.Should().Be("3"));
//End key should not select the last disabled item
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "End", Type = "keydown", }));
Expand All @@ -387,13 +396,14 @@ public async Task ComboBoxTest_KeyboardNavigation_SingleSelect()
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().Contain("mud-popover-open"));
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "ArrowDown", Type = "keydown", }));
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
comp.Render();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().Contain("d-none"));
comp.WaitForAssertion(() => combobox.Value.Should().Be("3"));
comp.WaitForAssertion(() => combobox.Value.Should().Be("1"));

await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "ArrowDown", Type = "keydown", }));
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
comp.WaitForAssertion(() => combobox.Value.Should().Be("3"));
comp.WaitForAssertion(() => combobox.Value.Should().Be("2"));

await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "Home", Type = "keydown", }));
Expand All @@ -403,17 +413,17 @@ public async Task ComboBoxTest_KeyboardNavigation_SingleSelect()
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "ArrowUp", Type = "keydown", }));
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
comp.WaitForAssertion(() => combobox.Value.Should().Be("1"));
comp.WaitForAssertion(() => combobox.Value.Should().Be("3"));

await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "End", Type = "keydown", }));
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "ArrowDown", Type = "keydown", }));
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
comp.WaitForAssertion(() => combobox.Value.Should().Be("3"));
comp.WaitForAssertion(() => combobox.Value.Should().Be("1"));

await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "2", Type = "keydown", }));
comp.WaitForAssertion(() => combobox.Value.Should().Be("3"));
comp.WaitForAssertion(() => combobox.Value.Should().Be("1"));

await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
comp.WaitForAssertion(() => combobox.Value.Should().Be("2"));
Expand All @@ -426,14 +436,15 @@ public async Task ComboBoxTest_KeyboardNavigation_ToggleSelect()
var combobox = comp.FindComponent<MudComboBox<string>>().Instance;
combobox.ToggleSelection = true;
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
comp.Render();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("d-none"));

await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "ArrowDown", Type = "keydown", }));
comp.WaitForAssertion(() => combobox.Value.Should().BeNull());

await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "ArrowDown", Type = "keydown", }));
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
comp.WaitForAssertion(() => combobox.Value.Should().Be("2"));
comp.WaitForAssertion(() => combobox.Value.Should().Be("3"));
//End key should not select the last disabled item
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
await comp.InvokeAsync(() => combobox.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
Expand All @@ -445,8 +456,10 @@ public async Task ComboBoxTest_KeyboardNavigation_MultiSelect()
{
var comp = Context.RenderComponent<ComboBoxMultiSelectTest3>();
var combobox = comp.FindComponent<MudComboBox<string>>();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().Contain("d-none"));

await comp.InvokeAsync(() => combobox.Instance.HandleKeyDown(new KeyboardEventArgs() { Key = " ", Type = "keydown", }));
comp.Render();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("d-none"));

await comp.InvokeAsync(() => combobox.Instance.HandleKeyDown(new KeyboardEventArgs() { Key = "a", CtrlKey = true, Type = "keydown", }));
Expand All @@ -463,35 +476,37 @@ public async Task ComboBoxTest_KeyboardNavigation_MultiSelect()
comp.WaitForAssertion(() => combobox.Instance.GetPresenterText().Should().Be("7 felines have been selected"));

await comp.InvokeAsync(() => combobox.Instance.HandleKeyDown(new KeyboardEventArgs() { Key = "Escape", Type = "keydown", }));
comp.Render();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().Contain("d-none"));

await comp.InvokeAsync(() => combobox.Instance.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
comp.Render();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("d-none"));

await comp.InvokeAsync(() => combobox.Instance.HandleKeyDown(new KeyboardEventArgs() { Key = "ArrowDown", Type = "keydown", }));
await comp.InvokeAsync(() => combobox.Instance.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
comp.WaitForAssertion(() => combobox.Instance.SelectedValues.Should().NotContain("Tiger"));
comp.WaitForAssertion(() => combobox.Instance.SelectedValues.Should().NotContain("Jaguar"));

await comp.InvokeAsync(() => combobox.Instance.HandleKeyDown(new KeyboardEventArgs() { Key = "Home", Type = "keydown", }));
await comp.InvokeAsync(() => combobox.Instance.HandleKeyDown(new KeyboardEventArgs() { Key = "NumpadEnter", Type = "keydown", }));
comp.WaitForAssertion(() => combobox.Instance.SelectedValues.Should().NotContain("Jaguar"));
comp.WaitForAssertion(() => combobox.Instance.SelectedValues.Should().Contain("Jaguar"));

await comp.InvokeAsync(() => combobox.Instance.HandleKeyDown(new KeyboardEventArgs() { Key = "ArrowDown", Type = "keydown", }));
await comp.InvokeAsync(() => combobox.Instance.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
comp.WaitForAssertion(() => combobox.Instance.SelectedValues.Should().NotContain("Leopard"));

await comp.InvokeAsync(() => combobox.Instance.HandleKeyDown(new KeyboardEventArgs() { Key = "End", Type = "keydown", }));
await comp.InvokeAsync(() => combobox.Instance.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
comp.WaitForAssertion(() => combobox.Instance.SelectedValues.Should().Contain("Tiger"));
comp.WaitForAssertion(() => combobox.Instance.SelectedValues.Should().NotContain("Tiger"));

combobox.SetParam("Disabled", true);
await comp.InvokeAsync(() => combobox.Instance.HandleKeyDown(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
comp.WaitForAssertion(() => combobox.Instance.SelectedValues.Should().Contain("Tiger"));
comp.WaitForAssertion(() => combobox.Instance.SelectedValues.Should().NotContain("Tiger"));

combobox.SetParam("Disabled", false);
//Test the keyup event
await comp.InvokeAsync(() => combobox.Instance.HandleKeyUp(new KeyboardEventArgs() { Key = "Enter", Type = "keyup", }));
comp.WaitForAssertion(() => combobox.Instance.SelectedValues.Should().Contain("Tiger"));
comp.WaitForAssertion(() => combobox.Instance.SelectedValues.Should().NotContain("Tiger"));

await comp.InvokeAsync(() => combobox.Instance.HandleKeyDown(new KeyboardEventArgs() { Key = "Tab", Type = "keydown", }));
await comp.InvokeAsync(() => combobox.Instance.OnKeyUp.InvokeAsync(new KeyboardEventArgs() { Key = "Tab" }));
Expand Down

0 comments on commit e7d6a3d

Please sign in to comment.