blob: bcba2c604094c1d5949e8c4f231d62ebbd309fbd [file] [log] [blame]
jason westover313d15c2025-08-18 17:16:01 -05001import { config } from '@vue/test-utils';
Jason Westovere5b9cca2026-01-08 10:57:41 -06002import { vi } from 'vitest';
jason westover313d15c2025-08-18 17:16:01 -05003
4// Make Math.random deterministic for stable snapshots (e.g., IDs in components)
Jason Westovere5b9cca2026-01-08 10:57:41 -06005vi.spyOn(Math, 'random').mockReturnValue(0.123456789);
jason westover313d15c2025-08-18 17:16:01 -05006
Jason Westovere5b9cca2026-01-08 10:57:41 -06007// Stub SVG component imports to avoid verbose path data in snapshots
8const SvgStub = {
9 template: '<svg data-testid="svg-stub"><title>SVG Stub</title></svg>',
10};
11vi.mock('@/assets/images/logo-header.svg?component', () => ({
12 default: SvgStub,
13}));
14vi.mock('@/assets/images/login-company-logo.svg?component', () => ({
15 default: SvgStub,
16}));
17vi.mock('@/assets/images/built-on-openbmc-logo.svg?component', () => ({
18 default: SvgStub,
jason westover313d15c2025-08-18 17:16:01 -050019}));
20
Jason Westovere5b9cca2026-01-08 10:57:41 -060021// Mock vue-router - provide a minimal API for tests that import it
22vi.mock('vue-router', () => ({
23 createRouter: () => ({}),
24 createMemoryHistory: () => ({}),
25 useRouter: () => ({
26 push: vi.fn(),
27 replace: vi.fn(),
28 }),
29 useRoute: () => ({
30 params: {},
31 query: {},
32 meta: { title: '' },
33 }),
34}));
jason westover313d15c2025-08-18 17:16:01 -050035
Jason Westovere5b9cca2026-01-08 10:57:41 -060036// Use the real i18n instance - Vite's import.meta.glob works natively
37import i18n from '@/i18n';
jason westover313d15c2025-08-18 17:16:01 -050038
39// Provide default global mocks/stubs
40config.global.mocks = {
41 $t: (k) => k,
42 $route: { meta: { title: '' } },
43 $eventBus: {
44 on: () => {},
45 off: () => {},
46 emit: () => {},
47 $on: () => {},
48 $off: () => {},
49 $emit: () => {},
50 },
51};
52
53// Stubs with single root elements to properly inherit attributes like data-test-id
54config.global.stubs = {
55 'router-link': { template: '<a><slot/></a>' },
56 'b-navbar': { template: '<nav><slot/></nav>' },
57 'b-navbar-brand': { template: '<div><slot/></div>' },
58 'b-navbar-nav': { template: '<div><slot/></div>' },
59 'b-dropdown': { template: '<div><slot/></div>' },
60 'b-dropdown-item': { template: '<div><slot/></div>' },
61 'b-nav': { template: '<ul class="nav mb-4 flex-column"><slot/></ul>' },
62 'b-nav-item': { template: '<li><slot/></li>' },
63 'b-collapse': { template: '<ul><slot/></ul>' },
64 'b-button': { template: '<button><slot/></button>' },
65 'b-input-group': { template: '<div class="input-group"><slot/></div>' },
66 'b-input-group-prepend': {
67 template: '<div class="input-group-prepend"><slot/></div>',
68 },
69 'b-input-group-text': {
70 template: '<span class="input-group-text"><slot/></span>',
71 },
72 'b-form-group': { template: '<div class="form-group mb-2"><slot/></div>' },
73 'b-form-input': { template: '<input class="form-control search-input" />' },
74 'b-form-checkbox': { template: '<div class="form-check"><slot/></div>' },
75 'b-form-radio': { template: '<div class="form-check"><slot/></div>' },
76 'b-form-select': { template: '<select><slot/></select>' },
77 'b-progress': { template: '<div class="progress"><slot/></div>' },
78 'b-progress-bar': { template: '<div class="progress-bar"></div>' },
79 'b-modal': { template: '<div class="modal"><slot/></div>' },
80 'b-tooltip': { template: '<div><slot/></div>' },
81};
82
83// Provide plugins - i18n for useI18n() support, and $root helpers
84config.global.plugins = [
Jason Westovere5b9cca2026-01-08 10:57:41 -060085 i18n,
jason westover313d15c2025-08-18 17:16:01 -050086 {
87 install(app) {
jason westover313d15c2025-08-18 17:16:01 -050088 app.config.globalProperties.$root =
89 app.config.globalProperties.$root || {};
90 if (!app.config.globalProperties.$root.$on) {
91 app.config.globalProperties.$root.$on = () => {};
92 }
93 if (!app.config.globalProperties.$root.$emit) {
94 app.config.globalProperties.$root.$emit = () => {};
95 }
96 app.mixin({
97 beforeCreate() {
98 const r = this.$root;
99 if (r && !r.$on) r.$on = () => {};
100 if (r && !r.$emit) r.$emit = () => {};
101 },
102 });
103 },
104 },
105];
106
107// Stub bootstrap-vue directives
108config.global.directives = {
109 'b-tooltip': () => {},
110 'b-toggle': () => {},
111};