Skip to content

Enhance InputSelect tests by adding edge case scenarios - #67015

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

karmegams02 wants to merge 21 commits into
dotnet:mainfrom
karmegams02:1030956_inputselect_test

Conversation

@karmegams02

@karmegams02 karmegams02 commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

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

  • Adding 17 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
  • Test methods added: ~17 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
Contributor Author

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

@lewing lewing left a comment

Copy link
Copy Markdown
Member

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.Tree → TestEnum.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 Single → SingleOrDefault 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
@karmegams02

Copy link
Copy Markdown
Contributor Author

Hi @lewing , thank you for your valuable feedback and detailed review.
• Reverted the enum rename and restored the original values
• Reinstated the Single assertion in the existing test
• Removed the duplicate tests
• Consolidated the attribute pass-through tests to reduce duplication
All review comments have been addressed. Please take a look at the latest changes.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Sep 26, 2026
@PureWeen

Copy link
Copy Markdown
Member

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Source-only review of frozen head ef3201d983bfcbcfd53f32dda929cdfcfa9f3d59 found two P3 test false-pass risks: the nullable-empty tests never initialize the component with their non-null model values, and the invalid-value retention tests begin at the type default.

Both routed guides completed independently: docs/CrossCuttingGuidance.md and docs/BlazorComponentsGuidance.md. The sole changed file was covered by both guides; no materially changed area was uncovered. Target execution, tests, CI, browser workflows, and security assessment were excluded by the trusted source-only review policy.

The complete prepared feedback contained no duplicate of these findings; earlier feedback covered separate scope and deduplication issues. There are no unresolved candidates. Evidence came only from the immutable version-2 bundle for head ef3201d983bfcbcfd53f32dda929cdfcfa9f3d59, merge base 59d3bac310685ce1e60b07e4893f9083f54c50f1, base tip and reviewer guidance commit 4f556f73a610b386e5ec29355a300e493d30c4c5. No target code or tests were executed. Limitations: tracked frozen Git bytes only, no feedback posted after bundle preparation, and no target behavior behind symlink/submodule/LFS pointers.

Generated by ASP.NET Core Pull Request Review for #67015 · copilot · gpt56 · 187.5 AIC · ⌖ 18.4 AIC · ⊞ 19.5K
Comment /review to run again

Copilot AI balanced review requested due to automatic review settings November 1, 2026 12:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The nullable input tests start with null rather than the model’s non-null values, so their null assertions can pass even if empty input leaves the value unchanged.

1 open issue
What changed in this PR

Expands unit coverage for Blazor’s InputSelect component without changing production code.

Changes:

  • Adds parsing, nullable-value, validation lifecycle, and repeated-selection tests.
  • Checks attribute pass-through, single- and multi-select rendering, and event-handler registration.
  • Strengthens the existing element-reference test with an explicit no-exception assertion.
File Description
src/​Components/​Web/​test/​Forms/​InputSelectTest.cs Adds edge-case tests and supporting models for input values, validation, and rendering.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The test-only expansion of InputSelect coverage has no active review issues.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@PureWeen

PureWeen commented Nov 4, 2026

Copy link
Copy Markdown
Member

/review

@kotlarmilos

Copy link
Copy Markdown
Member

Thanks for adding these tests. What specific regression or coverage gap are they addressing? I do not see a linked issue or product change, so I would like to understand the reason for this expansion.

@karmegams02

Copy link
Copy Markdown
Contributor Author

Hi @kotlarmilos , These tests were added early in the development phase to improve coverage in areas that had lower test coverage. They are not related to any specific issue or product change. The goal was to improve overall test coverage and help prevent future regressions.

@kotlarmilos

Copy link
Copy Markdown
Member

To keep CI cost under control, I suggest closing this PR unless we see regressions.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-reviewed-needs-changes area-blazor Includes: Blazor, Razor Components pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants