-
-
Notifications
You must be signed in to change notification settings - Fork 260
Develop unit tests for BitModalService component (#11750) #11751
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
Develop unit tests for BitModalService component (#11750) #11751
Conversation
WalkthroughIntroduces unit tests for BitModalService with three test methods covering modal rendering, closing, and persistent modal scenarios. Adds a test Blazor component TestModalContent to support modal content rendering in tests. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/BlazorUI/Bit.BlazorUI.Tests/Components/Extras/ModalService/BitModalServiceTests.cs (2)
20-37: Tighten content assertion to target the rendered elementUsing
container.Markup.Contains(message)works but is a bit loose; you can assert against the specific element rendered byTestModalContentfor a more robust test:- container.WaitForAssertion(() => - { - Assert.AreEqual(1, container.FindAll(".bit-mdl").Count); - Assert.IsTrue(container.Markup.Contains(message)); - }); + container.WaitForAssertion(() => + { + Assert.AreEqual(1, container.FindAll(".bit-mdl").Count); + + var content = container.Find(".test-modal-content"); + Assert.AreEqual(message, content.TextContent); + });This ties the assertion directly to the modal content component rather than any occurrence of the text in the markup.
59-72: Consider optional extra tests for overlay and persistent behaviorsCurrent tests cover basic render/close and the “persistent before container init” path. As a future enhancement (not blocking this PR), you might add:
- A test that shows a non‑blocking modal and verifies that clicking the overlay closes it.
- A test that shows a persistent modal after the container is already initialized to confirm it doesn’t get queued and still behaves as expected.
These would round out coverage of
persistentandBlocking‑related behavior.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting
📒 Files selected for processing (2)
src/BlazorUI/Bit.BlazorUI.Tests/Components/Extras/ModalService/BitModalServiceTests.cs(1 hunks)src/BlazorUI/Bit.BlazorUI.Tests/Components/Extras/ModalService/TestModalContent.cs(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/BlazorUI/Bit.BlazorUI.Tests/Components/Extras/ModalService/BitModalServiceTests.cs (4)
src/BlazorUI/Bit.BlazorUI.Extras/Components/ModalService/BitModalService.cs (1)
BitModalService(9-157)src/BlazorUI/Bit.BlazorUI.Extras/Components/ModalService/BitModalContainer.razor.cs (1)
BitModalContainer(5-73)src/BlazorUI/Bit.BlazorUI.Tests/Components/Extras/ModalService/TestModalContent.cs (1)
TestModalContent(6-17)src/BlazorUI/Bit.BlazorUI.Extras/Components/ModalService/BitModalReference.cs (1)
Close(49-52)
⏰ 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 Bit.BlazorUI
🔇 Additional comments (3)
src/BlazorUI/Bit.BlazorUI.Tests/Components/Extras/ModalService/TestModalContent.cs (1)
6-16: Simple, deterministic test component looks goodThe component cleanly exposes
Messageand renders a single predictable<p>element, which is ideal for bUnit assertions; no changes needed here.src/BlazorUI/Bit.BlazorUI.Tests/Components/Extras/ModalService/BitModalServiceTests.cs (2)
12-18: DI setup for BitModalService in tests is appropriateRegistering
BitModalServicein[TestInitialize]and resolving it via theServicesproperty integrates cleanly withBitModalContainer’s injection and keeps each test self‑contained.
39-57: Close‑path test effectively exercises BitModalReference & service wiringThe second test correctly verifies that
Showrenders a modal and that invokingmodalRef.Close()propagates throughBitModalService.Closeand the container’sOnCloseModalhandler, withWaitForAssertionguarding against async timing. This is a solid coverage of the close flow.
closes #11750
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.