Skip to content

Enhance InputSelect tests by adding edge case scenarios#67015

Open
karmegams02 wants to merge 5 commits into
dotnet:mainfrom
karmegams02:1030956_inputselect_test
Open

Enhance InputSelect tests by adding edge case scenarios#67015
karmegams02 wants to merge 5 commits into
dotnet:mainfrom
karmegams02:1030956_inputselect_test

Conversation

@karmegams02
Copy link
Copy Markdown

@karmegams02 karmegams02 commented Jun 4, 2026

Summary

This PR significantly enhances the test coverage for Microsoft.AspNetCore.Components.Forms.InputSelect component by:

  • Adding 20+ new test cases covering diverse scenarios
  • Improving validation coverage for enums, primitives, and nullable types
  • Ensuring correct attribute pass-through (class, data-, aria- )
  • Strengthening behavior verification for multi-select and binding scenarios
  • Improving test robustness and clarity with better patterns and helper usage

Changes

  • File modified: src/Components/Web/test/Forms/InputSelectTest.cs
  • Lines changed: +503 / -7
  • Test methods added: ~21 new tests
    • Core parsing & binding (enum parsing, nullable enum handling, bool parsing → null support)
    • Nullable & empty handling (nullable types → empty string = null, non-nullable keeps last valid value, validation errors)
    • Attribute pass-through (class, data-, aria- support)
    • Select behavior (multi-select renders multiple, single-select does not)
    • Validation lifecycle (invalid input not updating model, errors added/cleared correctly)
    • Field tracking (tracks changes for valid & invalid inputs)
    • Value stability (handles repeated selection, same value consistency)
    • Rendering & events (correct <select> rendering, onchange binding)

Testing

  • All existing tests continue to pass
  • All newly added tests pass successfully
  • Tests follow existing patterns and infrastructure

@github-actions github-actions Bot added the area-blazor Includes: Blazor, Razor Components label Jun 4, 2026
@karmegams02
Copy link
Copy Markdown
Author

@dotnet-policy-service agree company="Syncfusion, Inc."

Copy link
Copy Markdown
Member

@lewing lewing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, @karmegams02 — there are genuinely valuable additions here, especially around bool? parsing, nullable-empty handling, and EditContext.IsModified tracking, which were previously uncovered. Requesting changes on a couple of scope items and one consolidation suggestion before merge.

🚩 Please address (out of scope for an "add tests" PR)

  1. Revert the TestEnum.TreeTestEnum.Three rename (InputSelectTest.cs:260).
    This rename isn't mentioned in the PR description and isn't required by any of the new tests except ChangingValueMultipleTimesAlwaysReflectsLatestValue, which can use the existing Tree value instead. Renames to pre-existing test infrastructure should land as a separate, clearly-scoped PR.

  2. Revert the SingleSingleOrDefault change in RendersIdAttribute (InputSelectTest.cs:229).
    That test was passing on main with the stricter Single invariant ("exactly one id attribute frame"). Relaxing the assertion isn't necessary for any of the new tests, and weakens an existing precondition. If a new test breaks under Single, that's worth investigating rather than working around.

✂️ Please dedupe (functionally identical to existing tests)

  1. ParsesNotNullableEnumWithExactNameMatch and ParsesNullableEnumWithExactNameMatch are duplicates of the existing ParsesCurrentValueWhenUsingNotNullableEnumWithNotEmptyValue / ParsesCurrentValueWhenUsingNullableEnumWithNotEmptyValue — same input ("Two"/"One"), same assertion. The only difference is the async wrapper SetCurrentValueAsStringAsync, which just dispatches the same write through InvokeAsync — no new behavior is covered. Please delete both.

💡 Optional but recommended

The three attribute-pass-through tests (ClassAttributeIsPassedThroughViaAdditionalAttributes, DataAttributesArePassedThroughViaAdditionalAttributes, AriaAttributesArePassedThroughViaAdditionalAttributes) all exercise the same single line in production (builder.AddMultipleAttributes(1, AdditionalAttributes) in InputSelect.cs). Consider collapsing into one [Theory] over the three attribute families — cuts ~100 lines without losing coverage. Same applies to the multi-select pair (MultiSelectWithStringArrayRendersMultipleAttribute + SingleSelectDoesNotRenderMultipleAttribute).

Thanks again — the nullable-bool and validation-lifecycle tests are real coverage gains and worth landing.

@karmegams02 karmegams02 requested a review from lewing June 5, 2026 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants