From d026a3748d74d58ccdd1c51931bab8ebccb9998a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 08:27:57 +0000 Subject: [PATCH 1/3] Initial plan From 8a29db2ae519d030e46d80f8a0d97c31e90736c8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 08:31:01 +0000 Subject: [PATCH 2/3] Add BitSelectField behavior tests with type conversion support Co-authored-by: albx <5121303+albx@users.noreply.github.com> --- .../BitSelectFieldTest.Behaviors.cs | 237 ++++++++++++++++++ 1 file changed, 237 insertions(+) create mode 100644 tests/BitBlazor.Test/Form/SelectField/BitSelectFieldTest.Behaviors.cs diff --git a/tests/BitBlazor.Test/Form/SelectField/BitSelectFieldTest.Behaviors.cs b/tests/BitBlazor.Test/Form/SelectField/BitSelectFieldTest.Behaviors.cs new file mode 100644 index 0000000..8147be9 --- /dev/null +++ b/tests/BitBlazor.Test/Form/SelectField/BitSelectFieldTest.Behaviors.cs @@ -0,0 +1,237 @@ +using BitBlazor.Form; +using Bunit; + +namespace BitBlazor.Test.Form.SelectField; + +public class BitSelectFieldTest +{ + enum TestEnum + { + Option1, + Option2, + Option3 + } + + [Fact] + public void BitSelectField_Should_Change_String_Value_Correctly() + { + string? value = string.Empty; + + using var ctx = new BunitContext(); + + var component = ctx.Render>(parameters => parameters + .Add(p => p.Label, "Select a value") + .Add(p => p.Id, "test-select") + .Bind(p => p.Value, value!, v => value = v) + .AddChildContent>(child => child + .Add(p => p.Value, string.Empty) + .AddChildContent("Choose an option")) + .AddChildContent>(child => child + .Add(p => p.Value, "value1") + .AddChildContent("Value 1")) + .AddChildContent>(child => child + .Add(p => p.Value, "value2") + .AddChildContent("Value 2"))); + + var select = component.Find("select"); + select.Change("value1"); + + Assert.Equal("value1", value); + } + + [Fact] + public void BitSelectField_Should_Change_Int_Value_Correctly() + { + int value = 0; + + using var ctx = new BunitContext(); + + var component = ctx.Render>(parameters => parameters + .Add(p => p.Label, "Select a number") + .Add(p => p.Id, "test-select") + .Bind(p => p.Value, value, v => value = v) + .AddChildContent>(child => child + .Add(p => p.Value, 0) + .AddChildContent("Choose a number")) + .AddChildContent>(child => child + .Add(p => p.Value, 1) + .AddChildContent("One")) + .AddChildContent>(child => child + .Add(p => p.Value, 2) + .AddChildContent("Two")) + .AddChildContent>(child => child + .Add(p => p.Value, 3) + .AddChildContent("Three"))); + + var select = component.Find("select"); + select.Change(2); + + Assert.Equal(2, value); + } + + [Fact] + public void BitSelectField_Should_Change_Enum_Value_Correctly() + { + TestEnum value = TestEnum.Option1; + + using var ctx = new BunitContext(); + + var component = ctx.Render>(parameters => parameters + .Add(p => p.Label, "Select an option") + .Add(p => p.Id, "test-select") + .Bind(p => p.Value, value, v => value = v) + .AddChildContent>(child => child + .Add(p => p.Value, TestEnum.Option1) + .AddChildContent("Option 1")) + .AddChildContent>(child => child + .Add(p => p.Value, TestEnum.Option2) + .AddChildContent("Option 2")) + .AddChildContent>(child => child + .Add(p => p.Value, TestEnum.Option3) + .AddChildContent("Option 3"))); + + var select = component.Find("select"); + select.Change(TestEnum.Option3); + + Assert.Equal(TestEnum.Option3, value); + } + + [Fact] + public void BitSelectField_Should_Update_Bound_Value_When_Selection_Changes() + { + string? value = "initial"; + + using var ctx = new BunitContext(); + + var component = ctx.Render>(parameters => parameters + .Add(p => p.Label, "Select a value") + .Add(p => p.Id, "test-select") + .Bind(p => p.Value, value!, v => value = v) + .AddChildContent>(child => child + .Add(p => p.Value, "initial") + .AddChildContent("Initial Value")) + .AddChildContent>(child => child + .Add(p => p.Value, "changed") + .AddChildContent("Changed Value"))); + + Assert.Equal("initial", value); + + var select = component.Find("select"); + select.Change("changed"); + + Assert.Equal("changed", value); + } + + [Fact] + public void BitSelectField_Should_Set_Selected_Attribute_On_Correct_Option() + { + string? value = "value2"; + + using var ctx = new BunitContext(); + + var component = ctx.Render>(parameters => parameters + .Add(p => p.Label, "Select a value") + .Add(p => p.Id, "test-select") + .Bind(p => p.Value, value!, v => value = v) + .AddChildContent>(child => child + .Add(p => p.Value, "value1") + .AddChildContent("Value 1")) + .AddChildContent>(child => child + .Add(p => p.Value, "value2") + .AddChildContent("Value 2")) + .AddChildContent>(child => child + .Add(p => p.Value, "value3") + .AddChildContent("Value 3"))); + + var options = component.FindAll("option"); + var selectedOption = options.FirstOrDefault(o => o.HasAttribute("selected")); + + Assert.NotNull(selectedOption); + Assert.Equal("value2", selectedOption.GetAttribute("value")); + } + + [Fact] + public void BitSelectField_Should_Update_Selected_Attribute_When_Value_Changes() + { + int value = 1; + + using var ctx = new BunitContext(); + + var component = ctx.Render>(parameters => parameters + .Add(p => p.Label, "Select a number") + .Add(p => p.Id, "test-select") + .Bind(p => p.Value, value, v => value = v) + .AddChildContent>(child => child + .Add(p => p.Value, 1) + .AddChildContent("One")) + .AddChildContent>(child => child + .Add(p => p.Value, 2) + .AddChildContent("Two")) + .AddChildContent>(child => child + .Add(p => p.Value, 3) + .AddChildContent("Three"))); + + var select = component.Find("select"); + select.Change(3); + + var options = component.FindAll("option"); + var selectedOption = options.FirstOrDefault(o => o.HasAttribute("selected")); + + Assert.NotNull(selectedOption); + Assert.Equal("3", selectedOption.GetAttribute("value")); + } + + [Fact] + public void BitSelectField_Should_Handle_Nullable_Int_Value_Changes() + { + int? value = null; + + using var ctx = new BunitContext(); + + var component = ctx.Render>(parameters => parameters + .Add(p => p.Label, "Select a number") + .Add(p => p.Id, "test-select") + .Bind(p => p.Value, value, v => value = v) + .AddChildContent>(child => child + .Add(p => p.Value, (int?)null) + .AddChildContent("None")) + .AddChildContent>(child => child + .Add(p => p.Value, 1) + .AddChildContent("One")) + .AddChildContent>(child => child + .Add(p => p.Value, 2) + .AddChildContent("Two"))); + + var select = component.Find("select"); + select.Change(1); + + Assert.Equal(1, value); + } + + [Fact] + public void BitSelectField_Should_Handle_Nullable_Enum_Value_Changes() + { + TestEnum? value = null; + + using var ctx = new BunitContext(); + + var component = ctx.Render>(parameters => parameters + .Add(p => p.Label, "Select an option") + .Add(p => p.Id, "test-select") + .Bind(p => p.Value, value, v => value = v) + .AddChildContent>(child => child + .Add(p => p.Value, (TestEnum?)null) + .AddChildContent("None")) + .AddChildContent>(child => child + .Add(p => p.Value, TestEnum.Option1) + .AddChildContent("Option 1")) + .AddChildContent>(child => child + .Add(p => p.Value, TestEnum.Option2) + .AddChildContent("Option 2"))); + + var select = component.Find("select"); + select.Change(TestEnum.Option2); + + Assert.Equal(TestEnum.Option2, value); + } +} From d767df5a8c6f7f50eaf737add6b8623c0b302542 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 08:33:45 +0000 Subject: [PATCH 3/3] Address code review feedback: make TestEnum explicitly private and remove unnecessary null-forgiving operators Co-authored-by: albx <5121303+albx@users.noreply.github.com> --- .../Form/SelectField/BitSelectFieldTest.Behaviors.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/BitBlazor.Test/Form/SelectField/BitSelectFieldTest.Behaviors.cs b/tests/BitBlazor.Test/Form/SelectField/BitSelectFieldTest.Behaviors.cs index 8147be9..da79592 100644 --- a/tests/BitBlazor.Test/Form/SelectField/BitSelectFieldTest.Behaviors.cs +++ b/tests/BitBlazor.Test/Form/SelectField/BitSelectFieldTest.Behaviors.cs @@ -5,7 +5,7 @@ namespace BitBlazor.Test.Form.SelectField; public class BitSelectFieldTest { - enum TestEnum + private enum TestEnum { Option1, Option2, @@ -22,7 +22,7 @@ public void BitSelectField_Should_Change_String_Value_Correctly() var component = ctx.Render>(parameters => parameters .Add(p => p.Label, "Select a value") .Add(p => p.Id, "test-select") - .Bind(p => p.Value, value!, v => value = v) + .Bind(p => p.Value, value, v => value = v) .AddChildContent>(child => child .Add(p => p.Value, string.Empty) .AddChildContent("Choose an option")) @@ -106,7 +106,7 @@ public void BitSelectField_Should_Update_Bound_Value_When_Selection_Changes() var component = ctx.Render>(parameters => parameters .Add(p => p.Label, "Select a value") .Add(p => p.Id, "test-select") - .Bind(p => p.Value, value!, v => value = v) + .Bind(p => p.Value, value, v => value = v) .AddChildContent>(child => child .Add(p => p.Value, "initial") .AddChildContent("Initial Value")) @@ -132,7 +132,7 @@ public void BitSelectField_Should_Set_Selected_Attribute_On_Correct_Option() var component = ctx.Render>(parameters => parameters .Add(p => p.Label, "Select a value") .Add(p => p.Id, "test-select") - .Bind(p => p.Value, value!, v => value = v) + .Bind(p => p.Value, value, v => value = v) .AddChildContent>(child => child .Add(p => p.Value, "value1") .AddChildContent("Value 1"))