-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix Up and Down arrow buttons not disabling at first and last items in Collection Editor #14668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e6f5d7b
267e52d
aac2f7f
257f147
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,47 @@ namespace System.ComponentModel.Design.Tests; | |
|
|
||
| public class CollectionEditorTests | ||
| { | ||
| [Fact] | ||
| public void CollectionEditor_CollectionForm_UpdateEnabled_FirstMiddleLastNone_SetsUpDownExpected() | ||
| { | ||
| SubCollectionEditor editor = new(typeof(List<int>)); | ||
| using Form form = editor.CreateCollectionForm(); | ||
|
|
||
| dynamic a = form.TestAccessor.Dynamic; | ||
| a.AddItems(new object[] { 1, 2, 3 }); | ||
|
|
||
| ListBox listBox = (ListBox)a._listBox; | ||
| Button up = (Button)a._upButton; | ||
| Button down = (Button)a._downButton; | ||
|
|
||
| listBox.SelectedIndex = 2; | ||
| a.UpdateEnabled(); | ||
| up.Enabled.Should().BeTrue(); | ||
| down.Enabled.Should().BeFalse(); | ||
|
|
||
| listBox.ClearSelected(); | ||
| listBox.SelectedIndex = 0; | ||
| a.UpdateEnabled(); | ||
| up.Enabled.Should().BeFalse(); | ||
| down.Enabled.Should().BeTrue(); | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: This test relies on the Consider calling listBox.SelectedIndex = 0;
a.UpdateEnabled(); // Don't rely on event — call explicitly
up.Enabled.Should().BeFalse();This also makes the test more readable — it's clear we're testing the logic of
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion. I’ve updated the test to call UpdateEnabled() explicitly after selection changes to avoid relying on event wiring. Included in the latest commit. |
||
| listBox.ClearSelected(); | ||
| listBox.SelectedIndex = 1; | ||
| a.UpdateEnabled(); | ||
| up.Enabled.Should().BeTrue(); | ||
| down.Enabled.Should().BeTrue(); | ||
|
|
||
| listBox.ClearSelected(); | ||
| up.Enabled.Should().BeFalse(); | ||
| down.Enabled.Should().BeFalse(); | ||
|
|
||
| listBox.Items.Clear(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: After Same recommendation: call
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree with this. I’ve added an explicit UpdateEnabled() call after the state changes to ensure we’re validating the correct state. Fixed in the latest commit. |
||
| a.AddItems(new object[] { 42 }); | ||
| a.UpdateEnabled(); | ||
| up.Enabled.Should().BeFalse(); | ||
| down.Enabled.Should().BeFalse(); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(typeof(object), typeof(object))] | ||
| [InlineData(typeof(string), typeof(object))] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: The test implicitly assumes
AddItemsselects the last added item (index 2). IfAddItemsbehavior changes in the future, this test will fail without a clear reason.Consider adding an explicit assertion on the initial state:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve added an explicit assertion for the initial state after AddItems so the behavior is clearly verified. Updated in the latest commit.