Fix Up and Down arrow buttons not disabling at first and last items in Collection Editor#14668
Fix Up and Down arrow buttons not disabling at first and last items in Collection Editor#14668Rabina4363sf wants to merge 4 commits into
Conversation
| listBox.SelectedIndex = 0; | ||
| up.Enabled.Should().BeFalse(); | ||
| down.Enabled.Should().BeTrue(); | ||
|
|
There was a problem hiding this comment.
Suggestion: This test relies on the SelectedIndexChanged event being wired up to call UpdateEnabled() automatically. In a test environment (where the form is never shown), the event wiring may not be fully initialized, making this test fragile.
Consider calling UpdateEnabled() explicitly after each selection change to make the test deterministic:
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 UpdateEnabled(), not the event wiring.
There was a problem hiding this comment.
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.
| using Form form = editor.CreateCollectionForm(); | ||
|
|
||
| dynamic a = form.TestAccessor.Dynamic; | ||
| a.AddItems(new object[] { 1, 2, 3 }); |
There was a problem hiding this comment.
Suggestion: The test implicitly assumes AddItems selects the last added item (index 2). If AddItems behavior changes in the future, this test will fail without a clear reason.
Consider adding an explicit assertion on the initial state:
a.AddItems(new object[] { 1, 2, 3 });
// AddItems selects the last added item by default
listBox.SelectedIndex.Should().Be(2);
up.Enabled.Should().BeTrue();
down.Enabled.Should().BeFalse();There was a problem hiding this comment.
I’ve added an explicit assertion for the initial state after AddItems so the behavior is clearly verified. Updated in the latest commit.
| up.Enabled.Should().BeFalse(); | ||
| down.Enabled.Should().BeFalse(); | ||
|
|
||
| listBox.Items.Clear(); |
There was a problem hiding this comment.
Suggestion: After listBox.Items.Clear(), SelectedIndex becomes -1. If UpdateEnabled() is not triggered by the clear operation, the button states here could be stale values from the previous assertions rather than reflecting the current state.
Same recommendation: call a.UpdateEnabled() explicitly after AddItems to ensure we're verifying the actual logic, not leftover state.
There was a problem hiding this comment.
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.
|
@dotnet-policy-service agree company="Syncfusion, Inc." |
Fixes #3152
Proposed changes
UpdateEnabledlogic inCollectionEditorCollectionFormto correctly handle boundary conditions for item movement.SelectedIndexis0, preventing invalid upward moves.SelectedIndexis equal toItems.Count - 1, preventing invalid downward moves.Customer Impact
Regression?
Risk
Screenshots
Before
After
Test methodology
Accessibility testing
Test environment(s)
Microsoft Reviewers: Open in CodeFlow