Skip to content

Conversation

@msynk
Copy link
Member

@msynk msynk commented Nov 17, 2025

closes #11665

Summary by CodeRabbit

  • Tests
    • Added comprehensive unit tests for the BitDialog component covering rendering, overlay behavior, close functionality, dialog result handling, and accessibility role attributes.

@coderabbitai
Copy link

coderabbitai bot commented Nov 17, 2025

Walkthrough

A comprehensive test suite for the BitDialog component is introduced, covering rendering states, user interactions, button behavior, overlay dismissal logic with blocking variants, asynchronous dialog result flows, and accessibility role attributes across various configuration combinations.

Changes

Cohort / File(s) Summary
BitDialog Component Tests
src/BlazorUI/Bit.BlazorUI.Tests/Components/Surfaces/Dialog/BitDialogTests.cs
Adds comprehensive unit tests using BUnit covering: open/closed rendering with title, message, buttons, and overlay; overlay click dismissal based on IsBlocking flag; close button invocation and state updates; asynchronous Show() flows returning Ok/Cancel results; role attribute behavior based on IsAlert, IsBlocking, and IsModeless parameters; data-driven tests for IsAlert configuration.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Verify test coverage spans all documented scenarios (rendering, interactions, async flows, accessibility)
  • Confirm JSInterop mock initialization and element selection logic in each test
  • Validate assertions for state transitions and BitDialogResult correctness
  • Review data-driven test cases for IsAlert role determination logic

Poem

🐰 A dialog now tested with care,
With buttons and clicks everywhere,
Async flows dance, roles ring true,
Blocking and modeless, all shining new!
This rabbit salutes your test suite so rare! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add missing tests of BitDialog (#11665)' clearly summarizes the main change—adding comprehensive unit tests for the BitDialog component.
Linked Issues check ✅ Passed The pull request adds comprehensive unit tests for BitDialog covering rendering, overlay behavior, close button handling, Show() flows, and accessibility/role handling, which directly addresses the linked issue requirement.
Out of Scope Changes check ✅ Passed All changes are scoped to adding unit tests for the BitDialog component, with no alterations to exported/public entities or unrelated modifications.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/BlazorUI/Bit.BlazorUI.Tests/Components/Surfaces/Dialog/BitDialogTests.cs (3)

61-61: Remove redundant ternary operator.

The ternary isBlocking ? 1 : 1 always evaluates to 1, making it redundant.

Apply this diff:

-        Assert.AreEqual(isBlocking ? 1 : 1, overlays.Count);
+        Assert.AreEqual(1, overlays.Count);

136-136: Consider renaming to reflect actual test scope.

The method name mentions "AndBlocking" but only tests IsAlert variations. Consider renaming to BitDialogRoleRespectsIsAlert for clarity.

Apply this diff:

-    public void BitDialogRoleRespectsIsAlertAndBlocking(bool? isAlert)
+    public void BitDialogRoleRespectsIsAlert(bool? isAlert)

136-157: Consider expanding test coverage for IsBlocking and IsModeless.

The test sets IsBlocking=true and IsModeless=false but doesn't verify variations of these parameters. If the dialog's role attribute behavior depends on blocking or modeless states (per WAI-ARIA guidance), these scenarios should be tested.

Consider adding a data-driven test that varies IsAlert, IsBlocking, and IsModeless combinations to ensure the role attribute is set correctly across all accessibility scenarios. For example:

[TestMethod]
[DataRow(true, true, false, "alertdialog")]   // alert, blocking, not modeless
[DataRow(false, true, false, "dialog")]       // not alert, blocking, not modeless
[DataRow(true, false, true, "dialog")]        // alert, not blocking, modeless
// Add more combinations as needed based on component logic
public void BitDialogRoleRespectsAccessibilityParameters(bool isAlert, bool isBlocking, bool isModeless, string expectedRole)
{
    Context.JSInterop.Mode = JSRuntimeMode.Loose;

    var component = RenderComponent<BitDialog>(parameters =>
    {
        parameters.Add(p => p.IsOpen, true);
        parameters.Add(p => p.IsAlert, isAlert);
        parameters.Add(p => p.IsBlocking, isBlocking);
        parameters.Add(p => p.IsModeless, isModeless);
    });

    var roleDiv = component.Find("div[role]");
    Assert.AreEqual(expectedRole, roleDiv.GetAttribute("role"));
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between dd9578d and 0a315fe.

📒 Files selected for processing (1)
  • src/BlazorUI/Bit.BlazorUI.Tests/Components/Surfaces/Dialog/BitDialogTests.cs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build and test
🔇 Additional comments (4)
src/BlazorUI/Bit.BlazorUI.Tests/Components/Surfaces/Dialog/BitDialogTests.cs (4)

10-39: LGTM! Comprehensive rendering test.

The test effectively validates the dialog's core rendering behavior when open, checking title, message, buttons, and overlay presence.


44-75: Test logic correctly validates IsBlocking behavior.

The test properly verifies that overlay clicks respect the IsBlocking flag: dialogs stay open when blocking, and close with OnDismiss invocation when not blocking.


77-96: LGTM! Clear and focused test.

The test cleanly validates that clicking the close button both invokes the OnClose callback and updates the IsOpen state.


98-130: LGTM! Async flow correctly tested.

The test properly validates that Show() returns the expected BitDialogResult values for both OK and Cancel button clicks. Using separate component instances for each scenario is a sound approach.

@msynk msynk merged commit 3be174e into bitfoundation:develop Nov 17, 2025
3 checks passed
@msynk msynk deleted the 11665-blazorui-dialog-tests branch November 17, 2025 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing tests of BiDialog component

1 participant