@antcde/component-library 0.1.14-rc.f66cf15 → 0.1.14-rc.fd98dae

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/README.md +2 -2
  2. package/dist/index.js +40068 -35097
  3. package/dist/types/src/components/AntTourZone/_TourInfoCard.vue.d.ts +18 -0
  4. package/dist/types/src/components/AntTourZone/_TourRing.vue.d.ts +15 -0
  5. package/dist/types/src/components/AntTourZone/index.vue.d.ts +49 -0
  6. package/dist/types/{components → src/components}/BaseAntDatePicker.vue.d.ts +2 -0
  7. package/dist/types/{components → src/components}/BaseDeleteDialog.vue.d.ts +8 -1
  8. package/dist/types/src/components/DmsFilePicker/composables/usePickerNavigation.d.ts +196 -0
  9. package/dist/types/src/components/DmsFilePicker/composables/usePickerUpload.d.ts +22 -0
  10. package/dist/types/src/components/DmsFilePicker/index.vue.d.ts +28 -0
  11. package/dist/types/src/components/DmsFilePicker/utils/fileFormatting.d.ts +6 -0
  12. package/dist/types/src/components/FilePreviewContent/index.vue.d.ts +31 -0
  13. package/dist/types/src/components/FlowWindowContent/index.vue.d.ts +51 -0
  14. package/dist/types/src/components/RichTextEditor/index.vue.d.ts +51 -0
  15. package/dist/types/{components → src/components}/StackedLabels/_LabelsMenuCard.vue.d.ts +1 -1
  16. package/dist/types/src/components/TasksFlow/components/_FlowBreadcrumb.vue.d.ts +17 -0
  17. package/dist/types/src/components/TasksFlow/components/_FlowEdgeConditionsDialog.vue.d.ts +10 -0
  18. package/dist/types/{components/TasksFlow/components/nodes/_triggerNode.vue.d.ts → src/components/TasksFlow/components/_FlowSearch.vue.d.ts} +4 -3
  19. package/dist/types/src/components/TasksFlow/components/_FlowStats.vue.d.ts +5 -0
  20. package/dist/types/src/components/TasksFlow/components/_FlowToolbar.vue.d.ts +26 -0
  21. package/dist/types/src/components/TasksFlow/components/_FlowTriggerMenu.vue.d.ts +17 -0
  22. package/dist/types/src/components/TasksFlow/components/_FlowVersionBar.vue.d.ts +12 -0
  23. package/dist/types/src/components/TasksFlow/components/_InsertTemplateDialog.vue.d.ts +17 -0
  24. package/dist/types/src/components/TasksFlow/components/_SubflowPanel.vue.d.ts +33 -0
  25. package/dist/types/src/components/TasksFlow/components/_VersionDiffView.vue.d.ts +14 -0
  26. package/dist/types/src/components/TasksFlow/components/_VersionPublishDialog.vue.d.ts +14 -0
  27. package/dist/types/src/components/TasksFlow/components/_flowEditor.vue.d.ts +13 -0
  28. package/dist/types/src/components/TasksFlow/components/nodes/_DurationEditor.vue.d.ts +33 -0
  29. package/dist/types/src/components/TasksFlow/components/nodes/_NodeContextMenu.vue.d.ts +35 -0
  30. package/dist/types/src/components/TasksFlow/components/nodes/_NodeMeta.vue.d.ts +14 -0
  31. package/dist/types/src/components/TasksFlow/components/nodes/_UserPicker.vue.d.ts +32 -0
  32. package/dist/types/{components → src/components}/TasksFlow/components/nodes/_taskNode.vue.d.ts +2 -2
  33. package/dist/types/src/components/TasksFlow/components/nodes/_triggerNode.vue.d.ts +10 -0
  34. package/dist/types/src/components/TasksFlow/components/nodes/useTaskNodeState.d.ts +86 -0
  35. package/dist/types/src/components/TasksFlow/composables/useAutoLayout.d.ts +22 -0
  36. package/dist/types/src/components/TasksFlow/composables/useCriticalPath.d.ts +8 -0
  37. package/dist/types/src/components/TasksFlow/composables/useFlowAutoLayout.d.ts +12 -0
  38. package/dist/types/src/components/TasksFlow/composables/useFlowCache.d.ts +17 -0
  39. package/dist/types/src/components/TasksFlow/composables/useFlowCrud.d.ts +21 -0
  40. package/dist/types/src/components/TasksFlow/composables/useFlowEditor.d.ts +54 -0
  41. package/dist/types/src/components/TasksFlow/composables/useFlowFetch.d.ts +33 -0
  42. package/dist/types/src/components/TasksFlow/composables/useFlowKeyboard.d.ts +15 -0
  43. package/dist/types/src/components/TasksFlow/composables/useFlowNotifications.d.ts +15 -0
  44. package/dist/types/src/components/TasksFlow/composables/useFlowOperations.d.ts +8 -0
  45. package/dist/types/src/components/TasksFlow/composables/useFlowRealtime.d.ts +23 -0
  46. package/dist/types/src/components/TasksFlow/composables/useFlowSearch.d.ts +14 -0
  47. package/dist/types/src/components/TasksFlow/composables/useFlowSubflows.d.ts +22 -0
  48. package/dist/types/src/components/TasksFlow/composables/useFlowUsers.d.ts +27 -0
  49. package/dist/types/src/components/TasksFlow/composables/useFlowViewport.d.ts +28 -0
  50. package/dist/types/src/components/TasksFlow/composables/useTaskFlow.d.ts +321 -0
  51. package/dist/types/{components → src/components}/TasksFlow/composables/useTaskFlowDragDrop.d.ts +0 -1
  52. package/dist/types/src/components/TasksFlow/composables/useTaskFlowEdgeConditions.d.ts +10 -0
  53. package/dist/types/src/components/TasksFlow/composables/useTaskFlowEdges.d.ts +18 -0
  54. package/dist/types/src/components/TasksFlow/composables/useTaskFlowMappers.d.ts +4 -0
  55. package/dist/types/src/components/TasksFlow/composables/useTaskFlowTypes.d.ts +76 -0
  56. package/dist/types/src/components/TasksFlow/composables/useTemplateVersioning.d.ts +188 -0
  57. package/dist/types/src/components/TasksFlow/composables/useTemplateVersioningState.d.ts +176 -0
  58. package/dist/types/src/components/TasksFlow/composables/useTriggerExecution.d.ts +21 -0
  59. package/dist/types/src/components/TasksFlow/index.vue.d.ts +39 -0
  60. package/dist/types/src/components/UnifiedWindow/index.vue.d.ts +67 -0
  61. package/dist/types/src/components/UnifiedWindow/useWindowDrag.d.ts +28 -0
  62. package/dist/types/src/components/VersionPublishDialog.vue.d.ts +24 -0
  63. package/dist/types/{index.d.ts → src/index.d.ts} +12 -1
  64. package/lib/GisViewer/GisViewer.vue +3 -2
  65. package/lib/build/layer-order.css +33 -0
  66. package/lib/build/uno.ts +117 -0
  67. package/lib/build/vite.ts +117 -0
  68. package/lib/build/vuetify-overrides.css +14 -0
  69. package/lib/build/vuetify.ts +230 -0
  70. package/lib/test/TESTING.claude.md +225 -0
  71. package/lib/test/createMockAppContext.ts +211 -0
  72. package/lib/test/createTestPinia.ts +31 -0
  73. package/lib/test/createTestRouter.ts +31 -0
  74. package/lib/test/index.ts +41 -0
  75. package/lib/test/mockVueRouter.ts +93 -0
  76. package/lib/test/mocks/createMockApi.ts +43 -0
  77. package/lib/test/mocks/createMockContext.ts +109 -0
  78. package/lib/test/mocks/createMockSignal.ts +30 -0
  79. package/lib/test/mocks/createMockUser.ts +87 -0
  80. package/lib/test/mocks/index.ts +11 -0
  81. package/lib/test/mountApp.ts +47 -0
  82. package/lib/test/mountWithContext.ts +94 -0
  83. package/lib/test/setup.ts +151 -0
  84. package/lib/test/testAppSetup.ts +115 -0
  85. package/lib/test/vitest.ts +69 -0
  86. package/package.json +135 -37
  87. package/dist/types/components/TasksFlow/components/_flowEditor.vue.d.ts +0 -16
  88. package/dist/types/components/TasksFlow/composables/useTaskFlow.d.ts +0 -103
  89. package/dist/types/components/TasksFlow/index.vue.d.ts +0 -51
  90. /package/dist/types/{components → src/components}/BaseAntButton.vue.d.ts +0 -0
  91. /package/dist/types/{components → src/components}/BaseAntCard.vue.d.ts +0 -0
  92. /package/dist/types/{components → src/components}/BaseAntCreateCard.vue.d.ts +0 -0
  93. /package/dist/types/{components → src/components}/BaseAntInput.vue.d.ts +0 -0
  94. /package/dist/types/{components → src/components}/BaseAntLoading.vue.d.ts +0 -0
  95. /package/dist/types/{components → src/components}/BaseAppCard.vue.d.ts +0 -0
  96. /package/dist/types/{components → src/components}/BaseAppCardSkeleton.vue.d.ts +0 -0
  97. /package/dist/types/{components → src/components}/BaseClickableIcon.vue.d.ts +0 -0
  98. /package/dist/types/{components → src/components}/BaseConfirmDialog.vue.d.ts +0 -0
  99. /package/dist/types/{components → src/components}/BaseDialog.vue.d.ts +0 -0
  100. /package/dist/types/{components → src/components}/BaseLimitedButton.vue.d.ts +0 -0
  101. /package/dist/types/{components → src/components}/BaseResizePanel.vue.d.ts +0 -0
  102. /package/dist/types/{components → src/components}/BulkLabelsMenu.vue.d.ts +0 -0
  103. /package/dist/types/{components → src/components}/GlobalLabelBadge.vue.d.ts +0 -0
  104. /package/dist/types/{components → src/components}/RBAC/Permissions/PermissionCard.vue.d.ts +0 -0
  105. /package/dist/types/{components → src/components}/StackedLabels/index.vue.d.ts +0 -0
  106. /package/dist/types/{components → src/components}/TasksFlow/components/_dropzoneBackground.vue.d.ts +0 -0
  107. /package/dist/types/{components → src/components}/TasksFlow/components/_flowEdge.vue.d.ts +0 -0
