Skip to content

test: more tests for admin/events, also added alias for /src/__tests_ - $test#147

Merged
HardMax71 merged 2 commits intomainfrom
test/admin-events-frontend
Feb 7, 2026
Merged

test: more tests for admin/events, also added alias for /src/__tests_ - $test#147
HardMax71 merged 2 commits intomainfrom
test/admin-events-frontend

Conversation

@HardMax71
Copy link
Owner

@HardMax71 HardMax71 commented Feb 7, 2026


Summary by cubic

Adds comprehensive tests for the admin/events UI (tables, modals, banners, filters, stats, user overview), covering empty states, callbacks, and formatting. Fixes and standardizes test imports by introducing a $test alias and updating existing tests.

  • Refactors
    • Added $test alias in vitest.config.ts pointing to /src/tests.
    • Replaced legacy test-utils imports with $test/test-utils across components, routes, and stores; standardized icon/toast/mock component mocks.

Written for commit 84cfa37. Summary will update on new commits.

Summary by CodeRabbit

  • Tests

    • Added comprehensive unit tests for event management (details, filters, stats, table, replay flows, progress banner, user overview) and various UI components to improve reliability.
    • Standardized test utility imports across suites for clearer test structure.
  • Chores

    • Updated test configuration to enable a new test import alias and improve module resolution for test utilities.

@coderabbitai
Copy link

coderabbitai bot commented Feb 7, 2026

📝 Walkthrough

Walkthrough

Adds a Vitest path alias $test and updates many test files to import shared test utilities via that alias; also introduces seven new comprehensive test suites for admin events components. No runtime application code or public API/signatures were changed.

Changes

Cohort / File(s) Summary
Vitest config
frontend/vitest.config.ts
Added $test -> /src/__tests__ resolve alias for Vitest.
Test utility import updates (components & editor)
frontend/src/components/__tests__/Header.test.ts, frontend/src/components/__tests__/NotificationCenter.test.ts, frontend/src/components/__tests__/ProtectedRoute.test.ts, frontend/src/components/editor/__tests__/LanguageSelect.test.ts, frontend/src/components/editor/__tests__/OutputPanel.test.ts, frontend/src/components/editor/__tests__/ResourceLimits.test.ts, frontend/src/components/editor/__tests__/SavedScripts.test.ts
Replaced relative test-utils import paths with $test/test-utils across component/editor tests and mocks.
Test utility import updates (routes, admin, stores)
frontend/src/routes/__tests__/Editor.test.ts, frontend/src/routes/__tests__/Home.test.ts, frontend/src/routes/__tests__/Login.test.ts, frontend/src/routes/__tests__/Notifications.test.ts, frontend/src/routes/__tests__/Register.test.ts, frontend/src/routes/__tests__/Settings.test.ts, frontend/src/routes/admin/__tests__/AdminLayout.test.ts, frontend/src/routes/admin/__tests__/AdminSettings.test.ts, frontend/src/stores/__tests__/auth.test.ts
Replaced relative test-utils import paths with $test/test-utils across route, admin layout/settings, and store tests and mocks.
New admin events test suites
frontend/src/components/admin/events/__tests__/EventDetailsModal.test.ts, frontend/src/components/admin/events/__tests__/EventFilters.test.ts, frontend/src/components/admin/events/__tests__/EventStatsCards.test.ts, frontend/src/components/admin/events/__tests__/EventsTable.test.ts, frontend/src/components/admin/events/__tests__/ReplayPreviewModal.test.ts, frontend/src/components/admin/events/__tests__/ReplayProgressBanner.test.ts, frontend/src/components/admin/events/__tests__/UserOverviewModal.test.ts
Added seven comprehensive unit test files covering rendering, interactions, callbacks, and edge cases for admin events UI components.
Misc small test edits
frontend/src/components/__tests__/Header.test.ts, frontend/src/components/__tests__/NotificationCenter.test.ts (already listed above)
Minor import path tweaks: switched mocks to use $test/test-utils alias (no logic changes).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • PR #145: Migrates test-utils to a centralized module and updates tests to consume it via a path alias — directly overlaps alias/import changes.
  • PR #146: Edits the editor test suites (LanguageSelect, OutputPanel, ResourceLimits, SavedScripts) that share the same import updates present here.
  • PR #27: Broad frontend test infrastructure changes touching vitest.config and multiple test files; strongly related to the test consolidation in this PR.

Poem

🐰
Hopping through aliases bright and spry,
I swapped the paths and gave tests new sky.
Seven suites hop in a row,
Mocks aligned and ready to go.
Tail twitch — the test green lights fly!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: adding comprehensive tests for admin/events components and introducing a $test alias for test utilities.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/admin-events-frontend

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
frontend/src/components/admin/events/__tests__/EventStatsCards.test.ts (2)

51-61: getByText('3') may be fragile if other stat cards also contain the digit "3".

With default mock values (e.g., total_events: 150, error_rate: 2.5, avg_processing_time: 1.23), the digit '3' could appear elsewhere in the rendered output. Consider using a more scoped query or an exact: false text matcher anchored to the card context to avoid false matches.


31-39: Consider adding a boundary case for the error-rate threshold.

The parameterized cases cover error_rate: 5 (red) and error_rate: 0 (green). If the component uses a threshold like > 0 or >= 5, a case just below the boundary (e.g., error_rate: 4.99) would strengthen confidence in the conditional logic.


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

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 24 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="frontend/src/components/admin/events/__tests__/EventsTable.test.ts">

<violation number="1" location="frontend/src/components/admin/events/__tests__/EventsTable.test.ts:62">
P2: These assertions rely on the runtime default locale/time zone, which makes the test flaky across environments. Format the expected strings with an explicit locale and time zone (or mock Intl) to keep the test deterministic.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

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: 2

🤖 Fix all issues with AI agents
In `@frontend/src/components/admin/events/__tests__/EventDetailsModal.test.ts`:
- Around line 104-110: The test "shows '-' when correlation_id is null" sets
correlation_id to undefined, so update the test to match the case you want to
cover: either set detail.event.metadata.correlation_id = null to test the null
path, or rename the test to say "undefined" and/or add an additional test that
sets correlation_id = null to cover both; locate the code around
createMockEventDetail(), renderModal({ event: detail }) and the assertion using
screen.getAllByText('-') to make the change.

In `@frontend/src/components/admin/events/__tests__/EventStatsCards.test.ts`:
- Around line 25-29: The test EventStatsCards.test ('displays total_events with
locale formatting and totalEvents denominator') relies on hardcoded
comma-formatted strings which are locale-dependent; update the assertions to
generate the expected strings using a fixed locale (e.g., call
toLocaleString('en-US') on the numbers used in renderCards) or use
locale-agnostic regex/normalization when querying text. Locate the test block
that calls renderCards(createMockStats({ total_events: 1500 }), 10000) and
replace the literal '1,500' and /of 10,000 total/ expectations with expressions
that derive the formatted text from the numeric values (or a regex that matches
the numeric digits regardless of separator) so the assertions no longer fail
under different CI locales.
🧹 Nitpick comments (6)
frontend/src/components/admin/events/__tests__/ReplayProgressBanner.test.ts (1)

139-154: Test name claims "red" styling but only asserts text presence.

The test is named 'shows stderr in red when present' but only verifies that the text 'NameError' is in the document. Consider adding a class or style assertion to actually validate the red styling, similar to the status badge tests above.

frontend/src/components/admin/events/__tests__/ReplayPreviewModal.test.ts (1)

11-20: Consider importing ReplayPreview type from the source instead of redefining it locally.

This local interface definition could silently drift from the actual component's prop type. If the component exports or re-exports this type, importing it directly would catch type mismatches at compile time.

frontend/src/components/admin/events/__tests__/EventsTable.test.ts (1)

58-64: Locale-dependent timestamp assertions may be fragile in CI.

toLocaleDateString() and toLocaleTimeString() produce different output depending on the environment's locale (e.g., en-US vs en-GB). If CI runs with a different locale than your dev machine, this test will break. Consider either pinning the locale in the assertion or setting a fixed locale in the test environment.

-    const date = new Date('2024-06-15T14:30:00Z');
-    expect(screen.getByText(date.toLocaleDateString())).toBeInTheDocument();
-    expect(screen.getByText(date.toLocaleTimeString())).toBeInTheDocument();
+    const date = new Date('2024-06-15T14:30:00Z');
+    expect(screen.getByText(date.toLocaleDateString('en-US'))).toBeInTheDocument();
+    expect(screen.getByText(date.toLocaleTimeString('en-US'))).toBeInTheDocument();

This only works if the component also formats with the same locale. The key point is that both test and component should agree on the locale.

frontend/src/components/admin/events/__tests__/UserOverviewModal.test.ts (2)

109-114: Prefer a type-safe approach over the Record<string, unknown> cast.

The cast on line 111 bypasses TypeScript's type checking. If createMockUserOverview doesn't support overrides, consider using a spread to keep it type-safe:

-    const overview = createMockUserOverview();
-    (overview as Record<string, unknown>).rate_limit_summary = null;
-    renderModal({ overview });
+    const overview = { ...createMockUserOverview(), rate_limit_summary: null };
+    renderModal({ overview });

This achieves the same result without silencing the compiler.


90-97: Exact count assertion on getAllByText('100') is coupled to mock data.

expect(hundreds).toHaveLength(2) will break if the mock data or component layout changes to render "100" a different number of times. Using toBeGreaterThanOrEqual(1) (as done elsewhere in these tests) would be more resilient, though the stricter assertion does verify both values render. Just a trade-off to be aware of.

frontend/src/components/admin/events/__tests__/EventDetailsModal.test.ts (1)

60-67: Consider using container from the render result instead of global document.

Line 64 queries document.querySelector('pre') directly. While this works, using the container returned by render() is more idiomatic with Testing Library and better isolates the test:

-    const pre = document.querySelector('pre');
+    const { container } = renderModal({ event: detail });
+    const pre = container.querySelector('pre');

Though since renderModal already returns the render result, you'd just need to destructure it.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 7, 2026

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 2 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="frontend/src/components/admin/events/__tests__/EventStatsCards.test.ts">

<violation number="1" location="frontend/src/components/admin/events/__tests__/EventStatsCards.test.ts:27">
P2: These assertions are locale-dependent because `toLocaleString()` uses the runtime default locale. Tests can fail on machines with different locale settings. Specify a fixed locale (or use Intl.NumberFormat) so the output is deterministic.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@HardMax71 HardMax71 merged commit 1c1bbe9 into main Feb 7, 2026
15 of 16 checks passed
@HardMax71 HardMax71 deleted the test/admin-events-frontend branch February 7, 2026 22: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.

1 participant