@antcde/component-library 0.1.14 → 0.1.15

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 (108) 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 +104 -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 +227 -0
  71. package/lib/test/createMockAppContext.ts +212 -0
  72. package/lib/test/createMockConnect.ts +46 -0
  73. package/lib/test/createTestPinia.ts +31 -0
  74. package/lib/test/createTestRouter.ts +31 -0
  75. package/lib/test/index.ts +41 -0
  76. package/lib/test/mockVueRouter.ts +93 -0
  77. package/lib/test/mocks/createMockApi.ts +43 -0
  78. package/lib/test/mocks/createMockContext.ts +109 -0
  79. package/lib/test/mocks/createMockSignal.ts +30 -0
  80. package/lib/test/mocks/createMockUser.ts +87 -0
  81. package/lib/test/mocks/index.ts +11 -0
  82. package/lib/test/mountApp.ts +47 -0
  83. package/lib/test/mountWithContext.ts +94 -0
  84. package/lib/test/setup.ts +151 -0
  85. package/lib/test/testAppSetup.ts +110 -0
  86. package/lib/test/vitest.ts +69 -0
  87. package/package.json +135 -30
  88. package/dist/types/components/TasksFlow/components/_flowEditor.vue.d.ts +0 -16
  89. package/dist/types/components/TasksFlow/composables/useTaskFlow.d.ts +0 -103
  90. package/dist/types/components/TasksFlow/index.vue.d.ts +0 -51
  91. /package/dist/types/{components → src/components}/BaseAntButton.vue.d.ts +0 -0
  92. /package/dist/types/{components → src/components}/BaseAntCard.vue.d.ts +0 -0
  93. /package/dist/types/{components → src/components}/BaseAntCreateCard.vue.d.ts +0 -0
  94. /package/dist/types/{components → src/components}/BaseAntInput.vue.d.ts +0 -0
  95. /package/dist/types/{components → src/components}/BaseAntLoading.vue.d.ts +0 -0
  96. /package/dist/types/{components → src/components}/BaseAppCard.vue.d.ts +0 -0
  97. /package/dist/types/{components → src/components}/BaseAppCardSkeleton.vue.d.ts +0 -0
  98. /package/dist/types/{components → src/components}/BaseClickableIcon.vue.d.ts +0 -0
  99. /package/dist/types/{components → src/components}/BaseConfirmDialog.vue.d.ts +0 -0
  100. /package/dist/types/{components → src/components}/BaseDialog.vue.d.ts +0 -0
  101. /package/dist/types/{components → src/components}/BaseLimitedButton.vue.d.ts +0 -0
  102. /package/dist/types/{components → src/components}/BaseResizePanel.vue.d.ts +0 -0
  103. /package/dist/types/{components → src/components}/BulkLabelsMenu.vue.d.ts +0 -0
  104. /package/dist/types/{components → src/components}/GlobalLabelBadge.vue.d.ts +0 -0
  105. /package/dist/types/{components → src/components}/RBAC/Permissions/PermissionCard.vue.d.ts +0 -0
  106. /package/dist/types/{components → src/components}/StackedLabels/index.vue.d.ts +0 -0
  107. /package/dist/types/{components → src/components}/TasksFlow/components/_dropzoneBackground.vue.d.ts +0 -0
  108. /package/dist/types/{components → src/components}/TasksFlow/components/_flowEdge.vue.d.ts +0 -0
