-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Expand file tree
/
Copy pathtest-utils.ts
More file actions
88 lines (81 loc) · 2.36 KB
/
test-utils.ts
File metadata and controls
88 lines (81 loc) · 2.36 KB
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
import NotificationcenterPlugin from '@stekoe/vue-toast-notificationcenter';
import { RenderResult, render as tlRender } from '@testing-library/vue';
import { RouterLinkStub } from '@vue/test-utils';
import { merge } from 'lodash-es';
import PrimeVue from 'primevue/config';
import Tooltip from 'primevue/tooltip';
import { createI18n } from 'vue-i18n';
import { createRouter, createWebHashHistory } from 'vue-router';
import components from './components/index';
import SbaModalPlugin from './plugins/modal';
import { createViewRegistry } from '@/composables/ViewRegistry';
import ViewRegistry from '@/viewRegistry';
let terms = {};
const modules: Record<string, any> = import.meta.glob('@/**/i18n.en.json', {
eager: true,
});
for (const modulesKey in modules) {
const moduleContent = modules[modulesKey].default || modules[modulesKey];
terms = { ...terms, ...moduleContent };
}
export let router;
createViewRegistry();
export const render = (testComponent, options?): RenderResult => {
const routes = [{ path: '/', component: testComponent }];
if (testComponent.install) {
const viewRegistry = new ViewRegistry();
testComponent.install({ viewRegistry });
const routeForComponent = viewRegistry._toRoutes(() => true)[0];
routes.push({
...routeForComponent,
path: '/' + routeForComponent.path,
});
}
router = createRouter({
history: createWebHashHistory(),
routes: routes,
});
const renderOptions = merge(
{
global: {
plugins: [
router,
createI18n({
locale: options?.locale || 'en',
messages: {
en: terms,
},
legacy: false,
fallbackWarn: false,
missingWarn: false,
}),
NotificationcenterPlugin,
SbaModalPlugin,
[
PrimeVue,
{
theme: {
options: {
darkModeSelector: false,
},
},
},
],
components,
],
directives: {
tooltip: Tooltip,
},
stubs: {
RouterLink: RouterLinkStub,
'sba-exchanges-chart': true,
'font-awesome-icon': {
template: '<svg data-testid="icon" />',
},
},
},
},
options,
);
return tlRender(testComponent, renderOptions);
};