@@ -0,0 +1,31 @@
1
+ import type { TestingOptions, TestingPinia } from '@pinia/testing'
2
+ import { createTestingPinia } from '@pinia/testing'
3
+
4
+ /**
5
+ * Thin wrapper around `@pinia/testing`'s `createTestingPinia` with sensible defaults
6
+ * for component tests.
7
+ *
8
+ * Default `stubActions: false` keeps real action behavior — better for typical dialog
9
+ * and page tests that exercise full flows. Pass `stubActions: true` to spy without
10
+ * executing.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { createTestPinia, mountWithContext } from '@antcde/component-library/test'
15
+ *
16
+ * const pinia = createTestPinia()
17
+ * mountWithContext(MyComponent, { pinia })
18
+ *
19
+ * // With initial state and stubbed actions
20
+ * const pinia = createTestPinia({
21
+ * initialState: { auth: { user: { id: '1' } } },
22
+ * stubActions: true,
23
+ * })
24
+ * ```
25
+ */
26
+ export function createTestPinia(options: TestingOptions = {}): TestingPinia {
27
+ return createTestingPinia({
28
+ stubActions: false,
29
+ ...options,
30
+ })
31
+ }
@@ -0,0 +1,31 @@
1
+ import type { Router, RouteRecordRaw, RouterOptions } from 'vue-router'
2
+ import { createMemoryHistory, createRouter } from 'vue-router'
3
+
4
+ /**
5
+ * Creates a real `vue-router` instance backed by `createMemoryHistory()` for tests.
6
+ *
7
+ * Default `routes` is empty — fine for tests that just need `useRouter().push()` not
8
+ * to throw. Pass routes when navigation matters.
9
+ *
10
+ * **Always `await router.isReady()` after mounting** before asserting on rendered
11
+ * route components — initial navigation is async.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { createTestRouter, mountWithContext } from '@antcde/component-library/test'
16
+ *
17
+ * const router = createTestRouter([{ path: '/', component: HomePage }])
18
+ * const { wrapper } = mountWithContext(App, { router })
19
+ * await router.isReady()
20
+ * ```
21
+ */
22
+ export function createTestRouter(
23
+ routes: RouteRecordRaw[] = [],
24
+ options: Omit<RouterOptions, 'history' | 'routes'> = {},
25
+ ): Router {
26
+ return createRouter({
27
+ history: createMemoryHistory(),
28
+ routes,
29
+ ...options,
30
+ })
31
+ }
@@ -0,0 +1,41 @@
1
+ export { createMockAppContext, createTranslator, useApiMock } from './createMockAppContext'
2
+
3
+ export type { MockAppContext, MockColorMode } from './createMockAppContext'
4
+
5
+ export { createTestPinia } from './createTestPinia'
6
+
7
+ export { createTestRouter } from './createTestRouter'
8
+
9
+ export {
10
+ createMockApi,
11
+ createMockApiMap,
12
+ createMockContext,
13
+ createMockLicense,
14
+ createMockProject,
15
+ createMockSignal,
16
+ createMockTask,
17
+ createMockUser,
18
+ } from './mocks'
19
+
20
+ export type {
21
+ ApiMockMap,
22
+ MockApiReturn,
23
+ MockApiState,
24
+ MockContext,
25
+ MockSignalReturn,
26
+ UserPreset,
27
+ } from './mocks'
28
+ export { mockVueRouter } from './mockVueRouter'
29
+
30
+ export type { MockVueRouterOverrides } from './mockVueRouter'
31
+ export { mountApp } from './mountApp'
32
+
33
+ export type { MountAppOptions } from './mountApp'
34
+
35
+ export { mountWithContext } from './mountWithContext'
36
+ export type { MountWithContextOptions } from './mountWithContext'
37
+
38
+ export { createTestI18n } from './setup'
39
+
40
+ export { testAppSetup } from './testAppSetup'
41
+ export type { TestAppSetupOptions } from './testAppSetup'
@@ -0,0 +1,93 @@
1
+ import { vi } from 'vitest'
2
+
3
+ interface MockRouterMethods {
4
+ push?: ReturnType<typeof vi.fn>
5
+ replace?: ReturnType<typeof vi.fn>
6
+ back?: ReturnType<typeof vi.fn>
7
+ forward?: ReturnType<typeof vi.fn>
8
+ go?: ReturnType<typeof vi.fn>
9
+ beforeEach?: ReturnType<typeof vi.fn>
10
+ afterEach?: ReturnType<typeof vi.fn>
11
+ }
12
+
13
+ interface MockRoute {
14
+ path?: string
15
+ name?: string | symbol | undefined
16
+ fullPath?: string
17
+ query?: Record<string, string | string[] | undefined>
18
+ params?: Record<string, string | string[]>
19
+ hash?: string
20
+ meta?: Record<string, unknown>
21
+ matched?: unknown[]
22
+ redirectedFrom?: unknown
23
+ }
24
+
25
+ export interface MockVueRouterOverrides {
26
+ /** Partial overrides for `useRouter()` methods. Pass your own `vi.fn()` to assert calls. */
27
+ useRouter?: MockRouterMethods
28
+ /**
29
+ * Override for `useRoute()`. Pass an object for a static snapshot, or a function for
30
+ * live values that should re-read on every `useRoute()` call (e.g. when a closure
31
+ * variable changes between tests).
32
+ */
33
+ useRoute?: MockRoute | (() => MockRoute)
34
+ }
35
+
36
+ /**
37
+ * Builds a module-shape object for `vi.mock('vue-router', () => mockVueRouter(overrides))`.
38
+ * Stubs `useRouter` and `useRoute` so tests can assert navigation calls without a real router.
39
+ *
40
+ * **Important:** wrap the call in an arrow function. `vi.mock` is hoisted to the top of
41
+ * the file, so a bare `vi.mock('vue-router', mockVueRouter(...))` would invoke
42
+ * `mockVueRouter` before its import is initialized.
43
+ *
44
+ * Defaults: `useRouter` returns no-op `vi.fn()` for push/replace/back/forward/go.
45
+ * `useRoute` returns `{ path: '/', query: {}, params: {}, fullPath: '/', hash: '', meta: {} }`.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * import { mockVueRouter } from '@antcde/component-library/test'
50
+ *
51
+ * const replace = vi.fn()
52
+ * vi.mock('vue-router', () => mockVueRouter({ useRouter: { replace } }))
53
+ *
54
+ * // Live route reads — function form re-reads on every useRoute() call:
55
+ * let routeQuery: Record<string, string> = {}
56
+ * vi.mock('vue-router', () => mockVueRouter({ useRoute: () => ({ query: routeQuery }) }))
57
+ * ```
58
+ */
59
+ export function mockVueRouter(overrides: MockVueRouterOverrides = {}) {
60
+ const routerMethods: Required<MockRouterMethods> = {
61
+ push: overrides.useRouter?.push ?? vi.fn(),
62
+ replace: overrides.useRouter?.replace ?? vi.fn(),
63
+ back: overrides.useRouter?.back ?? vi.fn(),
64
+ forward: overrides.useRouter?.forward ?? vi.fn(),
65
+ go: overrides.useRouter?.go ?? vi.fn(),
66
+ beforeEach: overrides.useRouter?.beforeEach ?? vi.fn(() => () => {}),
67
+ afterEach: overrides.useRouter?.afterEach ?? vi.fn(() => () => {}),
68
+ }
69
+
70
+ const baseRoute: MockRoute = {
71
+ path: '/',
72
+ name: undefined,
73
+ fullPath: '/',
74
+ query: {},
75
+ params: {},
76
+ hash: '',
77
+ meta: {},
78
+ matched: [],
79
+ redirectedFrom: undefined,
80
+ }
81
+
82
+ const resolveRoute = () => {
83
+ const r = typeof overrides.useRoute === 'function' ? overrides.useRoute() : overrides.useRoute
84
+ return { ...baseRoute, ...r }
85
+ }
86
+
87
+ return {
88
+ useRouter: () => routerMethods,
89
+ useRoute: () => resolveRoute(),
90
+ RouterLink: { name: 'RouterLink', template: '<a><slot /></a>' },
91
+ RouterView: { name: 'RouterView', template: '<div><slot /></div>' },
92
+ }
93
+ }
@@ -0,0 +1,43 @@
1
+ import { ref } from 'vue'
2
+
3
+ export interface MockApiState<T = any> {
4
+ state: T
5
+ isLoading?: boolean
6
+ isReady?: boolean
7
+ error?: unknown
8
+ }
9
+
10
+ export interface MockApiReturn<T = any> {
11
+ state: ReturnType<typeof ref<T>>
12
+ isLoading: ReturnType<typeof ref<boolean>>
13
+ isReady: ReturnType<typeof ref<boolean>>
14
+ error: ReturnType<typeof ref<unknown>>
15
+ execute: (...args: any[]) => Promise<T>
16
+ executeDelayed: (...args: any[]) => void
17
+ }
18
+
19
+ export function createMockApi<T>(initial: MockApiState<T>): MockApiReturn<T> {
20
+ const state = ref(initial.state) as ReturnType<typeof ref<T>>
21
+ const isLoading = ref(initial.isLoading ?? false)
22
+ const isReady = ref(initial.isReady ?? true)
23
+ const error = ref(initial.error ?? null)
24
+
25
+ return {
26
+ state,
27
+ isLoading,
28
+ isReady,
29
+ error,
30
+ execute: async (..._args: any[]) => state.value as T,
31
+ executeDelayed: () => {},
32
+ }
33
+ }
34
+
35
+ export type ApiMockMap = Record<string, MockApiState>
36
+
37
+ export function createMockApiMap(mocks: ApiMockMap): Map<string, MockApiReturn> {
38
+ const map = new Map<string, MockApiReturn>()
39
+ for (const [key, state] of Object.entries(mocks)) {
40
+ map.set(key, createMockApi(state))
41
+ }
42
+ return map
43
+ }
@@ -0,0 +1,109 @@
1
+ import type { License, Project, Task } from '@antcde/connect-ts'
2
+
3
+ export interface MockContext {
4
+ license: License | null
5
+ project: Project | null
6
+ task: Task | null
7
+ }
8
+
9
+ const BASE_LICENSE: License = {
10
+ id: 'license-1',
11
+ is_admin: true,
12
+ name: 'Test License',
13
+ type: 'enterprise',
14
+ company: 'company-1',
15
+ theme: '#125CFF',
16
+ url: 'http://localhost',
17
+ mfa_required: false,
18
+ user_is_admin: true,
19
+ labels: [],
20
+ limits: {},
21
+ user_permissions: {},
22
+ user_roles: [],
23
+ }
24
+
25
+ const BASE_PROJECT: Project = {
26
+ id: 'project-1',
27
+ name: 'Test Project',
28
+ number: '001',
29
+ slug: 'test-project',
30
+ image: null,
31
+ license: 'license-1',
32
+ is_favorite: false,
33
+ is_master: 0,
34
+ is_archive: false,
35
+ created_at: '2025-01-01T00:00:00.000000Z',
36
+ user_is_admin: true,
37
+ labels: [],
38
+ limits: {},
39
+ user_permissions: {},
40
+ user_roles: [],
41
+ }
42
+
43
+ const BASE_TASK: Task = {
44
+ id: 'task-1',
45
+ number: 1,
46
+ title: 'Test Task',
47
+ description: null,
48
+ status: 'open',
49
+ priority: 'normal',
50
+ progress: 0,
51
+ license: 'license-1',
52
+ project: 'project-1',
53
+ parent: undefined,
54
+ parent_task: null,
55
+ assigned_to: null,
56
+ assignable_users: null,
57
+ created_by: {
58
+ id: 'user-1',
59
+ email: 'test@example.com',
60
+ firstname: 'Test',
61
+ lastname: 'User',
62
+ name: 'Test User',
63
+ profile_picture: '',
64
+ },
65
+ created_at: '2025-01-01T00:00:00.000000Z',
66
+ task_project: null,
67
+ children: [],
68
+ labels: [],
69
+ relations: [],
70
+ sbscode: null,
71
+ sbs_record: null,
72
+ is_private: false,
73
+ is_task: true,
74
+ location: null,
75
+ script: null,
76
+ planned_start: null,
77
+ planned_end: null,
78
+ due: null,
79
+ task_type: null,
80
+ type: null,
81
+ hasChildren: false,
82
+ attachments: [],
83
+ rules: [],
84
+ position_x: 0,
85
+ position_y: 0,
86
+ app: null,
87
+ trigger_id: null,
88
+ trigger: null,
89
+ }
90
+
91
+ export function createMockLicense(overrides: Partial<License> = {}): License {
92
+ return { ...structuredClone(BASE_LICENSE), ...overrides }
93
+ }
94
+
95
+ export function createMockProject(overrides: Partial<Project> = {}): Project {
96
+ return { ...structuredClone(BASE_PROJECT), ...overrides }
97
+ }
98
+
99
+ export function createMockTask(overrides: Partial<Task> = {}): Task {
100
+ return { ...structuredClone(BASE_TASK), ...overrides }
101
+ }
102
+
103
+ export function createMockContext(overrides: Partial<MockContext> = {}): MockContext {
104
+ return {
105
+ license: overrides.license ?? createMockLicense(),
106
+ project: overrides.project ?? null,
107
+ task: overrides.task ?? null,
108
+ }
109
+ }
@@ -0,0 +1,30 @@
1
+ import type { Signal } from '@antcde/connect-ts'
2
+ import type { DeepReadonly, Ref } from 'vue'
3
+ import { readonly, ref } from 'vue'
4
+
5
+ export interface MockSignalReturn {
6
+ signal: DeepReadonly<Ref<Signal | undefined>>
7
+ emit: (signal: Signal) => void
8
+ history: Signal[]
9
+ sent: Signal[]
10
+ send: (signal: Signal) => void
11
+ }
12
+
13
+ export function createMockSignal(): MockSignalReturn {
14
+ const signal = ref<Signal | undefined>()
15
+ const history: Signal[] = []
16
+ const sent: Signal[] = []
17
+
18
+ return {
19
+ signal: readonly(signal),
20
+ emit(s: Signal) {
21
+ signal.value = s
22
+ history.push(s)
23
+ },
24
+ history,
25
+ sent,
26
+ send(s: Signal) {
27
+ sent.push(s)
28
+ },
29
+ }
30
+ }
@@ -0,0 +1,87 @@
1
+ import type { User } from '@antcde/connect-ts'
2
+
3
+ export type UserPreset = 'admin' | 'viewer' | 'editor'
4
+
5
+ const USER_PRESETS: Record<UserPreset, Partial<User>> = {
6
+ admin: {
7
+ is_admin: true,
8
+ licenses: [
9
+ {
10
+ id: 'license-1',
11
+ company: 'company-1',
12
+ name: 'Test License',
13
+ theme: '#125CFF',
14
+ is_admin: true,
15
+ mfa_required: false,
16
+ type: 'enterprise',
17
+ url: 'http://localhost',
18
+ user_is_admin: true,
19
+ labels: [],
20
+ limits: {},
21
+ },
22
+ ],
23
+ },
24
+ viewer: {
25
+ is_admin: false,
26
+ licenses: [
27
+ {
28
+ id: 'license-1',
29
+ company: 'company-1',
30
+ name: 'Test License',
31
+ theme: '#125CFF',
32
+ is_admin: false,
33
+ mfa_required: false,
34
+ type: 'starter',
35
+ url: 'http://localhost',
36
+ user_is_admin: false,
37
+ labels: [],
38
+ limits: {},
39
+ },
40
+ ],
41
+ },
42
+ editor: {
43
+ is_admin: false,
44
+ licenses: [
45
+ {
46
+ id: 'license-1',
47
+ company: 'company-1',
48
+ name: 'Test License',
49
+ theme: '#125CFF',
50
+ is_admin: false,
51
+ mfa_required: false,
52
+ type: 'professional',
53
+ url: 'http://localhost',
54
+ user_is_admin: false,
55
+ labels: [],
56
+ limits: {},
57
+ },
58
+ ],
59
+ },
60
+ }
61
+
62
+ const BASE_USER: User = {
63
+ id: 'user-1',
64
+ email: 'test@example.com',
65
+ name: 'Test User',
66
+ firstname: 'Test',
67
+ lastname: 'User',
68
+ language: 'en',
69
+ company_name: null,
70
+ licenses: [],
71
+ is_admin: false,
72
+ two_factor_enabled: 0,
73
+ photo: null,
74
+ profile_picture: null,
75
+ }
76
+
77
+ export function createMockUser(presetOrOverrides: UserPreset | Partial<User> = 'admin', overrides: Partial<User> = {}): User {
78
+ const preset = typeof presetOrOverrides === 'string'
79
+ ? USER_PRESETS[presetOrOverrides]
80
+ : presetOrOverrides
81
+
82
+ return {
83
+ ...structuredClone(BASE_USER),
84
+ ...structuredClone(preset),
85
+ ...structuredClone(overrides),
86
+ }
87
+ }
@@ -0,0 +1,11 @@
1
+ export { createMockApi, createMockApiMap } from './createMockApi'
2
+ export type { ApiMockMap, MockApiReturn, MockApiState } from './createMockApi'
3
+
4
+ export { createMockContext, createMockLicense, createMockProject, createMockTask } from './createMockContext'
5
+ export type { MockContext } from './createMockContext'
6
+
7
+ export { createMockSignal } from './createMockSignal'
8
+ export type { MockSignalReturn } from './createMockSignal'
9
+
10
+ export { createMockUser } from './createMockUser'
11
+ export type { UserPreset } from './createMockUser'
@@ -0,0 +1,47 @@
1
+ import type { MountingOptions } from '@vue/test-utils'
2
+ import type { Component, Plugin } from 'vue'
3
+ import { mount } from '@vue/test-utils'
4
+
5
+ export interface MountAppOptions {
6
+ props?: Record<string, any>
7
+ slots?: MountingOptions<any>['slots']
8
+ plugins?: Plugin[]
9
+ stubs?: Record<string, any>
10
+ global?: Omit<NonNullable<MountingOptions<any>['global']>, 'plugins' | 'stubs'>
11
+ }
12
+
13
+ /**
14
+ * Thin wrapper around `mount()` for iframe app component tests.
15
+ * Vuetify + i18n come from `config.global.plugins` (registered in `setup.ts`).
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { mountApp } from '@antcde/component-library/test'
20
+ * import Main from '@/components/Main.vue'
21
+ *
22
+ * const wrapper = mountApp(Main)
23
+ * const wrapper = mountApp(Main, { props: { id: '1' } })
24
+ * ```
25
+ */
26
+ export function mountApp(
27
+ component: Component,
28
+ options: MountAppOptions = {},
29
+ ) {
30
+ const {
31
+ props,
32
+ slots,
33
+ plugins = [],
34
+ stubs = {},
35
+ global: globalOverrides = {},
36
+ } = options
37
+
38
+ return mount(component, {
39
+ props,
40
+ slots,
41
+ global: {
42
+ plugins,
43
+ stubs: { Transition: false, TransitionGroup: false, ...stubs },
44
+ ...globalOverrides,
45
+ },
46
+ })
47
+ }
@@ -0,0 +1,94 @@
1
+ import type { MountingOptions } from '@vue/test-utils'
2
+ import type { App, Component, Plugin } from 'vue'
3
+ import type { MockAppContext } from './createMockAppContext'
4
+ import type { MockContext } from './mocks/createMockContext'
5
+ import type { UserPreset } from './mocks/createMockUser'
6
+ import { mount } from '@vue/test-utils'
7
+ import { createMockAppContext } from './createMockAppContext'
8
+ import { createMockLicense } from './mocks/createMockContext'
9
+ import { createMockUser } from './mocks/createMockUser'
10
+
11
+ export interface MountWithContextOptions {
12
+ user?: UserPreset | ReturnType<typeof createMockUser>
13
+ /** Domain context overrides (license/project/task). Used to build the default mock context. */
14
+ context?: Partial<MockContext>
15
+ /**
16
+ * Pre-built mock app context (from `createMockAppContext`). Provided under the
17
+ * `appContext` injection key so components calling `injectContext()` resolve it
18
+ * without needing a per-test `vi.mock('@/plugins/context')`.
19
+ */
20
+ mockContext?: MockAppContext
21
+ /** Pinia instance — typically from `createTestPinia()`. Opt-in. */
22
+ pinia?: Plugin
23
+ /** Router instance — typically from `createTestRouter()`. Opt-in. */
24
+ router?: Plugin
25
+ props?: Record<string, any>
26
+ slots?: MountingOptions<any>['slots']
27
+ stubs?: MountingOptions<any>['global'] extends { stubs?: infer S } ? S : never
28
+ mountOptions?: MountingOptions<any>
29
+ }
30
+
31
+ function provideAppContext(ctx: MockAppContext): Plugin {
32
+ return {
33
+ install(app: App) {
34
+ const value = { comms: ctx.comms, i18n: ctx.i18n, colorMode: ctx.colorMode }
35
+ // Matches `useSingleton('appContext', factory)` shape: inject(name)() returns the value.
36
+ app.provide<() => typeof value>('appContext', () => value)
37
+ },
38
+ }
39
+ }
40
+
41
+ export function mountWithContext(
42
+ component: Component,
43
+ options: MountWithContextOptions = {},
44
+ ) {
45
+ const {
46
+ user: userOption = 'admin',
47
+ context: contextOverrides = {},
48
+ mockContext,
49
+ pinia,
50
+ router,
51
+ props = {},
52
+ slots,
53
+ stubs = {},
54
+ mountOptions = {},
55
+ } = options
56
+
57
+ const user = typeof userOption === 'string'
58
+ ? createMockUser(userOption)
59
+ : userOption
60
+
61
+ const ctx = mockContext ?? createMockAppContext({
62
+ license: contextOverrides.license ?? createMockLicense({
63
+ is_admin: user.is_admin,
64
+ user_is_admin: user.is_admin,
65
+ }),
66
+ })
67
+
68
+ const plugins: Plugin[] = [provideAppContext(ctx)]
69
+ if (router)
70
+ plugins.unshift(router)
71
+ if (pinia)
72
+ plugins.unshift(pinia)
73
+
74
+ const wrapper = mount(component, {
75
+ props,
76
+ slots,
77
+ ...mountOptions,
78
+ global: {
79
+ plugins,
80
+ stubs: {
81
+ Transition: false,
82
+ TransitionGroup: false,
83
+ ...stubs,
84
+ },
85
+ ...mountOptions.global,
86
+ },
87
+ })
88
+
89
+ return {
90
+ wrapper,
91
+ user,
92
+ context: ctx,
93
+ }
94
+ }