@antcde/component-library 0.1.12 → 0.1.14-rc.00a441c
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.
- package/README.md +2 -2
- package/dist/index.js +41317 -33581
- package/dist/types/src/components/BaseAntCard.vue.d.ts +30 -0
- package/dist/types/{components → src/components}/BaseAntInput.vue.d.ts +13 -5
- package/dist/types/{components → src/components}/BaseAppCard.vue.d.ts +18 -1
- package/dist/types/{components → src/components}/BaseClickableIcon.vue.d.ts +1 -1
- package/dist/types/{components → src/components}/BaseConfirmDialog.vue.d.ts +16 -7
- package/dist/types/{components → src/components}/BaseDeleteDialog.vue.d.ts +24 -9
- package/dist/types/{components → src/components}/BaseDialog.vue.d.ts +12 -4
- package/dist/types/src/components/BaseLimitedButton.vue.d.ts +45 -0
- package/dist/types/{components → src/components}/BaseResizePanel.vue.d.ts +12 -12
- package/dist/types/src/components/BulkLabelsMenu.vue.d.ts +33 -0
- package/dist/types/src/components/DmsFilePicker/composables/usePickerNavigation.d.ts +196 -0
- package/dist/types/src/components/DmsFilePicker/composables/usePickerUpload.d.ts +22 -0
- package/dist/types/src/components/DmsFilePicker/index.vue.d.ts +28 -0
- package/dist/types/src/components/DmsFilePicker/utils/fileFormatting.d.ts +6 -0
- package/dist/types/src/components/FilePreviewContent/index.vue.d.ts +31 -0
- package/dist/types/src/components/FlowWindowContent/index.vue.d.ts +113 -0
- package/dist/types/src/components/RichTextEditor/index.vue.d.ts +51 -0
- package/dist/types/src/components/StackedLabels/_LabelsMenuCard.vue.d.ts +15 -0
- package/dist/types/src/components/StackedLabels/index.vue.d.ts +26 -0
- package/dist/types/src/components/TasksFlow/components/_FlowBreadcrumb.vue.d.ts +17 -0
- package/dist/types/src/components/TasksFlow/components/_FlowEdgeConditionsDialog.vue.d.ts +10 -0
- package/dist/types/{components/TasksFlow/components/nodes/_triggerNode.vue.d.ts → src/components/TasksFlow/components/_FlowSearch.vue.d.ts} +4 -3
- package/dist/types/src/components/TasksFlow/components/_FlowStats.vue.d.ts +5 -0
- package/dist/types/src/components/TasksFlow/components/_InsertTemplateDialog.vue.d.ts +17 -0
- package/dist/types/src/components/TasksFlow/components/_SubflowPanel.vue.d.ts +125 -0
- package/dist/types/src/components/TasksFlow/components/_VersionDiffView.vue.d.ts +14 -0
- package/dist/types/src/components/TasksFlow/components/_VersionPublishDialog.vue.d.ts +14 -0
- package/dist/types/src/components/TasksFlow/components/_dropzoneBackground.vue.d.ts +17 -0
- package/dist/types/src/components/TasksFlow/components/_flowEditor.vue.d.ts +13 -0
- package/dist/types/src/components/TasksFlow/components/nodes/_DurationEditor.vue.d.ts +33 -0
- package/dist/types/src/components/TasksFlow/components/nodes/_NodeContextMenu.vue.d.ts +35 -0
- package/dist/types/src/components/TasksFlow/components/nodes/_UserPicker.vue.d.ts +32 -0
- package/dist/types/{components → src/components}/TasksFlow/components/nodes/_taskNode.vue.d.ts +2 -2
- package/dist/types/src/components/TasksFlow/components/nodes/_triggerNode.vue.d.ts +10 -0
- package/dist/types/src/components/TasksFlow/composables/useAutoLayout.d.ts +22 -0
- package/dist/types/src/components/TasksFlow/composables/useCriticalPath.d.ts +8 -0
- package/dist/types/src/components/TasksFlow/composables/useFlowCache.d.ts +17 -0
- package/dist/types/src/components/TasksFlow/composables/useFlowCrud.d.ts +21 -0
- package/dist/types/src/components/TasksFlow/composables/useFlowEditor.d.ts +54 -0
- package/dist/types/src/components/TasksFlow/composables/useFlowFetch.d.ts +33 -0
- package/dist/types/src/components/TasksFlow/composables/useFlowKeyboard.d.ts +15 -0
- package/dist/types/src/components/TasksFlow/composables/useFlowNotifications.d.ts +15 -0
- package/dist/types/src/components/TasksFlow/composables/useFlowOperations.d.ts +8 -0
- package/dist/types/src/components/TasksFlow/composables/useFlowRealtime.d.ts +23 -0
- package/dist/types/src/components/TasksFlow/composables/useFlowSearch.d.ts +14 -0
- package/dist/types/src/components/TasksFlow/composables/useFlowSubflows.d.ts +22 -0
- package/dist/types/src/components/TasksFlow/composables/useFlowUsers.d.ts +27 -0
- package/dist/types/src/components/TasksFlow/composables/useFlowViewport.d.ts +28 -0
- package/dist/types/src/components/TasksFlow/composables/useTaskFlow.d.ts +321 -0
- package/dist/types/{components → src/components}/TasksFlow/composables/useTaskFlowDragDrop.d.ts +3 -4
- package/dist/types/src/components/TasksFlow/composables/useTaskFlowEdgeConditions.d.ts +10 -0
- package/dist/types/src/components/TasksFlow/composables/useTaskFlowEdges.d.ts +18 -0
- package/dist/types/src/components/TasksFlow/composables/useTaskFlowMappers.d.ts +4 -0
- package/dist/types/src/components/TasksFlow/composables/useTaskFlowTypes.d.ts +76 -0
- package/dist/types/src/components/TasksFlow/composables/useTemplateVersioning.d.ts +188 -0
- package/dist/types/src/components/TasksFlow/composables/useTemplateVersioningState.d.ts +176 -0
- package/dist/types/src/components/TasksFlow/composables/useTriggerExecution.d.ts +21 -0
- package/dist/types/src/components/TasksFlow/index.vue.d.ts +39 -0
- package/dist/types/src/components/UnifiedWindow/index.vue.d.ts +67 -0
- package/dist/types/src/components/UnifiedWindow/useWindowDrag.d.ts +28 -0
- package/dist/types/src/components/VersionPublishDialog.vue.d.ts +24 -0
- package/dist/types/{index.d.ts → src/index.d.ts} +15 -1
- package/lib/GisViewer/GisViewer.vue +3 -2
- package/lib/build/layer-order.css +33 -0
- package/lib/build/uno.ts +117 -0
- package/lib/build/vite.ts +104 -0
- package/lib/build/vuetify-overrides.css +14 -0
- package/lib/build/vuetify.ts +230 -0
- package/lib/test/TESTING.claude.md +225 -0
- package/lib/test/createMockAppContext.ts +211 -0
- package/lib/test/createTestPinia.ts +31 -0
- package/lib/test/createTestRouter.ts +31 -0
- package/lib/test/index.ts +41 -0
- package/lib/test/mockVueRouter.ts +93 -0
- package/lib/test/mocks/createMockApi.ts +43 -0
- package/lib/test/mocks/createMockContext.ts +109 -0
- package/lib/test/mocks/createMockSignal.ts +30 -0
- package/lib/test/mocks/createMockUser.ts +87 -0
- package/lib/test/mocks/index.ts +11 -0
- package/lib/test/mountApp.ts +47 -0
- package/lib/test/mountWithContext.ts +94 -0
- package/lib/test/setup.ts +151 -0
- package/lib/test/testAppSetup.ts +110 -0
- package/lib/test/vitest.ts +69 -0
- package/package.json +147 -61
- package/dist/component-library.css +0 -1
- package/dist/types/components/BaseAntCard.vue.d.ts +0 -22
- package/dist/types/components/TasksFlow/components/_dropzoneBackground.vue.d.ts +0 -9
- package/dist/types/components/TasksFlow/components/_flowEditor.vue.d.ts +0 -16
- package/dist/types/components/TasksFlow/composables/useTaskFlow.d.ts +0 -103
- package/dist/types/components/TasksFlow/index.vue.d.ts +0 -51
- package/lib/DocumentManager/DocumentDrop.vue +0 -74
- package/lib/DocumentManager/DocumentManager.vue +0 -571
- package/lib/DocumentManager/hooks/useDms.ts +0 -172
- package/lib/DocumentManager/index.ts +0 -3
- package/lib/DocumentManager/lang/translations/de.json +0 -36
- package/lib/DocumentManager/lang/translations/en.json +0 -38
- package/lib/DocumentManager/lang/translations/nl.json +0 -36
- package/lib/DocumentManager/utils.ts +0 -16
- /package/dist/types/{components → src/components}/BaseAntButton.vue.d.ts +0 -0
- /package/dist/types/{components → src/components}/BaseAntCreateCard.vue.d.ts +0 -0
- /package/dist/types/{components → src/components}/BaseAntDatePicker.vue.d.ts +0 -0
- /package/dist/types/{components → src/components}/BaseAntLoading.vue.d.ts +0 -0
- /package/dist/types/{components → src/components}/BaseAppCardSkeleton.vue.d.ts +0 -0
- /package/dist/types/{components → src/components}/GlobalLabelBadge.vue.d.ts +0 -0
- /package/dist/types/{components → src/components}/RBAC/Permissions/PermissionCard.vue.d.ts +0 -0
- /package/dist/types/{components → src/components}/TasksFlow/components/_flowEdge.vue.d.ts +0 -0
|
@@ -0,0 +1,225 @@
|
|
|
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?)` | Real `vue-router` with `createMemoryHistory()`. Always `await router.isReady()` after mount. |
|
|
29
|
+
| `mockVueRouter(overrides?)` | Returns a module-shape object. Use as `vi.mock('vue-router', () => mockVueRouter({ ... }))`. |
|
|
30
|
+
| `createTestPinia(options?)` | 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 { createTestRouter, mountWithContext } from '@antcde/component-library/test'
|
|
100
|
+
import HomePage from '@/pages/Home/index.vue'
|
|
101
|
+
import DetailPage from '@/pages/Detail/index.vue'
|
|
102
|
+
|
|
103
|
+
const router = createTestRouter([
|
|
104
|
+
{ path: '/', component: HomePage },
|
|
105
|
+
{ path: '/detail/:id', component: DetailPage },
|
|
106
|
+
])
|
|
107
|
+
|
|
108
|
+
const { wrapper } = mountWithContext(App, { router })
|
|
109
|
+
await router.isReady() // initial navigation is async — always await
|
|
110
|
+
|
|
111
|
+
await router.push('/detail/42')
|
|
112
|
+
await flushPromises()
|
|
113
|
+
expect(wrapper.findComponent(DetailPage).exists()).toBe(true)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Test asserting navigation calls (no real router)
|
|
117
|
+
|
|
118
|
+
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.
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
122
|
+
|
|
123
|
+
const { mockReplace } = vi.hoisted(() => ({ mockReplace: vi.fn() }))
|
|
124
|
+
|
|
125
|
+
vi.mock('vue-router', async () => {
|
|
126
|
+
const { mockVueRouter } = await import('@antcde/component-library/test/mockVueRouter')
|
|
127
|
+
return mockVueRouter({ useRouter: { replace: mockReplace } })
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
// ... rest of test imports + describe block
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
For a dynamic route query that changes between tests, pass a function:
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
let routeQuery: Record<string, string> = {}
|
|
137
|
+
|
|
138
|
+
vi.mock('vue-router', async () => {
|
|
139
|
+
const { mockVueRouter } = await import('@antcde/component-library/test/mockVueRouter')
|
|
140
|
+
return mockVueRouter({
|
|
141
|
+
useRoute: () => ({ query: routeQuery }), // re-read on every useRoute() call
|
|
142
|
+
})
|
|
143
|
+
})
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
> **Why the subpath?** The main `@antcde/component-library/test` barrel re-exports `createTestRouter`, which imports `vue-router`. Importing the barrel from a `vue-router` mock factory creates a resolution cycle. The `./test/mockVueRouter` subpath imports only the helper.
|
|
147
|
+
|
|
148
|
+
### Custom translations
|
|
149
|
+
|
|
150
|
+
When a test needs real translated text instead of falling back to keys.
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
import { createTestI18n, mountWithContext } from '@antcde/component-library/test'
|
|
154
|
+
|
|
155
|
+
const i18n = createTestI18n({
|
|
156
|
+
messages: { en: { greeting: 'Hello {name}' } },
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
mountWithContext(MyComponent, {
|
|
160
|
+
// Adds alongside the auto-registered Vuetify+i18n. Last-registered i18n wins
|
|
161
|
+
// for the component's useI18n() resolution.
|
|
162
|
+
mountOptions: { global: { plugins: [i18n] } },
|
|
163
|
+
})
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
For app tests using `injectContext().i18n.t()`, pass `messages` to `createMockAppContext`:
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
import en from '@/lang/translations/en.json'
|
|
170
|
+
const mockContext = createMockAppContext({ messages: en })
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Pinia (apps using stores)
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
import { createTestPinia, mountWithContext } from '@antcde/component-library/test'
|
|
177
|
+
|
|
178
|
+
// Default: real action behavior
|
|
179
|
+
const pinia = createTestPinia()
|
|
180
|
+
mountWithContext(MyComponent, { pinia })
|
|
181
|
+
|
|
182
|
+
// Stub actions (spy without executing) + initial state
|
|
183
|
+
const pinia = createTestPinia({
|
|
184
|
+
stubActions: true,
|
|
185
|
+
initialState: { auth: { user: { id: 'u-1' } } },
|
|
186
|
+
})
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Anti-patterns
|
|
190
|
+
|
|
191
|
+
Don't write any of these in new tests. When you touch a file with these patterns, drop them.
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
// DON'T — Vuetify is auto-registered globally
|
|
195
|
+
import { createVuetify } from 'vuetify'
|
|
196
|
+
const vuetify = createVuetify({ components, directives })
|
|
197
|
+
mount(Cmp, { global: { plugins: [vuetify] } })
|
|
198
|
+
|
|
199
|
+
// DON'T — i18n is auto-registered globally
|
|
200
|
+
import { createI18n } from 'vue-i18n'
|
|
201
|
+
const i18n = createI18n({ legacy: false, ... })
|
|
202
|
+
mount(Cmp, { global: { plugins: [i18n] } })
|
|
203
|
+
|
|
204
|
+
// DON'T — mountWithContext provides appContext directly
|
|
205
|
+
vi.mock('@/plugins/context', () => ({
|
|
206
|
+
injectContext: () => ({ i18n: ..., comms: ..., colorMode: ... })
|
|
207
|
+
}))
|
|
208
|
+
|
|
209
|
+
// DON'T — useApi is mocked globally by setup.ts
|
|
210
|
+
vi.mock('@antcde/vue-utils', () => ({
|
|
211
|
+
useApi: (_fn, defaultValue) => ({ ... }),
|
|
212
|
+
}))
|
|
213
|
+
|
|
214
|
+
// DON'T — write router mocks inline
|
|
215
|
+
vi.mock('vue-router', () => ({
|
|
216
|
+
useRouter: () => ({ push: vi.fn(), replace: vi.fn() }),
|
|
217
|
+
useRoute: () => ({ query: {} }),
|
|
218
|
+
}))
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Migration note
|
|
222
|
+
|
|
223
|
+
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.
|
|
224
|
+
|
|
225
|
+
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,211 @@
|
|
|
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 { createMockContext, createMockLicense } from './mocks/createMockContext'
|
|
7
|
+
|
|
8
|
+
type MockFn = Mock & ((...args: any[]) => any)
|
|
9
|
+
|
|
10
|
+
export type MockColorMode = Ref<string> & {
|
|
11
|
+
isDark: Ref<boolean>
|
|
12
|
+
host: Ref<boolean | null | undefined>
|
|
13
|
+
state: Ref<string>
|
|
14
|
+
system: Ref<string>
|
|
15
|
+
store: Ref<string>
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface MockAppContext {
|
|
19
|
+
comms: {
|
|
20
|
+
context: Ref<{ license?: any, project?: any, task?: any, [key: string]: any }>
|
|
21
|
+
toolbar: {
|
|
22
|
+
title: Ref<string | undefined>
|
|
23
|
+
subtitle: Ref<string | undefined>
|
|
24
|
+
searchEnabled: Ref<boolean>
|
|
25
|
+
search: Ref<string>
|
|
26
|
+
menu: Ref<any[]>
|
|
27
|
+
isLoading: Ref<boolean>
|
|
28
|
+
}
|
|
29
|
+
signal: ((...signals: Signal[]) => Promise<unknown>) & {
|
|
30
|
+
send: (...signals: Signal[]) => Promise<unknown>
|
|
31
|
+
receive: (cb: (s: Signal) => void) => () => void
|
|
32
|
+
with: (...args: any[]) => { receive: (cb: (s: any) => void) => () => void }
|
|
33
|
+
append: (...signals: Signal[]) => any
|
|
34
|
+
}
|
|
35
|
+
notifications: {
|
|
36
|
+
success: MockFn
|
|
37
|
+
error: MockFn
|
|
38
|
+
warning: MockFn
|
|
39
|
+
info: MockFn
|
|
40
|
+
}
|
|
41
|
+
notepad: {
|
|
42
|
+
show: MockFn
|
|
43
|
+
hide: MockFn
|
|
44
|
+
showTask: MockFn
|
|
45
|
+
selectSbs: MockFn
|
|
46
|
+
}
|
|
47
|
+
connect: Record<string, any>
|
|
48
|
+
request: MockFn
|
|
49
|
+
appState: Ref<string>
|
|
50
|
+
unsubscribe: () => void
|
|
51
|
+
}
|
|
52
|
+
i18n: {
|
|
53
|
+
t: (key: string, params?: Record<string, any>) => string
|
|
54
|
+
locale: Ref<string>
|
|
55
|
+
}
|
|
56
|
+
colorMode: MockColorMode
|
|
57
|
+
/** Simulate receiving a signal from host */
|
|
58
|
+
emitSignal: (signal: Signal) => void
|
|
59
|
+
/** All signals sent by the app */
|
|
60
|
+
sentSignals: Signal[]
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function resolveKey(messages: Record<string, any>, key: string): string | undefined {
|
|
64
|
+
const parts = key.split('.')
|
|
65
|
+
let current: any = messages
|
|
66
|
+
for (const part of parts) {
|
|
67
|
+
if (current == null || typeof current !== 'object')
|
|
68
|
+
return undefined
|
|
69
|
+
current = current[part]
|
|
70
|
+
}
|
|
71
|
+
return typeof current === 'string' ? current : undefined
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function createTranslator(messages?: Record<string, any>) {
|
|
75
|
+
return (key: string, params?: Record<string, any>) => {
|
|
76
|
+
let text = messages ? resolveKey(messages, key) : undefined
|
|
77
|
+
if (!text)
|
|
78
|
+
return params ? `${key}:${JSON.stringify(params)}` : key
|
|
79
|
+
if (params) {
|
|
80
|
+
for (const [k, v] of Object.entries(params))
|
|
81
|
+
text = text.split(`{${k}}`).join(String(v))
|
|
82
|
+
}
|
|
83
|
+
return text
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function createMockSignalHandler(sentSignals: Signal[], signalCallbacks: Set<(s: Signal) => void>) {
|
|
88
|
+
const receive = (cb: (s: Signal) => void) => {
|
|
89
|
+
signalCallbacks.add(cb)
|
|
90
|
+
return () => {
|
|
91
|
+
signalCallbacks.delete(cb)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const send = (...signals: Signal[]) => {
|
|
96
|
+
sentSignals.push(...signals)
|
|
97
|
+
return Promise.resolve()
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const withFilter = (..._args: any[]): { receive: typeof receive } => ({ receive })
|
|
101
|
+
|
|
102
|
+
const fn = (...signals: Signal[]) => {
|
|
103
|
+
sentSignals.push(...signals)
|
|
104
|
+
return Promise.resolve()
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const builder: any = Object.assign(fn, {
|
|
108
|
+
send,
|
|
109
|
+
receive,
|
|
110
|
+
with: withFilter,
|
|
111
|
+
append: (...signals: Signal[]) => {
|
|
112
|
+
sentSignals.push(...signals)
|
|
113
|
+
return builder
|
|
114
|
+
},
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
return builder as MockAppContext['comms']['signal']
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function createMockColorMode(): MockColorMode {
|
|
121
|
+
const mode = ref('light')
|
|
122
|
+
const isDark = computed(() => mode.value === 'dark')
|
|
123
|
+
const host = ref<boolean | null | undefined>(null)
|
|
124
|
+
|
|
125
|
+
return Object.assign(mode, {
|
|
126
|
+
isDark,
|
|
127
|
+
host,
|
|
128
|
+
state: mode,
|
|
129
|
+
system: ref('light'),
|
|
130
|
+
store: mode,
|
|
131
|
+
}) satisfies MockColorMode
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function createMockAppContext(overrides?: {
|
|
135
|
+
license?: Parameters<typeof createMockLicense>[0]
|
|
136
|
+
connect?: Record<string, any>
|
|
137
|
+
/** Pass app translation messages for realistic text. Import `en.json` and pass it. */
|
|
138
|
+
messages?: Record<string, any>
|
|
139
|
+
}): MockAppContext {
|
|
140
|
+
const mockCtx = createMockContext({
|
|
141
|
+
license: createMockLicense(overrides?.license),
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
const sentSignals: Signal[] = []
|
|
145
|
+
const signalCallbacks: Set<(s: Signal) => void> = new Set()
|
|
146
|
+
|
|
147
|
+
const comms = {
|
|
148
|
+
context: ref(mockCtx),
|
|
149
|
+
toolbar: {
|
|
150
|
+
title: ref<string | undefined>(undefined),
|
|
151
|
+
subtitle: ref<string | undefined>(undefined),
|
|
152
|
+
searchEnabled: ref(false),
|
|
153
|
+
search: ref(''),
|
|
154
|
+
menu: ref<any[]>([]),
|
|
155
|
+
isLoading: ref(false),
|
|
156
|
+
},
|
|
157
|
+
signal: createMockSignalHandler(sentSignals, signalCallbacks),
|
|
158
|
+
notifications: {
|
|
159
|
+
success: vi.fn().mockResolvedValue(undefined),
|
|
160
|
+
error: vi.fn().mockResolvedValue(undefined),
|
|
161
|
+
warning: vi.fn().mockResolvedValue(undefined),
|
|
162
|
+
info: vi.fn().mockResolvedValue(undefined),
|
|
163
|
+
},
|
|
164
|
+
notepad: {
|
|
165
|
+
show: vi.fn().mockResolvedValue(undefined),
|
|
166
|
+
hide: vi.fn().mockResolvedValue(undefined),
|
|
167
|
+
showTask: vi.fn().mockResolvedValue(undefined),
|
|
168
|
+
selectSbs: vi.fn().mockResolvedValue(undefined),
|
|
169
|
+
},
|
|
170
|
+
connect: { httpClient: {}, ...overrides?.connect },
|
|
171
|
+
request: vi.fn().mockResolvedValue(undefined),
|
|
172
|
+
appState: ref(''),
|
|
173
|
+
unsubscribe: () => {},
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const i18n = {
|
|
177
|
+
t: createTranslator(overrides?.messages),
|
|
178
|
+
locale: ref('en'),
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const colorMode = createMockColorMode()
|
|
182
|
+
|
|
183
|
+
Object.assign(globalThis, {
|
|
184
|
+
__antTestMockComms: comms,
|
|
185
|
+
__antTestMockColorMode: colorMode,
|
|
186
|
+
__antTestMockI18n: i18n,
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
comms,
|
|
191
|
+
i18n,
|
|
192
|
+
colorMode,
|
|
193
|
+
emitSignal: (signal: Signal) => signalCallbacks.forEach(cb => cb(signal)),
|
|
194
|
+
sentSignals,
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Factory for `vi.mock('@antcde/vue-utils', useApiMock)`.
|
|
200
|
+
*/
|
|
201
|
+
export function useApiMock() {
|
|
202
|
+
return {
|
|
203
|
+
useApi: (_serviceFn: any, defaultValue: any) => {
|
|
204
|
+
const state = ref(structuredClone(defaultValue))
|
|
205
|
+
const isLoading = ref(false)
|
|
206
|
+
const error = ref(null)
|
|
207
|
+
const execute = vi.fn(async () => state.value)
|
|
208
|
+
return { state, isLoading, error, execute, isReady: ref(true), executeDelayed: vi.fn() }
|
|
209
|
+
},
|
|
210
|
+
}
|
|
211
|
+
}
|
|
@@ -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
|
+
}
|