-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvitest.setup.mts
More file actions
86 lines (79 loc) · 3.6 KB
/
Copy pathvitest.setup.mts
File metadata and controls
86 lines (79 loc) · 3.6 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
import { beforeAll, beforeEach, vi } from 'vitest';
import { setActivePinia, createPinia } from 'pinia';
import { config, RouterLinkStub } from '@vue/test-utils';
// silencing the warning everywhere.
config.global.stubs.RouterLink = RouterLinkStub;
// The url names tests assert on, at the paths Django really serves them from,
// so an expected url in a test reads like the one in the browser. Anything not
// listed falls through to the Proxy below.
const urls: Record<string, unknown> = {
api_process_requirements: (id: string) =>
`/bcap/api/process_requirement/${id}`,
api_resource: (graphSlug: string, id: string) =>
`/bcap/api/resource/${graphSlug}/${id}`,
api_resource_blank: (graphSlug: string) =>
`/bcap/api/resource/${graphSlug}/blank`,
api_site_related_resources: (graphSlug: string, id: string) =>
`/bcap/api/arch_site_related_resources/${graphSlug}/${id}`,
api_workflow_draft: (graphSlug: string) =>
`/bcap/api/workflow_draft/${graphSlug}`,
api_workflow_draft_all: '/bcap/api/workflow_draft',
assignable_contributors: '/bcap/api/contributors/assignable',
assignable_groups: '/bcap/api/assignable_groups',
bcap_message_detail: (messageId: string) =>
`/bcap/api/bcap_message/${messageId}`,
bcap_message_resource_threads: (resourceId: string) =>
`/bcap/api/bcap_message/resource/${resourceId}/threads`,
bcap_message_thread_messages: (threadId: string) =>
`/bcap/api/bcap_message/thread/${threadId}`,
dashboard: '/bcap/api/dashboard',
dashboard_external: '/bcap/api/dashboard/external',
module_requirement: (
permitId: string,
moduleTileId: string,
requirementId: string,
) =>
`/bcap/api/permit_application/${permitId}/module/${moduleTileId}/requirement/${requirementId}`,
permit_application_create: '/bcap/api/permit_application',
plugin: (slug: string) => `/plugins/${slug}`,
registration_link: '/bcap/api/registration_link',
seed_process_requirements: (permitId: string, permitType: string) =>
`/bcap/api/permit_application/${permitId}/process_requirement/${permitType}`,
unlinked_contributors: '/bcap/api/unlinked_contributors',
};
beforeAll(() => {
// routes.ts (and others) call arches.urls.<name>(...) at import time, so the
// stub needs a urls object. Unnamed urls fall back to a path built from the
// arguments, so a module only transitively imported doesn't crash.
vi.mock('arches', () => ({
default: {
urls: new Proxy(urls, {
get: (target, name: string) =>
target[name] ??
((...args: string[]) => '/' + args.join('/')),
}),
},
}));
vi.mock('vue3-gettext', () => ({
useGettext: () => ({
$gettext: (text: string) => text,
}),
}));
// The component lab ships these as .ts constants a mounted widget reads at
// import time. Stubbed so tests don't pull the package's build in for them.
vi.mock('@/arches_component_lab/widgets/constants.ts', () => ({
EDIT: 'edit',
VIEW: 'view',
CONFIGURE: 'configure',
}));
// The component lab's tsconfig has a broken extends that crashes the esbuild
// transform, so the real widget can never be loaded here. A test that needs
// it to behave (emit, render a label) mocks it again with the behaviour.
vi.mock(
'@/arches_component_lab/generics/GenericWidget/GenericWidget.vue',
() => ({ default: { name: 'GenericWidget', template: '<div />' } }),
);
});
beforeEach(() => {
setActivePinia(createPinia());
});