Skip to content

test(core): stub BillingNavComputeGaugeComponent in core.navigation unit tests#4180

Merged
PierreBrisorgueil merged 2 commits into
masterfrom
fix/navigation-gauge-stub
May 20, 2026
Merged

test(core): stub BillingNavComputeGaugeComponent in core.navigation unit tests#4180
PierreBrisorgueil merged 2 commits into
masterfrom
fix/navigation-gauge-stub

Conversation

@PierreBrisorgueil
Copy link
Copy Markdown
Collaborator

Closes #4129.

Why

The real BillingNavComputeGaugeComponent auto-fetches compute usage via the billing store on mount (<script> calls useBillingMeterStore or equivalent). This silently coupled core.navigation unit tests to billing infrastructure: any test that flips meterMode=true would trigger network/store side-effects irrelevant to navigation behavior.

What

  • Refactor the hoisted auth mock to use a mutable authStoreState ref (mirrors the existing coreStoreState pattern). Individual tests can now override serverConfig (e.g. enable billing.meterMode) without re-mocking.
  • Extend mountNav({ ..., stubsOverride }) to accept extra stubs; merge them after defaults.
  • Default-stub BillingNavComputeGaugeComponent to a placeholder <div class=\"stub-billing-nav-compute-gauge\" /> — decouples nav tests from billing infra.
  • Add positive-path test: when meterMode=true, the stubbed gauge renders.
  • `beforeEach` resets `authStoreState.serverConfig` to default (no billing) for independent tests.

Verification

npm run test:unit -- src/modules/core/tests/core.navigation.component.unit.tests.js
# Test Files  1 passed (1)
#      Tests  20 passed (20)

All existing tests in the suite preserved (4 prior gauge-slot tests + 16 other). +1 new positive-path test = 20 total.

Copilot AI review requested due to automatic review settings May 20, 2026 10:26
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

Warning

Rate limit exceeded

@PierreBrisorgueil has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 25 minutes and 56 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4f5bf102-0833-41f5-bcf6-9578cb3ae6c5

📥 Commits

Reviewing files that changed from the base of the PR and between acf5756 and fce91cc.

📒 Files selected for processing (1)
  • src/modules/core/tests/core.navigation.component.unit.tests.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/navigation-gauge-stub

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.

…nit tests

Closes #4129. The real gauge auto-fetches via the billing store on
mount, silently coupling navigation unit tests to billing
infrastructure. Adding a default stub in mountNav() decouples the
suites and enables a positive-path test (meterMode=true → gauge slot
renders).
@PierreBrisorgueil PierreBrisorgueil force-pushed the fix/navigation-gauge-stub branch from ade9167 to 5a15033 Compare May 20, 2026 10:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR decouples core.navigation unit tests from billing infrastructure by default-stubbing the billing compute gauge component, preventing unintended billing-store side effects when tests enable billing.meterMode.

Changes:

  • Refactors the auth store mock to a mutable hoisted authStoreState so tests can override serverConfig without re-mocking.
  • Extends mountNav() to accept stubsOverride and merges it after default stubs.
  • Adds a default stub for BillingNavComputeGaugeComponent and a new positive-path test asserting it renders when meterMode=true.

Comment on lines +307 to +313
});

it('renders stubbed BillingNavComputeGaugeComponent when meterMode is true', () => {
// Override auth state so meterMode resolves to true for this test only.
// beforeEach resets it back to the default (no billing key) for subsequent tests.
authStoreState.serverConfig = { organizations: { enabled: false }, billing: { meterMode: true } };
const wrapper = mountNav();
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed in fce91cc: wrapped the meterMode=true override in try/finally so the override cannot leak even if mountNav() throws. Next describes' beforeEach already reset state, but defensive intra-test reset is cleaner.


// Mock auth store — report logged in + org so the drawer actually renders
// Mock auth store — report logged in + org so the drawer actually renders.
// authStoreState is a mutable hoisted ref so individual tests can override
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed in fce91cc: comment reworded to 'mutable hoisted object' (matches reality — it's a plain hoisted object via vi.hoisted(), not a Vue ref).

@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.55%. Comparing base (25a3ceb) to head (fce91cc).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4180   +/-   ##
=======================================
  Coverage   99.55%   99.55%           
=======================================
  Files          31       31           
  Lines        1136     1136           
  Branches      328      328           
=======================================
  Hits         1131     1131           
  Misses          5        5           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…iew nits)

- Reword comment: 'mutable hoisted ref' → 'mutable hoisted object' (it's a plain
  hoisted object, not a Vue ref). Avoids future-edit confusion.
- Wrap the meterMode=true test's authStoreState mutation in try/finally so the
  override cannot leak into subsequent tests/describes even if mountNav()
  throws. Next describes' beforeEach already reset state, but defensive intra-test
  reset is cleaner and resilient to test reordering.
@PierreBrisorgueil PierreBrisorgueil merged commit 57465e6 into master May 20, 2026
7 checks passed
@PierreBrisorgueil PierreBrisorgueil deleted the fix/navigation-gauge-stub branch May 20, 2026 11:00
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.

fix(core): stub billingComputeGauge in core.navigation unit tests

2 participants