1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
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 data-testid="svg-stub"><title>SVG Stub</title></svg>',
};
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: '<a><slot/></a>' },
'b-navbar': { template: '<nav><slot/></nav>' },
'b-navbar-brand': { template: '<div><slot/></div>' },
'b-navbar-nav': { template: '<div><slot/></div>' },
'b-dropdown': { template: '<div><slot/></div>' },
'b-dropdown-item': { template: '<div><slot/></div>' },
'b-nav': { template: '<ul class="nav mb-4 flex-column"><slot/></ul>' },
'b-nav-item': { template: '<li><slot/></li>' },
'b-collapse': { template: '<ul><slot/></ul>' },
'b-button': { template: '<button><slot/></button>' },
'b-input-group': { template: '<div class="input-group"><slot/></div>' },
'b-input-group-prepend': {
template: '<div class="input-group-prepend"><slot/></div>',
},
'b-input-group-text': {
template: '<span class="input-group-text"><slot/></span>',
},
'b-form-group': { template: '<div class="form-group mb-2"><slot/></div>' },
'b-form-input': { template: '<input class="form-control search-input" />' },
'b-form-checkbox': { template: '<div class="form-check"><slot/></div>' },
'b-form-radio': { template: '<div class="form-check"><slot/></div>' },
'b-form-select': { template: '<select><slot/></select>' },
'b-progress': { template: '<div class="progress"><slot/></div>' },
'b-progress-bar': { template: '<div class="progress-bar"></div>' },
'b-modal': { template: '<div class="modal"><slot/></div>' },
'b-tooltip': { template: '<div><slot/></div>' },
};
// 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': () => {},
};
|