-
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
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,41 @@ 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; | ||
|
|
||
| up.Enabled.Should().BeTrue(); | ||
| down.Enabled.Should().BeFalse(); | ||
|
|
||
| listBox.SelectedIndex = 0; | ||
| 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 |
||
| listBox.ClearSelected(); | ||
| listBox.SelectedIndex = 1; | ||
| 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 |
||
| a.AddItems(new object[] { 42 }); | ||
| 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: