|
| 1 | +# Testing Gaps — NoteBookmark.BlazorApp.Tests |
| 2 | + |
| 3 | +> Written by Biggs (Tester/QA) as part of Issue #119 regression coverage. |
| 4 | +> Purpose: document what we tested, what we couldn't, and what would make it testable. |
| 5 | +
|
| 6 | +--- |
| 7 | + |
| 8 | +## What We Tested (bUnit unit tests) |
| 9 | + |
| 10 | +| Component | Tests | Notes | |
| 11 | +|---|---|---| |
| 12 | +| `NavMenu` | 5 | Smoke + link presence. No service injection. ✅ Easy to test. | |
| 13 | +| `LoginDisplay` | 4 | Authenticated / anonymous states via FakeAuthStateProvider. ✅ | |
| 14 | +| `SuggestionList` | 4 | Null/empty/populated states. Stub PostNoteClient via fake HttpClient. ✅ | |
| 15 | +| `NoteDialog` | 5 | Create mode, edit mode, tag display, category list. FluentDialog cascade stubbed as null (safe for non-click tests). ✅ | |
| 16 | +| `MinimalLayout` | 3 | Body rendering, footer presence. ✅ | |
| 17 | +| `MainLayout` | 4 | Composite layout; requires FluentUI + auth setup. ✅ Smoke only. | |
| 18 | + |
| 19 | +**Total: 25 tests across 6 components.** |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +## Known Gaps |
| 24 | + |
| 25 | +### 1. SuggestionList — Button Click Interactions |
| 26 | + |
| 27 | +**What's not tested:** Clicking "Add" or "Delete" on a suggestion item. |
| 28 | + |
| 29 | +**Why:** These handlers call `PostNoteClient.ExtractPostDetailsAndSave()` and `IToastService.ShowSuccess/ShowError()`. The PostNoteClient is backed by a stub HttpClient in unit tests, but the response shape must match the expected JSON contract. More importantly, `IToastService.ShowSuccess` is registered via `AddFluentUIComponents()` but the FluentToastProvider is not mounted in the test host, so toast display assertions would be vacuous. |
| 30 | + |
| 31 | +**What would make it testable:** |
| 32 | +- Mock `IToastService` explicitly and verify `ShowSuccess()`/`ShowError()` was called. |
| 33 | +- Use `PostNoteClient` with a typed stub HttpClient returning a real `PostSuggestion` JSON blob. |
| 34 | +- Register a minimal FluentToastProvider in the test component tree. |
| 35 | + |
| 36 | +**Candidate:** Integration test with a lightweight ASP.NET Core test host. |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +### 2. NoteDialog — Save / Cancel / Delete Button Actions |
| 41 | + |
| 42 | +**What's not tested:** Clicking Save, Cancel, or Delete inside the dialog. |
| 43 | + |
| 44 | +**Why:** These handlers call `Dialog.CloseAsync()` and `Dialog.CancelAsync()` on the cascading `FluentDialog`. In bUnit, we cascade `null` for `FluentDialog` because it's a concrete component requiring the full Fluent dialog infrastructure (a mounted `FluentDialogProvider` and `IDialogService` host). Clicking a button that calls `Dialog.CloseAsync()` on `null` would throw a NullReferenceException. |
| 45 | + |
| 46 | +**What would make it testable:** |
| 47 | +- Extract an `IDialogContext` interface (or adapter) over `FluentDialog` so tests can inject a mock. |
| 48 | +- Or: mount a real `FluentDialogProvider` in the bUnit test context and open `NoteDialog` via `IDialogService.ShowDialogAsync<NoteDialog>(...)`. This is the integration test path. |
| 49 | +- Or: refactor `NoteDialog` to use an `EventCallback<NoteDialogResult>` instead of `Dialog.CloseAsync()` — this would make it fully unit-testable without the Fluent dialog framework. |
| 50 | + |
| 51 | +**Candidate:** Integration test via `IDialogService` OR component refactor. |
| 52 | + |
| 53 | +--- |
| 54 | + |
| 55 | +### 3. MainLayout — LoginDisplay Interaction |
| 56 | + |
| 57 | +**What's not tested:** Clicking "Login" or "Logout" inside the rendered MainLayout triggers the correct navigation. |
| 58 | + |
| 59 | +**Why:** `LoginDisplay` calls `Navigation.NavigateTo(...)`. bUnit provides a `FakeNavigationManager`, but verifying navigation from within a composite layout requires inspecting `NavigationManager.Uri` after a button click. This is feasible but was excluded from the smoke-test scope. |
| 60 | + |
| 61 | +**What would make it testable:** |
| 62 | +```csharp |
| 63 | +var cut = RenderComponent<MainLayout>(...); |
| 64 | +cut.Find("button[aria-label='Login']").Click(); // or similar selector |
| 65 | +ctx.Services.GetRequiredService<NavigationManager>().Uri.Should().Contain("/login"); |
| 66 | +``` |
| 67 | +The navigation manager in bUnit doesn't actually navigate (no page load), so this is safe to add as a unit test. |
| 68 | + |
| 69 | +**Candidate:** Unit test — low effort to add. |
| 70 | + |
| 71 | +--- |
| 72 | + |
| 73 | +### 4. Pages (Home, Posts, Search, Settings, etc.) |
| 74 | + |
| 75 | +**What's not tested:** Any of the page-level components. |
| 76 | + |
| 77 | +**Why:** Pages inject `PostNoteClient`, `IToastService`, `IDialogService`, `NavigationManager`, and in some cases `IHttpContextAccessor` (Login page) or `ResearchService` (Search page). The `Login.razor` page is the hardest — it uses `IHttpContextAccessor` and triggers an OIDC challenge on `OnInitializedAsync()`, which is not available in a bUnit context. |
| 78 | + |
| 79 | +**What would make it testable:** |
| 80 | +- Pages with only `PostNoteClient` + FluentUI services: testable today with stub client (same pattern as SuggestionList tests). |
| 81 | +- `Login.razor` and `Logout.razor`: require a real ASP.NET Core test host (`WebApplicationFactory`). These are **integration test candidates**. |
| 82 | +- `PostEditor.razor`, `PostEditorLight.razor`, `Summaries.razor`, `SummaryEditor.razor`: not reviewed in this batch — should be assessed for #119 scope. |
| 83 | + |
| 84 | +**Candidate:** Mix — some unit-testable with stubs; Login/Logout require integration tests. |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +### 5. After SharedUI Extraction (Issue #119) |
| 89 | + |
| 90 | +Once Leia completes the extraction, these tests need a small update: |
| 91 | + |
| 92 | +1. Add `<ProjectReference>` to `NoteBookmark.SharedUI` (marked with `TODO` in the `.csproj`). |
| 93 | +2. Update `using` statements if component namespaces change (e.g., `NoteBookmark.BlazorApp.Components.Shared` → `NoteBookmark.SharedUI.Components`). |
| 94 | +3. Verify the same tests still pass — **that's the regression proof**. |
| 95 | +4. Re-run `dotnet test src/NoteBookmark.BlazorApp.Tests/` after the extraction merge. |
| 96 | + |
| 97 | +The tests are intentionally written against the component's **public contract** (parameters, rendered output) rather than internal implementation, so they should survive the move with only namespace changes. |
| 98 | + |
| 99 | +--- |
| 100 | + |
| 101 | +## Test Environment Notes |
| 102 | + |
| 103 | +- **bUnit version:** 2.7.2 |
| 104 | +- **xUnit:** 2.9.3 (from Central Package Management) |
| 105 | +- **FluentUI:** 4.13.2 |
| 106 | +- **JSInterop mode:** `Loose` — FluentUI components call JS internally; we suppress those calls. |
| 107 | +- **PostNoteClient:** not an interface, uses `HttpClient`. Tested via `StubHttpMessageHandler` that returns `[]` for all requests. |
| 108 | +- **AuthorizeView:** tested via `FakeAuthStateProvider` + `AddCascadingAuthenticationState()`. |
0 commit comments