import { config } from '@vue/test-utils'; import { vi } from 'vitest'; // Make Math.random deterministic for stable snapshots (e.g., IDs in components) vi.spyOn(Math, 'random').mockReturnValue(0.123456789); // Stub SVG component imports to avoid verbose path data in snapshots const SvgStub = { template: 'SVG Stub', }; vi.mock('@/assets/images/logo-header.svg?component', () => ({ default: SvgStub, })); vi.mock('@/assets/images/login-company-logo.svg?component', () => ({ default: SvgStub, })); vi.mock('@/assets/images/built-on-openbmc-logo.svg?component', () => ({ default: SvgStub, })); // Mock vue-router - provide a minimal API for tests that import it vi.mock('vue-router', () => ({ createRouter: () => ({}), createMemoryHistory: () => ({}), useRouter: () => ({ push: vi.fn(), replace: vi.fn(), }), useRoute: () => ({ params: {}, query: {}, meta: { title: '' }, }), })); // Use the real i18n instance - Vite's import.meta.glob works natively import i18n from '@/i18n'; // Provide default global mocks/stubs config.global.mocks = { $t: (k) => k, $route: { meta: { title: '' } }, $eventBus: { on: () => {}, off: () => {}, emit: () => {}, $on: () => {}, $off: () => {}, $emit: () => {}, }, }; // Stubs with single root elements to properly inherit attributes like data-test-id config.global.stubs = { 'router-link': { template: '' }, 'b-navbar': { template: '' }, 'b-navbar-brand': { template: '
' }, 'b-navbar-nav': { template: '
' }, 'b-dropdown': { template: '
' }, 'b-dropdown-item': { template: '
' }, 'b-nav': { template: '' }, 'b-nav-item': { template: '
  • ' }, 'b-collapse': { template: '' }, 'b-button': { template: '' }, 'b-input-group': { template: '
    ' }, 'b-input-group-prepend': { template: '
    ', }, 'b-input-group-text': { template: '', }, 'b-form-group': { template: '
    ' }, 'b-form-input': { template: '' }, 'b-form-checkbox': { template: '
    ' }, 'b-form-radio': { template: '
    ' }, 'b-form-select': { template: '' }, 'b-progress': { template: '
    ' }, 'b-progress-bar': { template: '
    ' }, 'b-modal': { template: '' }, 'b-tooltip': { template: '
    ' }, }; // Provide plugins - i18n for useI18n() support, and $root helpers config.global.plugins = [ i18n, { install(app) { app.config.globalProperties.$root = app.config.globalProperties.$root || {}; if (!app.config.globalProperties.$root.$on) { app.config.globalProperties.$root.$on = () => {}; } if (!app.config.globalProperties.$root.$emit) { app.config.globalProperties.$root.$emit = () => {}; } app.mixin({ beforeCreate() { const r = this.$root; if (r && !r.$on) r.$on = () => {}; if (r && !r.$emit) r.$emit = () => {}; }, }); }, }, ]; // Stub bootstrap-vue directives config.global.directives = { 'b-tooltip': () => {}, 'b-toggle': () => {}, };