Skip to content

Commit ade9167

Browse files
test(core): stub BillingNavComputeGaugeComponent in core.navigation unit 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).
1 parent acf5756 commit ade9167

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

src/modules/core/tests/core.navigation.component.unit.tests.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ vi.mock('vuetify', async (importOriginal) => {
1818
};
1919
});
2020

21-
// Mock auth store — report logged in + org so the drawer actually renders
21+
// Mock auth store — report logged in + org so the drawer actually renders.
22+
// authStoreState is a mutable hoisted ref so individual tests can override
23+
// serverConfig (e.g. to enable billing.meterMode) without re-mocking.
24+
const authStoreState = vi.hoisted(() => ({
25+
isLoggedIn: true,
26+
user: { currentOrganization: { _id: 'org1', name: 'Org' } },
27+
serverConfig: { organizations: { enabled: false } },
28+
signout: vi.fn(),
29+
}));
2230
vi.mock('../../auth/stores/auth.store', () => ({
23-
useAuthStore: () => ({
24-
isLoggedIn: true,
25-
user: { currentOrganization: { _id: 'org1', name: 'Org' } },
26-
serverConfig: { organizations: { enabled: false } },
27-
signout: vi.fn(),
28-
}),
31+
useAuthStore: () => authStoreState,
2932
}));
3033

3134
// Mock core store — we inject our own nav + navBottom arrays per test
@@ -64,10 +67,11 @@ const makeConfig = (overrides = {}) => ({
6467
* @param {Object} opts
6568
* @param {Array} opts.nav - items for the main nav list
6669
* @param {Array} opts.navBottom - items for the bottom nav list
70+
* @param {Object} [opts.stubsOverride] - additional stubs merged after defaults (e.g. to replace the gauge stub)
6771
* @param {Object} [opts.configOverrides] - partial config overrides (e.g. { app: { logoFile: '/logo.svg' } })
6872
* @returns {import('@vue/test-utils').VueWrapper}
6973
*/
70-
const mountNav = ({ nav = [], navBottom = [], configOverrides = {} } = {}) => {
74+
const mountNav = ({ nav = [], navBottom = [], stubsOverride = {}, configOverrides = {} } = {}) => {
7175
coreStoreState.nav = nav;
7276
coreStoreState.navBottom = navBottom;
7377
const vuetify = createVuetify({ components, directives });
@@ -82,6 +86,9 @@ const mountNav = ({ nav = [], navBottom = [], configOverrides = {} } = {}) => {
8286
'router-link': { template: '<a><slot /></a>' },
8387
// Stub v-navigation-drawer to a plain wrapper — the real one needs a <v-layout> ancestor
8488
'v-navigation-drawer': { template: '<div class="v-navigation-drawer"><slot /><slot name="append" /></div>' },
89+
// Stub the gauge to prevent it from auto-fetching billing data on mount
90+
BillingNavComputeGaugeComponent: { template: '<div class="stub-billing-nav-compute-gauge" />' },
91+
...stubsOverride,
8592
},
8693
},
8794
});
@@ -231,6 +238,8 @@ describe('core.navigation.component — compute gauge slot', () => {
231238
setActivePinia(createPinia());
232239
coreStoreState.nav = [];
233240
coreStoreState.navBottom = [];
241+
// Reset auth state to default (no billing) so tests are independent
242+
authStoreState.serverConfig = { organizations: { enabled: false } };
234243
});
235244

236245
it('meterMode computed returns false when serverConfig has no billing.meterMode', () => {
@@ -294,6 +303,15 @@ describe('core.navigation.component — compute gauge slot', () => {
294303
expect(signOutPos).toBeGreaterThan(accountPos);
295304
expect(signOutPos).toBeGreaterThan(settingsPos);
296305
});
306+
307+
it('renders stubbed BillingNavComputeGaugeComponent when meterMode is true', () => {
308+
// Override auth state so meterMode resolves to true for this test only.
309+
// beforeEach resets it back to the default (no billing key) for subsequent tests.
310+
authStoreState.serverConfig = { organizations: { enabled: false }, billing: { meterMode: true } };
311+
const wrapper = mountNav();
312+
expect(wrapper.vm.meterMode).toBe(true);
313+
expect(wrapper.find('.stub-billing-nav-compute-gauge').exists()).toBe(true);
314+
});
297315
});
298316

299317
describe('core.navigation.component — sidenav logo', () => {

0 commit comments

Comments
 (0)