@@ -0,0 +1,230 @@
1
+ import type { FunctionalComponent } from 'vue'
2
+ import type { IconProps, VuetifyOptions } from 'vuetify'
3
+ import { Icon } from '@iconify/vue'
4
+ import { h } from 'vue'
5
+ import { createVuetify } from 'vuetify'
6
+ import 'vuetify/styles'
7
+ import 'virtual:uno.css'
8
+ // CSS patches for Vuetify quirks not expressible via theme/defaults.
9
+ import './vuetify-overrides.css'
10
+
11
+ /** ANT platform light theme colors — exported for apps that need to reference them in `themes` overrides (e.g. when adding a dark theme). */
12
+ export const ANT_COLORS = {
13
+ 'background': '#FFFFFF',
14
+ 'surface': '#FFFFFF',
15
+ 'surface-bright': '#FFFFFF',
16
+ 'surface-light': '#F5F5F5',
17
+ 'surface-variant': '#F1F5F9',
18
+ 'on-surface-variant': '#334155',
19
+ 'primary': '#125CFF',
20
+ 'primary-darken-1': '#0D47A1',
21
+ 'secondary': '#64748B',
22
+ 'secondary-darken-1': '#475569',
23
+ 'error': '#B00020',
24
+ 'info': '#2196F3',
25
+ 'success': '#4CAF50',
26
+ 'warning': '#FB8C00',
27
+ // Hairline border for outlined surfaces — ≈ rgba(0,0,0,0.10) on white.
28
+ // Registered as a theme color so component defaults resolve it per active
29
+ // theme (see `ANT_DARK_COLORS.hairline` for the dark equivalent).
30
+ 'hairline': '#E5E7EB',
31
+ } as const
32
+
33
+ /** ANT platform dark theme colors — exported for apps that need custom dark theme overrides. */
34
+ export const ANT_DARK_COLORS = {
35
+ 'background': '#121212',
36
+ 'surface': '#1E1E1E',
37
+ 'surface-bright': '#2C2C2C',
38
+ 'surface-light': '#252525',
39
+ 'surface-variant': '#1E293B',
40
+ 'on-surface-variant': '#CBD5E1',
41
+ 'primary': '#5C9AFF',
42
+ 'primary-darken-1': '#125CFF',
43
+ 'secondary': '#94A3B8',
44
+ 'secondary-darken-1': '#64748B',
45
+ 'error': '#CF6679',
46
+ 'info': '#64B5F6',
47
+ 'success': '#81C784',
48
+ 'warning': '#FFB74D',
49
+ // ≈ 10% white on dark surface (#1E1E1E) — subtle hairline that does not
50
+ // read as a bright visible line in dark mode.
51
+ 'hairline': '#2D2D2D',
52
+ } as const
53
+
54
+ /** Theme variables controlling opacity, borders, and interaction feedback. */
55
+ const ANT_VARIABLES = {
56
+ 'border-color': '#000000',
57
+ 'border-opacity': 0.12,
58
+ 'high-emphasis-opacity': 0.87,
59
+ 'medium-emphasis-opacity': 0.60,
60
+ 'disabled-opacity': 0.38,
61
+ 'idle-opacity': 0.04,
62
+ 'hover-opacity': 0.04,
63
+ 'focus-opacity': 0.12,
64
+ 'selected-opacity': 0.08,
65
+ 'activated-opacity': 0.12,
66
+ 'pressed-opacity': 0.12,
67
+ 'dragged-opacity': 0.08,
68
+ 'theme-kbd': '#212529',
69
+ 'theme-on-kbd': '#FFFFFF',
70
+ 'theme-code': '#F5F5F5',
71
+ 'theme-on-code': '#000000',
72
+ }
73
+
74
+ /** Dark theme variables — borders flip to white-based. */
75
+ const ANT_DARK_VARIABLES = {
76
+ 'border-color': '#FFFFFF',
77
+ 'border-opacity': 0.12,
78
+ 'high-emphasis-opacity': 0.87,
79
+ 'medium-emphasis-opacity': 0.60,
80
+ 'disabled-opacity': 0.38,
81
+ 'idle-opacity': 0.10,
82
+ 'hover-opacity': 0.04,
83
+ 'focus-opacity': 0.12,
84
+ 'selected-opacity': 0.08,
85
+ 'activated-opacity': 0.12,
86
+ 'pressed-opacity': 0.12,
87
+ 'dragged-opacity': 0.08,
88
+ 'theme-kbd': '#212529',
89
+ 'theme-on-kbd': '#FFFFFF',
90
+ 'theme-code': '#2C2C2C',
91
+ 'theme-on-code': '#CCCCCC',
92
+ }
93
+
94
+ /** ANT platform component defaults — exported for reference. */
95
+ export const ANT_DEFAULTS: VuetifyOptions['defaults'] = {
96
+ VAppBar: {
97
+ flat: true,
98
+ },
99
+ VToolbar: {
100
+ flat: true,
101
+ },
102
+ VNavigationDrawer: {
103
+ elevation: 0,
104
+ },
105
+ VCard: {
106
+ rounded: 'xl',
107
+ flat: true,
108
+ },
109
+ VCardTitle: {
110
+ style: 'white-space: break-spaces;',
111
+ },
112
+ VBtn: {
113
+ rounded: 'xl',
114
+ class: 'text-none',
115
+ },
116
+ VBtnToggle: {
117
+ rounded: 'xl',
118
+ },
119
+ VBtnGroup: {
120
+ rounded: 'xl',
121
+ },
122
+ VChip: {
123
+ rounded: 'xl',
124
+ },
125
+ // Form fields use `lg` (8px) — closest Vuetify scale to the 10px target shared
126
+ // with the storefront mockups. `xl` (24px) is reserved for cards/buttons/chips
127
+ // and looks oversized on inputs. Variant intentionally not set: keep whatever
128
+ // each call site declares (outlined / solo / plain / underlined).
129
+ VTextField: {
130
+ rounded: 'lg',
131
+ },
132
+ VSelect: {
133
+ rounded: 'lg',
134
+ },
135
+ VAutocomplete: {
136
+ rounded: 'lg',
137
+ },
138
+ VCombobox: {
139
+ rounded: 'lg',
140
+ },
141
+ VTextarea: {
142
+ rounded: 'lg',
143
+ },
144
+ VFileInput: {
145
+ rounded: 'lg',
146
+ },
147
+ }
148
+
149
+ /**
150
+ * Adapter from Vuetify's `IconProps` ({ icon: IconValue, tag, disabled }) to
151
+ * Iconify's `<Icon>` ({ icon: string }). Vuetify passes the resolved icon
152
+ * string for component-based sets, so we forward it directly. A thin wrapper
153
+ * is used instead of casting `Icon`, so the icon set conforms to Vuetify's
154
+ * `IconComponent` type (= `JSXComponent<IconProps>`) with no type assertions.
155
+ */
156
+ const IconifyAdapter: FunctionalComponent<IconProps> = (props) => {
157
+ return h(Icon, { icon: typeof props.icon === 'string' ? props.icon : '' })
158
+ }
159
+
160
+ const DEFAULT_ICONS: VuetifyOptions['icons'] = {
161
+ defaultSet: 'mdi',
162
+ sets: {
163
+ mdi: {
164
+ component: IconifyAdapter,
165
+ },
166
+ },
167
+ }
168
+
169
+ export interface AntVuetifyOverrides {
170
+ /** Merge additional component defaults (shallow merge at component level) */
171
+ defaults?: VuetifyOptions['defaults']
172
+ /** Override individual light theme colors (shallow merge). For dark theme overrides, use `themes` instead. */
173
+ colors?: Record<string, string>
174
+ /** Provide a full themes object (replaces the default light theme entirely) */
175
+ themes?: VuetifyOptions['theme'] extends { themes?: infer T } ? T : never
176
+ /** Default theme name (default: 'light') */
177
+ defaultTheme?: string
178
+ /** Explicit component imports (e.g., lab components like VDateInput) */
179
+ components?: VuetifyOptions['components']
180
+ /** Explicit directive imports */
181
+ directives?: VuetifyOptions['directives']
182
+ /** Override icon configuration */
183
+ icons?: VuetifyOptions['icons']
184
+ }
185
+
186
+ /**
187
+ * Creates a Vuetify instance pre-configured with the ANT platform design system.
188
+ *
189
+ * Importing this module automatically loads `vuetify/styles` and `virtual:uno.css`
190
+ * as side effects. CSS layer ordering is handled by the `transformIndexHtml` plugin
191
+ * in `createAntViteConfig`.
192
+ *
193
+ * @example
194
+ * ```ts
195
+ * // plugins/vuetify.ts — zero-arg default (most apps)
196
+ * import { createAntVuetify } from '@antcde/component-library/build/vuetify'
197
+ * export default createAntVuetify()
198
+ *
199
+ * // With overrides (ant-os)
200
+ * export default createAntVuetify({
201
+ * defaults: {
202
+ * VMenu: { transition: 'menu-ant', openDelay: 0, closeDelay: 0 },
203
+ * },
204
+ * })
205
+ * ```
206
+ */
207
+ export function createAntVuetify(overrides: AntVuetifyOverrides = {}) {
208
+ const { defaults, colors, themes, defaultTheme, components, directives, icons } = overrides
209
+
210
+ return createVuetify({
211
+ defaults: { ...ANT_DEFAULTS, ...defaults },
212
+ theme: {
213
+ defaultTheme: defaultTheme ?? 'light',
214
+ themes: themes ?? {
215
+ light: {
216
+ colors: { ...ANT_COLORS, ...(colors ?? {}) },
217
+ variables: ANT_VARIABLES,
218
+ },
219
+ dark: {
220
+ dark: true,
221
+ colors: { ...ANT_DARK_COLORS },
222
+ variables: ANT_DARK_VARIABLES,
223
+ },
224
+ },
225
+ },
226
+ icons: icons ?? DEFAULT_ICONS,
227
+ ...(components && { components }),
228
+ ...(directives && { directives }),
229
+ })
230
+ }
@@ -0,0 +1,227 @@
1
+ # Testing Reference — `@antcde/component-library/test`
2
+
3
+ Source of truth for the shared test infrastructure. Read this before writing tests for ant-os, ant-apps, or collaborall-apps.
4
+
5
+ ## What's automatic
6
+
7
+ The shared `setup.ts` (loaded via `createAntVitestConfig` or the explicit `'../ant-component-library/lib/test/setup.ts'` reference in `ant-os/vitest.config.ts`) registers the following globally — every `mount()` call inherits them:
8
+
9
+ - **Vuetify** — `createVuetify({ components, directives })` on `config.global.plugins`.
10
+ - **i18n** — `createTestI18n()` (legacy: false, locale: 'en', fallback to key on missing) on `config.global.plugins`.
11
+ - **`@antcde/vue-utils` mock** — `useApi` (executes service fn so `vi.fn()` resolves), `useCommsClient` (returns `__antTestMockComms` set by `createMockAppContext`), `useAntColorMode`, `useAntI18n`. Real `useSingleton` preserved so app context plugins work.
12
+ - **`enableAutoUnmount(afterEach)`** — wrappers auto-cleanup after each test.
13
+ - **Polyfills** — `ResizeObserver`, `visualViewport`, `window.scrollTo`, happy-dom fetch interceptor.
14
+
15
+ You **never** need to manually instantiate Vuetify or i18n in a test file. Don't import `createVuetify`, `createI18n`, or vuetify components/directives.
16
+
17
+ ## Helpers reference
18
+
19
+ All exports live at `@antcde/component-library/test`.
20
+
21
+ | Export | One-line purpose |
22
+ |--------|------------------|
23
+ | `mountApp(component, options?)` | Thin `mount()` wrapper for iframe app component tests. Adds `Transition: false` / `TransitionGroup: false` stubs. |
24
+ | `mountWithContext(component, options?)` | Mount with auto-injected `appContext`. Optional `mockContext`, `router`, `pinia`. |
25
+ | `testAppSetup(App, mockContext, { provideContext })` | 5 integration tests verifying real app wiring. Every iframe app's `app.test.ts` includes this. |
26
+ | `createMockAppContext(overrides?)` | Full mock context: `comms`, `i18n`, `colorMode`, `emitSignal`, `sentSignals`. Sets `globalThis.__antTestMockComms` so `useCommsClient` resolves. |
27
+ | `createTestI18n(overrides?)` | Build an i18n instance with custom messages/locale. |
28
+ | `createTestRouter(routes?, options?)` | **Subpath:** `…/test/createTestRouter`. Real `vue-router` with `createMemoryHistory()`. Always `await router.isReady()` after mount. |
29
+ | `mockVueRouter(overrides?)` | **Subpath:** `…/test/mockVueRouter`. Returns a module-shape object. Use as `vi.mock('vue-router', () => mockVueRouter({ ... }))`. |
30
+ | `createTestPinia(options?)` | **Subpath:** `…/test/createTestPinia`. Wraps `@pinia/testing` `createTestingPinia` (default `stubActions: false`). |
31
+ | `createMockUser(preset?)` | User with `'admin'` / `'viewer'` / `'editor'` presets. |
32
+ | `createMockLicense/Project/Task(overrides?)` | Domain objects with sensible defaults. |
33
+ | `createMockSignal()` | Signal mock — `emit()` simulates host, `send()` captures app signals. |
34
+ | `createMockApi(initial)` | `useApi`-shaped return — for composable/store mocking. |
35
+ | `createMockContext(overrides?)` | `{ license, project, task }` — for ant-os store tests. |
36
+ | `createTranslator(messages)` | Resolves dot-notation i18n keys from a JSON tree. |
37
+ | `useApiMock` | Factory for `vi.mock('@antcde/vue-utils', useApiMock)`. Rarely needed — `useApi` is mocked globally. |
38
+
39
+ ## Common patterns
40
+
41
+ ### Component test (iframe app) — `mountWithContext` with `mockContext`
42
+
43
+ The default. No per-file `vi.mock('@/plugins/context')`.
44
+
45
+ ```ts
46
+ import { createMockAppContext, mountWithContext } from '@antcde/component-library/test'
47
+ import { afterEach, describe, expect, it, vi } from 'vitest'
48
+ import MyDialog from '@/components/MyDialog.vue'
49
+
50
+ const mockContext = createMockAppContext({
51
+ connect: {
52
+ myService: {
53
+ getThings: vi.fn().mockResolvedValue([]),
54
+ createThing: vi.fn(),
55
+ },
56
+ },
57
+ })
58
+
59
+ describe('MyDialog', () => {
60
+ afterEach(() => { document.body.innerHTML = '' })
61
+
62
+ it('renders and emits save', async () => {
63
+ const { wrapper } = mountWithContext(MyDialog, {
64
+ mockContext,
65
+ props: { open: true },
66
+ mountOptions: { attachTo: document.body },
67
+ })
68
+ const buttons = wrapper.findAllComponents({ name: 'VBtn' })
69
+ await buttons.find(b => b.text().includes('save'))!.trigger('click')
70
+ expect(wrapper.emitted('save')).toHaveLength(1)
71
+ })
72
+ })
73
+ ```
74
+
75
+ ### App smoke test — `testAppSetup`
76
+
77
+ Every iframe app needs this in `tests/app.test.ts`.
78
+
79
+ ```ts
80
+ import { createMockAppContext, testAppSetup } from '@antcde/component-library/test'
81
+ import { vi } from 'vitest'
82
+ import App from '@/App.vue'
83
+ import { provideContext } from '@/plugins/context'
84
+
85
+ const mockContext = createMockAppContext({
86
+ connect: {
87
+ projects: { getProjects: vi.fn().mockResolvedValue([]) },
88
+ },
89
+ })
90
+
91
+ testAppSetup(App, mockContext, { provideContext })
92
+ ```
93
+
94
+ ### Page test with router (real navigation)
95
+
96
+ Use `createTestRouter` when the test needs actual `<router-view>` rendering or `router.push()` to navigate.
97
+
98
+ ```ts
99
+ import { mountWithContext } from '@antcde/component-library/test'
100
+ import { createTestRouter } from '@antcde/component-library/test/createTestRouter'
101
+ import HomePage from '@/pages/Home/index.vue'
102
+ import DetailPage from '@/pages/Detail/index.vue'
103
+
104
+ const router = createTestRouter([
105
+ { path: '/', component: HomePage },
106
+ { path: '/detail/:id', component: DetailPage },
107
+ ])
108
+
109
+ const { wrapper } = mountWithContext(App, { router })
110
+ await router.isReady() // initial navigation is async — always await
111
+
112
+ await router.push('/detail/42')
113
+ await flushPromises()
114
+ expect(wrapper.findComponent(DetailPage).exists()).toBe(true)
115
+ ```
116
+
117
+ ### Test asserting navigation calls (no real router)
118
+
119
+ Use `mockVueRouter` when the test only inspects `push`/`replace` calls. **Note the `vi.hoisted` for the `vi.fn()` reference and the async dynamic-import factory** — `vi.mock` is hoisted above imports, so direct symbol references fail.
120
+
121
+ ```ts
122
+ import { describe, expect, it, vi } from 'vitest'
123
+
124
+ const { mockReplace } = vi.hoisted(() => ({ mockReplace: vi.fn() }))
125
+
126
+ vi.mock('vue-router', async () => {
127
+ const { mockVueRouter } = await import('@antcde/component-library/test/mockVueRouter')
128
+ return mockVueRouter({ useRouter: { replace: mockReplace } })
129
+ })
130
+
131
+ // ... rest of test imports + describe block
132
+ ```
133
+
134
+ For a dynamic route query that changes between tests, pass a function:
135
+
136
+ ```ts
137
+ let routeQuery: Record<string, string> = {}
138
+
139
+ vi.mock('vue-router', async () => {
140
+ const { mockVueRouter } = await import('@antcde/component-library/test/mockVueRouter')
141
+ return mockVueRouter({
142
+ useRoute: () => ({ query: routeQuery }), // re-read on every useRoute() call
143
+ })
144
+ })
145
+ ```
146
+
147
+ > **Why the subpath?** `createTestRouter` / `createTestPinia` / `mockVueRouter` are intentionally **not** on the `/test` barrel — they import `vue-router` / `@pinia/testing`, which most iframe apps don't have. Keeping them subpath-only means importing the barrel never forces those deps, and a `vue-router` mock factory can pull `mockVueRouter` without dragging in the whole barrel.
148
+
149
+ ### Custom translations
150
+
151
+ When a test needs real translated text instead of falling back to keys.
152
+
153
+ ```ts
154
+ import { createTestI18n, mountWithContext } from '@antcde/component-library/test'
155
+
156
+ const i18n = createTestI18n({
157
+ messages: { en: { greeting: 'Hello {name}' } },
158
+ })
159
+
160
+ mountWithContext(MyComponent, {
161
+ // Adds alongside the auto-registered Vuetify+i18n. Last-registered i18n wins
162
+ // for the component's useI18n() resolution.
163
+ mountOptions: { global: { plugins: [i18n] } },
164
+ })
165
+ ```
166
+
167
+ For app tests using `injectContext().i18n.t()`, pass `messages` to `createMockAppContext`:
168
+
169
+ ```ts
170
+ import en from '@/lang/translations/en.json'
171
+ const mockContext = createMockAppContext({ messages: en })
172
+ ```
173
+
174
+ ### Pinia (apps using stores)
175
+
176
+ ```ts
177
+ import { mountWithContext } from '@antcde/component-library/test'
178
+ import { createTestPinia } from '@antcde/component-library/test/createTestPinia'
179
+
180
+ // Default: real action behavior
181
+ const pinia = createTestPinia()
182
+ mountWithContext(MyComponent, { pinia })
183
+
184
+ // Stub actions (spy without executing) + initial state
185
+ const pinia = createTestPinia({
186
+ stubActions: true,
187
+ initialState: { auth: { user: { id: 'u-1' } } },
188
+ })
189
+ ```
190
+
191
+ ## Anti-patterns
192
+
193
+ Don't write any of these in new tests. When you touch a file with these patterns, drop them.
194
+
195
+ ```ts
196
+ // DON'T — Vuetify is auto-registered globally
197
+ import { createVuetify } from 'vuetify'
198
+ const vuetify = createVuetify({ components, directives })
199
+ mount(Cmp, { global: { plugins: [vuetify] } })
200
+
201
+ // DON'T — i18n is auto-registered globally
202
+ import { createI18n } from 'vue-i18n'
203
+ const i18n = createI18n({ legacy: false, ... })
204
+ mount(Cmp, { global: { plugins: [i18n] } })
205
+
206
+ // DON'T — mountWithContext provides appContext directly
207
+ vi.mock('@/plugins/context', () => ({
208
+ injectContext: () => ({ i18n: ..., comms: ..., colorMode: ... })
209
+ }))
210
+
211
+ // DON'T — useApi is mocked globally by setup.ts
212
+ vi.mock('@antcde/vue-utils', () => ({
213
+ useApi: (_fn, defaultValue) => ({ ... }),
214
+ }))
215
+
216
+ // DON'T — write router mocks inline
217
+ vi.mock('vue-router', () => ({
218
+ useRouter: () => ({ push: vi.fn(), replace: vi.fn() }),
219
+ useRoute: () => ({ query: {} }),
220
+ }))
221
+ ```
222
+
223
+ ## Migration note
224
+
225
+ Existing tests still using stale patterns (`createVuetify`/`createI18n` inline, `vi.mock('@/plugins/context')`, inline `vue-router` mocks) keep working. When you touch one of those files, replace the boilerplate with the helpers above. Don't refactor unrelated tests.
226
+
227
+ If a test uses `mountWithContext` but still has `vi.mock('@/plugins/context', ...)` — drop the `vi.mock` and pass `mockContext` to the helper instead.
@@ -0,0 +1,212 @@
1
+ import type { Signal } from '@antcde/connect-ts'
2
+ import type { Mock } from 'vitest'
3
+ import type { Ref } from 'vue'
4
+ import { vi } from 'vitest'
5
+ import { computed, ref } from 'vue'
6
+ import { createMockConnect } from './createMockConnect'
7
+ import { createMockContext, createMockLicense } from './mocks/createMockContext'
8
+
9
+ type MockFn = Mock & ((...args: any[]) => any)
10
+
11
+ export type MockColorMode = Ref<string> & {
12
+ isDark: Ref<boolean>
13
+ host: Ref<boolean | null | undefined>
14
+ state: Ref<string>
15
+ system: Ref<string>
16
+ store: Ref<string>
17
+ }
18
+
19
+ export interface MockAppContext {
20
+ comms: {
21
+ context: Ref<{ license?: any, project?: any, task?: any, [key: string]: any }>
22
+ toolbar: {
23
+ title: Ref<string | undefined>
24
+ subtitle: Ref<string | undefined>
25
+ searchEnabled: Ref<boolean>
26
+ search: Ref<string>
27
+ menu: Ref<any[]>
28
+ isLoading: Ref<boolean>
29
+ }
30
+ signal: ((...signals: Signal[]) => Promise<unknown>) & {
31
+ send: (...signals: Signal[]) => Promise<unknown>
32
+ receive: (cb: (s: Signal) => void) => () => void
33
+ with: (...args: any[]) => { receive: (cb: (s: any) => void) => () => void }
34
+ append: (...signals: Signal[]) => any
35
+ }
36
+ notifications: {
37
+ success: MockFn
38
+ error: MockFn
39
+ warning: MockFn
40
+ info: MockFn
41
+ }
42
+ notepad: {
43
+ show: MockFn
44
+ hide: MockFn
45
+ showTask: MockFn
46
+ selectSbs: MockFn
47
+ }
48
+ connect: Record<string, any>
49
+ request: MockFn
50
+ appState: Ref<string>
51
+ unsubscribe: () => void
52
+ }
53
+ i18n: {
54
+ t: (key: string, params?: Record<string, any>) => string
55
+ locale: Ref<string>
56
+ }
57
+ colorMode: MockColorMode
58
+ /** Simulate receiving a signal from host */
59
+ emitSignal: (signal: Signal) => void
60
+ /** All signals sent by the app */
61
+ sentSignals: Signal[]
62
+ }
63
+
64
+ function resolveKey(messages: Record<string, any>, key: string): string | undefined {
65
+ const parts = key.split('.')
66
+ let current: any = messages
67
+ for (const part of parts) {
68
+ if (current == null || typeof current !== 'object')
69
+ return undefined
70
+ current = current[part]
71
+ }
72
+ return typeof current === 'string' ? current : undefined
73
+ }
74
+
75
+ export function createTranslator(messages?: Record<string, any>) {
76
+ return (key: string, params?: Record<string, any>) => {
77
+ let text = messages ? resolveKey(messages, key) : undefined
78
+ if (!text)
79
+ return params ? `${key}:${JSON.stringify(params)}` : key
80
+ if (params) {
81
+ for (const [k, v] of Object.entries(params))
82
+ text = text.split(`{${k}}`).join(String(v))
83
+ }
84
+ return text
85
+ }
86
+ }
87
+
88
+ function createMockSignalHandler(sentSignals: Signal[], signalCallbacks: Set<(s: Signal) => void>) {
89
+ const receive = (cb: (s: Signal) => void) => {
90
+ signalCallbacks.add(cb)
91
+ return () => {
92
+ signalCallbacks.delete(cb)
93
+ }
94
+ }
95
+
96
+ const send = (...signals: Signal[]) => {
97
+ sentSignals.push(...signals)
98
+ return Promise.resolve()
99
+ }
100
+
101
+ const withFilter = (..._args: any[]): { receive: typeof receive } => ({ receive })
102
+
103
+ const fn = (...signals: Signal[]) => {
104
+ sentSignals.push(...signals)
105
+ return Promise.resolve()
106
+ }
107
+
108
+ const builder: any = Object.assign(fn, {
109
+ send,
110
+ receive,
111
+ with: withFilter,
112
+ append: (...signals: Signal[]) => {
113
+ sentSignals.push(...signals)
114
+ return builder
115
+ },
116
+ })
117
+
118
+ return builder as MockAppContext['comms']['signal']
119
+ }
120
+
121
+ function createMockColorMode(): MockColorMode {
122
+ const mode = ref('light')
123
+ const isDark = computed(() => mode.value === 'dark')
124
+ const host = ref<boolean | null | undefined>(null)
125
+
126
+ return Object.assign(mode, {
127
+ isDark,
128
+ host,
129
+ state: mode,
130
+ system: ref('light'),
131
+ store: mode,
132
+ }) satisfies MockColorMode
133
+ }
134
+
135
+ export function createMockAppContext(overrides?: {
136
+ license?: Parameters<typeof createMockLicense>[0]
137
+ connect?: Record<string, any>
138
+ /** Pass app translation messages for realistic text. Import `en.json` and pass it. */
139
+ messages?: Record<string, any>
140
+ }): MockAppContext {
141
+ const mockCtx = createMockContext({
142
+ license: createMockLicense(overrides?.license),
143
+ })
144
+
145
+ const sentSignals: Signal[] = []
146
+ const signalCallbacks: Set<(s: Signal) => void> = new Set()
147
+
148
+ const comms = {
149
+ context: ref(mockCtx),
150
+ toolbar: {
151
+ title: ref<string | undefined>(undefined),
152
+ subtitle: ref<string | undefined>(undefined),
153
+ searchEnabled: ref(false),
154
+ search: ref(''),
155
+ menu: ref<any[]>([]),
156
+ isLoading: ref(false),
157
+ },
158
+ signal: createMockSignalHandler(sentSignals, signalCallbacks),
159
+ notifications: {
160
+ success: vi.fn().mockResolvedValue(undefined),
161
+ error: vi.fn().mockResolvedValue(undefined),
162
+ warning: vi.fn().mockResolvedValue(undefined),
163
+ info: vi.fn().mockResolvedValue(undefined),
164
+ },
165
+ notepad: {
166
+ show: vi.fn().mockResolvedValue(undefined),
167
+ hide: vi.fn().mockResolvedValue(undefined),
168
+ showTask: vi.fn().mockResolvedValue(undefined),
169
+ selectSbs: vi.fn().mockResolvedValue(undefined),
170
+ },
171
+ connect: createMockConnect(overrides?.connect),
172
+ request: vi.fn().mockResolvedValue(undefined),
173
+ appState: ref(''),
174
+ unsubscribe: () => {},
175
+ }
176
+
177
+ const i18n = {
178
+ t: createTranslator(overrides?.messages),
179
+ locale: ref('en'),
180
+ }
181
+
182
+ const colorMode = createMockColorMode()
183
+
184
+ Object.assign(globalThis, {
185
+ __antTestMockComms: comms,
186
+ __antTestMockColorMode: colorMode,
187
+ __antTestMockI18n: i18n,
188
+ })
189
+
190
+ return {
191
+ comms,
192
+ i18n,
193
+ colorMode,
194
+ emitSignal: (signal: Signal) => signalCallbacks.forEach(cb => cb(signal)),
195
+ sentSignals,
196
+ }
197
+ }
198
+
199
+ /**
200
+ * Factory for `vi.mock('@antcde/vue-utils', useApiMock)`.
201
+ */
202
+ export function useApiMock() {
203
+ return {
204
+ useApi: (_serviceFn: any, defaultValue: any) => {
205
+ const state = ref(structuredClone(defaultValue))
206
+ const isLoading = ref(false)
207
+ const error = ref(null)
208
+ const execute = vi.fn(async () => state.value)
209
+ return { state, isLoading, error, execute, isReady: ref(true), executeDelayed: vi.fn() }
210
+ },
211
+ }
212
+ }