@jskit-ai/users-web 0.1.173 → 0.1.175

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 (113) hide show
  1. package/package.json +18 -149
  2. package/src/client/composables/account-settings/accountSettingsAvatarUploadRuntime.js +2 -2
  3. package/src/client/composables/useAccountSettingsRuntime.js +3 -3
  4. package/src/client/index.js +0 -11
  5. package/src/client/providers/UsersWebClientProvider.js +0 -2
  6. package/test/exportsContract.test.js +3 -29
  7. package/test/settingsPlacementContract.test.js +10 -0
  8. package/fixtures/crud-list-date-filters/App.vue +0 -107
  9. package/fixtures/crud-list-date-filters/index.html +0 -12
  10. package/fixtures/crud-list-date-filters/main.js +0 -24
  11. package/fixtures/crud-list-date-filters/vite.config.mjs +0 -18
  12. package/src/client/bulkActions.js +0 -47
  13. package/src/client/components/CrudAddEditScreen.vue +0 -186
  14. package/src/client/components/CrudDeleteAction.vue +0 -93
  15. package/src/client/components/CrudListBulkActionSurface.vue +0 -126
  16. package/src/client/components/CrudListDateFilterControl.vue +0 -188
  17. package/src/client/components/CrudListFilterSurface.vue +0 -388
  18. package/src/client/components/CrudListRecordActionMenu.vue +0 -120
  19. package/src/client/components/CrudListScreen.vue +0 -501
  20. package/src/client/components/CrudViewScreen.vue +0 -197
  21. package/src/client/composables/crud/crudBindingSupport.js +0 -75
  22. package/src/client/composables/crud/crudHttpClientSupport.js +0 -57
  23. package/src/client/composables/crud/crudJsonApiTransportSupport.js +0 -145
  24. package/src/client/composables/crud/crudLookupFieldLabelSupport.js +0 -151
  25. package/src/client/composables/crud/crudLookupFieldRuntime.js +0 -251
  26. package/src/client/composables/crud/crudSchemaFormHelpers.js +0 -464
  27. package/src/client/composables/internal/crudListFilterLookupSupport.js +0 -161
  28. package/src/client/composables/internal/crudListParentTitleSupport.js +0 -171
  29. package/src/client/composables/internal/useOperationScope.js +0 -144
  30. package/src/client/composables/records/useAddEdit.js +0 -224
  31. package/src/client/composables/records/useCrudAddEdit.js +0 -227
  32. package/src/client/composables/records/useCrudList.js +0 -101
  33. package/src/client/composables/records/useCrudView.js +0 -47
  34. package/src/client/composables/records/useList.js +0 -500
  35. package/src/client/composables/records/useView.js +0 -164
  36. package/src/client/composables/runtime/addEditUiRuntime.js +0 -130
  37. package/src/client/composables/runtime/listUiRuntime.js +0 -123
  38. package/src/client/composables/runtime/modelStateHelpers.js +0 -90
  39. package/src/client/composables/runtime/operationAdapters.js +0 -34
  40. package/src/client/composables/runtime/operationUiHelpers.js +0 -125
  41. package/src/client/composables/runtime/operationValidationHelpers.js +0 -51
  42. package/src/client/composables/runtime/useAddEditCore.js +0 -112
  43. package/src/client/composables/runtime/useCommandCore.js +0 -123
  44. package/src/client/composables/runtime/useEndpointResource.js +0 -199
  45. package/src/client/composables/runtime/useFieldErrorBag.js +0 -61
  46. package/src/client/composables/runtime/useListCore.js +0 -112
  47. package/src/client/composables/runtime/useUiFeedback.js +0 -98
  48. package/src/client/composables/runtime/useViewCore.js +0 -93
  49. package/src/client/composables/runtime/viewUiRuntime.js +0 -96
  50. package/src/client/composables/support/errorMessageHelpers.js +0 -66
  51. package/src/client/composables/support/listQueryParamSupport.js +0 -473
  52. package/src/client/composables/support/listSearchSupport.js +0 -70
  53. package/src/client/composables/support/refValueHelpers.js +0 -19
  54. package/src/client/composables/support/requestQueryRuntimeSupport.js +0 -141
  55. package/src/client/composables/support/resourceLoadStateHelpers.js +0 -208
  56. package/src/client/composables/support/routeTemplateHelpers.js +0 -285
  57. package/src/client/composables/support/scopeHelpers.js +0 -145
  58. package/src/client/composables/useAccess.js +0 -109
  59. package/src/client/composables/useCommand.js +0 -118
  60. package/src/client/composables/useCrudAddEditScreen.js +0 -88
  61. package/src/client/composables/useCrudDeleteAction.js +0 -160
  62. package/src/client/composables/useCrudListBulkActions.js +0 -147
  63. package/src/client/composables/useCrudListFilterLookups.js +0 -146
  64. package/src/client/composables/useCrudListFilters.js +0 -339
  65. package/src/client/composables/useCrudListParentTitle.js +0 -151
  66. package/src/client/composables/useCrudListRowActions.js +0 -144
  67. package/src/client/composables/useCrudListScreen.js +0 -237
  68. package/src/client/composables/useCrudViewScreen.js +0 -77
  69. package/src/client/composables/usePagedCollection.js +0 -181
  70. package/src/client/composables/useRealtimeQueryInvalidation.js +0 -156
  71. package/src/client/composables/useScopeRuntime.js +0 -135
  72. package/src/client/filters.js +0 -15
  73. package/src/client/lib/httpClient.js +0 -47
  74. package/src/client/lib/permissions.js +0 -34
  75. package/src/client/rowActions.js +0 -47
  76. package/src/client/support/contractGuards.js +0 -34
  77. package/src/client/support/crudListDateFilterSupport.js +0 -91
  78. package/test/addEditUiRuntime.test.js +0 -110
  79. package/test/crudBindingSupport.test.js +0 -110
  80. package/test/crudHttpClientSupport.test.js +0 -77
  81. package/test/crudJsonApiTransportSupport.test.js +0 -179
  82. package/test/crudListBulkActionSurface.test.js +0 -27
  83. package/test/crudListDateFilterSupport.test.js +0 -92
  84. package/test/crudListDateFilterSurface.browser.test.js +0 -182
  85. package/test/crudListFilterSurface.test.js +0 -90
  86. package/test/crudLookupFieldRuntime.test.js +0 -264
  87. package/test/crudScreenComponents.test.js +0 -117
  88. package/test/errorIntentContract.test.js +0 -31
  89. package/test/errorMessageHelpers.test.js +0 -28
  90. package/test/listQueryParamSupport.test.js +0 -223
  91. package/test/listUiRuntime.test.js +0 -102
  92. package/test/operationValidationHelpers.test.js +0 -64
  93. package/test/permissions.test.js +0 -35
  94. package/test/refValueHelpers.test.js +0 -14
  95. package/test/requestTransportOptions.test.js +0 -457
  96. package/test/resourceLoadStateHelpers.test.js +0 -189
  97. package/test/routeTemplateHelpers.test.js +0 -85
  98. package/test/scopeHelpers.test.js +0 -57
  99. package/test/useAddEditCore.test.js +0 -124
  100. package/test/useAddEditRequestQueryParams.test.js +0 -190
  101. package/test/useCrudAddEdit.test.js +0 -415
  102. package/test/useCrudDeleteAction.test.js +0 -139
  103. package/test/useCrudListBulkActions.test.js +0 -65
  104. package/test/useCrudListFilterLookups.test.js +0 -114
  105. package/test/useCrudListFilters.test.js +0 -293
  106. package/test/useCrudListParentTitle.test.js +0 -262
  107. package/test/useCrudListRowActions.test.js +0 -77
  108. package/test/useListRouteInitialization.test.js +0 -337
  109. package/test/useListSearchSupport.test.js +0 -61
  110. package/test/usePagedCollection.test.js +0 -53
  111. package/test/useViewRequestQueryParams.test.js +0 -20
  112. package/test/viewCoreLoading.test.js +0 -44
  113. package/test/viewUiRuntime.test.js +0 -95
@@ -1,415 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import test from "node:test";
3
- import { reactive } from "vue";
4
- import {
5
- normalizeCrudFormFields,
6
- createCrudFormModel,
7
- buildCrudFormPayload,
8
- applyCrudPayloadToForm,
9
- resolveCrudRouteBoundFieldValues,
10
- applyCrudRouteBoundFieldValues,
11
- resolveCrudFieldErrors
12
- } from "../src/client/composables/crud/crudSchemaFormHelpers.js";
13
-
14
- test("normalizeCrudFormFields trims keys, removes invalid entries, and deduplicates", () => {
15
- const fields = normalizeCrudFormFields([
16
- { key: " name ", type: "string" },
17
- { key: "name", type: "string" },
18
- { key: "", type: "string" },
19
- null,
20
- { key: "active", type: "boolean" }
21
- ]);
22
-
23
- assert.deepEqual(fields.map((field) => field.key), ["name", "active"]);
24
- });
25
-
26
- test("createCrudFormModel resolves defaults and supports explicit initial values", () => {
27
- const model = createCrudFormModel([
28
- { key: "name", type: "string" },
29
- { key: "active", type: "boolean" },
30
- { key: "reviewed", type: "boolean", nullable: true },
31
- { key: "role", type: "string", initialValue: "member" }
32
- ]);
33
-
34
- assert.deepEqual(model, {
35
- name: "",
36
- active: false,
37
- reviewed: null,
38
- role: "member"
39
- });
40
- });
41
-
42
- test("createCrudFormModel preserves explicit boolean defaults for nullable fields", () => {
43
- const model = createCrudFormModel([
44
- { key: "reviewed", type: "boolean", nullable: true, initialValue: false },
45
- { key: "approved", type: "boolean", nullable: true, defaultValue: true }
46
- ]);
47
-
48
- assert.deepEqual(model, {
49
- reviewed: false,
50
- approved: true
51
- });
52
- });
53
-
54
- test("createCrudFormModel initializes nullable lookup fields as null", () => {
55
- const model = createCrudFormModel([
56
- {
57
- key: "serviceId",
58
- type: "string",
59
- nullable: true,
60
- component: "lookup",
61
- relation: { kind: "lookup", namespace: "services" }
62
- }
63
- ]);
64
-
65
- assert.deepEqual(model, {
66
- serviceId: null
67
- });
68
- });
69
-
70
- test("buildCrudFormPayload normalizes booleans and numbers while skipping empty numeric values", () => {
71
- const payload = buildCrudFormPayload(
72
- [
73
- { key: "name", type: "string" },
74
- { key: "active", type: "boolean" },
75
- { key: "age", type: "integer" },
76
- { key: "score", type: "number" }
77
- ],
78
- {
79
- name: "Ada",
80
- active: 1,
81
- age: "42",
82
- score: ""
83
- }
84
- );
85
-
86
- assert.deepEqual(payload, {
87
- name: "Ada",
88
- active: true,
89
- age: 42
90
- });
91
- });
92
-
93
- test("buildCrudFormPayload and applyCrudPayloadToForm round-trip date-time fields", () => {
94
- const fields = [
95
- { key: "scheduledAt", type: "string", format: "date-time" }
96
- ];
97
- const payload = buildCrudFormPayload(fields, {
98
- scheduledAt: "2024-01-02T03:04"
99
- });
100
-
101
- assert.match(payload.scheduledAt, /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.000Z$/);
102
-
103
- const form = reactive({
104
- scheduledAt: ""
105
- });
106
- applyCrudPayloadToForm(fields, form, payload);
107
-
108
- assert.equal(form.scheduledAt, "2024-01-02T03:04");
109
- });
110
-
111
- test("date-time form values honor strict temporal precision without losing fractional tails", () => {
112
- const noFraction = buildCrudFormPayload(
113
- [{ key: "scheduledAt", type: "string", format: "date-time", temporalPrecision: 0 }],
114
- { scheduledAt: "2024-01-02T03:04" }
115
- );
116
- assert.match(noFraction.scheduledAt, /T\d{2}:\d{2}:00Z$/u);
117
- assert.doesNotMatch(noFraction.scheduledAt, /\.000Z$/u);
118
-
119
- const microseconds = buildCrudFormPayload(
120
- [{ key: "scheduledAt", type: "string", format: "date-time", temporalPrecision: 6 }],
121
- { scheduledAt: "2024-01-02T03:04:05.123456" }
122
- );
123
- assert.match(microseconds.scheduledAt, /T\d{2}:\d{2}:05\.123456Z$/u);
124
-
125
- const form = reactive({ scheduledAt: "" });
126
- applyCrudPayloadToForm(
127
- [{ key: "scheduledAt", type: "string", format: "date-time", temporalPrecision: 6 }],
128
- form,
129
- { scheduledAt: "2024-01-02T03:04:05.123456Z" }
130
- );
131
- assert.match(form.scheduledAt, /T\d{2}:\d{2}:05\.123456$/u);
132
- });
133
-
134
- test("applyCrudPayloadToForm normalizes date values for HTML date inputs", () => {
135
- const fields = [
136
- { key: "publishedOn", type: "string", format: "date" },
137
- { key: "reviewedOn", type: "string", format: "date" },
138
- { key: "archivedOn", type: "string", format: "date" },
139
- { key: "invalidOn", type: "string", format: "date" }
140
- ];
141
- const form = reactive({
142
- publishedOn: "",
143
- reviewedOn: "",
144
- archivedOn: "",
145
- invalidOn: ""
146
- });
147
-
148
- applyCrudPayloadToForm(fields, form, {
149
- publishedOn: "2026-08-10",
150
- reviewedOn: "2026-08-11T00:00:00.000Z",
151
- archivedOn: new Date("2026-08-12T00:00:00.000Z"),
152
- invalidOn: "not-a-date"
153
- });
154
-
155
- assert.deepEqual(form, {
156
- publishedOn: "2026-08-10",
157
- reviewedOn: "2026-08-11",
158
- archivedOn: "2026-08-12",
159
- invalidOn: "not-a-date"
160
- });
161
- });
162
-
163
- test("buildCrudFormPayload preserves strict time precision", () => {
164
- const fields = [
165
- { key: "fromTime", type: "string", format: "time" },
166
- { key: "toTime", type: "string", format: "time" }
167
- ];
168
-
169
- const payload = buildCrudFormPayload(fields, {
170
- fromTime: "06:13 PM",
171
- toTime: "18:45:00"
172
- });
173
-
174
- assert.deepEqual(payload, {
175
- fromTime: "18:13",
176
- toTime: "18:45:00"
177
- });
178
- });
179
-
180
- test("buildCrudFormPayload serializes cleared nullable typed fields as null", () => {
181
- const payload = buildCrudFormPayload(
182
- [
183
- { key: "reviewed", type: "boolean", nullable: true },
184
- { key: "serviceId", type: "integer", nullable: true },
185
- {
186
- key: "selectedServiceId",
187
- type: "string",
188
- nullable: true,
189
- component: "lookup",
190
- relation: { kind: "lookup", namespace: "services" }
191
- },
192
- { key: "fromDate", type: "string", format: "date", nullable: true },
193
- { key: "scheduledAt", type: "string", format: "date-time", nullable: true },
194
- { key: "fromTime", type: "string", format: "time", nullable: true }
195
- ],
196
- {
197
- reviewed: null,
198
- serviceId: null,
199
- selectedServiceId: "",
200
- fromDate: "",
201
- scheduledAt: "",
202
- fromTime: ""
203
- }
204
- );
205
-
206
- assert.deepEqual(payload, {
207
- reviewed: null,
208
- serviceId: null,
209
- selectedServiceId: null,
210
- fromDate: null,
211
- scheduledAt: null,
212
- fromTime: null
213
- });
214
- });
215
-
216
- test("buildCrudFormPayload preserves nullable booleans while keeping non-nullable booleans binary", () => {
217
- const fields = [
218
- { key: "active", type: "boolean" },
219
- { key: "reviewed", type: "boolean", nullable: true },
220
- { key: "approved", type: "boolean", nullable: true }
221
- ];
222
-
223
- assert.deepEqual(
224
- buildCrudFormPayload(fields, {
225
- active: null,
226
- reviewed: null,
227
- approved: true
228
- }),
229
- {
230
- active: false,
231
- reviewed: null,
232
- approved: true
233
- }
234
- );
235
-
236
- assert.deepEqual(
237
- buildCrudFormPayload(fields, {
238
- active: 1,
239
- reviewed: 0,
240
- approved: false
241
- }),
242
- {
243
- active: true,
244
- reviewed: false,
245
- approved: false
246
- }
247
- );
248
- });
249
-
250
- test("applyCrudPayloadToForm preserves strict time values for form inputs", () => {
251
- const fields = [
252
- { key: "fromTime", type: "string", format: "time" },
253
- { key: "toTime", type: "string", format: "time" }
254
- ];
255
- const form = reactive({
256
- fromTime: "",
257
- toTime: ""
258
- });
259
-
260
- applyCrudPayloadToForm(fields, form, {
261
- fromTime: "18:13:00",
262
- toTime: "06:45 PM"
263
- });
264
-
265
- assert.deepEqual(form, {
266
- fromTime: "18:13:00",
267
- toTime: "18:45"
268
- });
269
- });
270
-
271
- test("strict temporal form values round-trip seconds and fractions", () => {
272
- const fields = [
273
- { key: "fromTime", type: "string", format: "time", temporalPrecision: 6 },
274
- { key: "scheduledAt", type: "string", format: "date-time", temporalPrecision: 3 }
275
- ];
276
- const form = reactive({
277
- fromTime: "",
278
- scheduledAt: ""
279
- });
280
-
281
- applyCrudPayloadToForm(fields, form, {
282
- fromTime: "18:13:14.123456",
283
- scheduledAt: "2026-08-13T07:08:09.123Z"
284
- });
285
-
286
- assert.equal(form.fromTime, "18:13:14.123456");
287
- assert.match(form.scheduledAt, /^2026-08-13T\d{2}:\d{2}:09\.123$/u);
288
- assert.deepEqual(buildCrudFormPayload(fields, form), {
289
- fromTime: "18:13:14.123456",
290
- scheduledAt: "2026-08-13T07:08:09.123Z"
291
- });
292
- });
293
-
294
- test("applyCrudPayloadToForm maps payload values into reactive form model", () => {
295
- const form = reactive({
296
- name: "",
297
- active: false,
298
- reviewed: null,
299
- age: ""
300
- });
301
- applyCrudPayloadToForm(
302
- [
303
- { key: "name", type: "string" },
304
- { key: "active", type: "boolean" },
305
- { key: "reviewed", type: "boolean", nullable: true },
306
- { key: "age", type: "integer" }
307
- ],
308
- form,
309
- {
310
- name: "Grace",
311
- active: 1,
312
- reviewed: null,
313
- age: 33
314
- }
315
- );
316
-
317
- assert.deepEqual(form, {
318
- name: "Grace",
319
- active: true,
320
- reviewed: null,
321
- age: "33"
322
- });
323
- });
324
-
325
- test("applyCrudPayloadToForm preserves nullable boolean payload values", () => {
326
- const fields = [
327
- { key: "active", type: "boolean" },
328
- { key: "reviewed", type: "boolean", nullable: true },
329
- { key: "approved", type: "boolean", nullable: true }
330
- ];
331
- const form = reactive({
332
- active: false,
333
- reviewed: null,
334
- approved: null
335
- });
336
-
337
- applyCrudPayloadToForm(fields, form, {
338
- active: null,
339
- reviewed: null,
340
- approved: true
341
- });
342
-
343
- assert.deepEqual(form, {
344
- active: false,
345
- reviewed: null,
346
- approved: true
347
- });
348
- });
349
-
350
- test("applyCrudPayloadToForm preserves null lookup payload values", () => {
351
- const fields = [
352
- {
353
- key: "serviceId",
354
- type: "string",
355
- nullable: true,
356
- component: "lookup",
357
- relation: { kind: "lookup", namespace: "services" }
358
- }
359
- ];
360
- const form = reactive({
361
- serviceId: "existing"
362
- });
363
-
364
- applyCrudPayloadToForm(fields, form, {
365
- serviceId: null
366
- });
367
- assert.equal(form.serviceId, null);
368
-
369
- applyCrudPayloadToForm(fields, form, {
370
- serviceId: 42
371
- });
372
- assert.equal(form.serviceId, "42");
373
- });
374
-
375
- test("resolveCrudRouteBoundFieldValues maps route params for route-bound form fields", () => {
376
- const values = resolveCrudRouteBoundFieldValues(
377
- [
378
- { key: "contactId", routeParamKey: "contactId" },
379
- { key: "name" }
380
- ],
381
- {
382
- contactId: " 2971 "
383
- }
384
- );
385
-
386
- assert.deepEqual(values, {
387
- contactId: "2971"
388
- });
389
- });
390
-
391
- test("applyCrudRouteBoundFieldValues enforces route-bound field values onto target payload", () => {
392
- const payload = {
393
- name: "Address one",
394
- contactId: "123"
395
- };
396
- applyCrudRouteBoundFieldValues(
397
- [
398
- { key: "contactId", routeParamKey: "contactId" }
399
- ],
400
- payload,
401
- {
402
- contactId: "2971"
403
- }
404
- );
405
-
406
- assert.deepEqual(payload, {
407
- name: "Address one",
408
- contactId: "2971"
409
- });
410
- });
411
-
412
- test("resolveCrudFieldErrors returns Vuetify-compatible error arrays", () => {
413
- assert.deepEqual(resolveCrudFieldErrors({ name: "Name is required." }, "name"), ["Name is required."]);
414
- assert.deepEqual(resolveCrudFieldErrors({ name: "Name is required." }, "email"), []);
415
- });
@@ -1,139 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import test from "node:test";
3
- import { QueryClient, VueQueryPlugin } from "@tanstack/vue-query";
4
- import { createSSRApp, h, nextTick, ref } from "vue";
5
- import { renderToString } from "vue/server-renderer";
6
- import { createMemoryHistory, createRouter } from "vue-router";
7
- import {
8
- requireCrudDeleteOperation,
9
- useCrudDeleteAction
10
- } from "../src/client/composables/useCrudDeleteAction.js";
11
-
12
- const deleteResource = Object.freeze({
13
- namespace: "notes",
14
- operations: Object.freeze({
15
- delete: Object.freeze({
16
- method: "DELETE"
17
- })
18
- })
19
- });
20
-
21
- function createTestRouter() {
22
- return createRouter({
23
- history: createMemoryHistory(),
24
- routes: [
25
- { path: "/notes", component: { render: () => h("div") } },
26
- { path: "/notes/:noteId", component: { render: () => h("div") } }
27
- ]
28
- });
29
- }
30
-
31
- function createScreen() {
32
- return Object.freeze({
33
- view: Object.freeze({
34
- recordId: ref("42"),
35
- record: ref({ id: "42", title: "Keep it simple" }),
36
- isLoading: ref(false),
37
- isNotFound: ref(false),
38
- resolveParams(template = "") {
39
- return String(template || "").replace(":noteId", "42");
40
- }
41
- }),
42
- listLocation: ref({ path: "/notes" })
43
- });
44
- }
45
-
46
- async function renderDeleteAction({ client, queryClient = new QueryClient() } = {}) {
47
- const router = createTestRouter();
48
- await router.push("/notes/42");
49
- await router.isReady();
50
-
51
- let deleteAction = null;
52
- const app = createSSRApp({
53
- setup() {
54
- deleteAction = useCrudDeleteAction({
55
- screen: createScreen(),
56
- resource: deleteResource,
57
- resourceNamespace: "notes",
58
- apiUrlTemplate: "/notes/:noteId",
59
- client
60
- });
61
- return () => h("div");
62
- }
63
- });
64
- app.use(router);
65
- app.use(VueQueryPlugin, { queryClient });
66
- await renderToString(app);
67
-
68
- return { deleteAction, queryClient, router };
69
- }
70
-
71
- test("useCrudDeleteAction confirms one DELETE, invalidates CRUD state, and returns to the list", async () => {
72
- const requests = [];
73
- const invalidations = [];
74
- let finishRequest = null;
75
- const queryClient = new QueryClient();
76
- queryClient.invalidateQueries = async function invalidateQueries(options = {}) {
77
- invalidations.push(options);
78
- };
79
- const pendingRequest = new Promise((resolve) => {
80
- finishRequest = resolve;
81
- });
82
- const client = {
83
- async request(path, options = {}) {
84
- requests.push({ path, options });
85
- return pendingRequest;
86
- }
87
- };
88
- const { deleteAction, router } = await renderDeleteAction({ client, queryClient });
89
-
90
- assert.equal(deleteAction.canDelete, true);
91
- assert.equal(deleteAction.request(), true);
92
- assert.equal(deleteAction.isOpen, true);
93
-
94
- const confirmation = deleteAction.confirm();
95
- await nextTick();
96
- assert.equal(deleteAction.isDeleting, true);
97
- assert.equal(requests.length, 1);
98
- assert.match(requests[0].path, /\/notes\/42$/);
99
- assert.equal(requests[0].options.method, "DELETE");
100
- assert.equal(Object.hasOwn(requests[0].options, "body"), false);
101
-
102
- finishRequest(null);
103
- await confirmation;
104
-
105
- assert.equal(deleteAction.isDeleting, false);
106
- assert.equal(deleteAction.isOpen, false);
107
- assert.equal(router.currentRoute.value.path, "/notes");
108
- assert.deepEqual(invalidations, [
109
- { queryKey: ["ui-generator", "notes"] }
110
- ]);
111
- });
112
-
113
- test("useCrudDeleteAction keeps the record dialog open with useful error feedback", async () => {
114
- const client = {
115
- async request() {
116
- throw new Error("Delete service unavailable.");
117
- }
118
- };
119
- const { deleteAction, router } = await renderDeleteAction({ client });
120
-
121
- deleteAction.request();
122
- await deleteAction.confirm();
123
-
124
- assert.equal(deleteAction.isOpen, true);
125
- assert.equal(deleteAction.isDeleting, false);
126
- assert.equal(deleteAction.error, "Delete service unavailable.");
127
- assert.equal(router.currentRoute.value.path, "/notes/42");
128
- });
129
-
130
- test("useCrudDeleteAction rejects resources without the canonical DELETE operation", () => {
131
- assert.throws(
132
- () => requireCrudDeleteOperation({ operations: {} }),
133
- /requires resource\.operations\.delete/
134
- );
135
- assert.throws(
136
- () => requireCrudDeleteOperation({ operations: { delete: { method: "POST" } } }),
137
- /method to be DELETE/
138
- );
139
- });
@@ -1,65 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import test from "node:test";
3
- import { nextTick } from "vue";
4
-
5
- test("useCrudListBulkActions manages selection and executes action context", async () => {
6
- const { defineCrudListBulkActions } = await import("@jskit-ai/users-web/client/bulkActions");
7
- const { useCrudListBulkActions } = await import("@jskit-ai/users-web/client/composables/useCrudListBulkActions");
8
- const calls = [];
9
- const actions = defineCrudListBulkActions([
10
- {
11
- key: "archive",
12
- label: "Archive",
13
- async run(context) {
14
- calls.push(context);
15
- context.clearSelection();
16
- }
17
- }
18
- ]);
19
- const runtime = useCrudListBulkActions(actions, {
20
- resolveRecordId: (record) => record.id,
21
- resolveContext: () => ({
22
- reload: "reload-token"
23
- })
24
- });
25
-
26
- assert.equal(runtime.hasActions.value, true);
27
- assert.equal(runtime.hasSelection.value, false);
28
-
29
- runtime.setRecordSelected({ id: "10", label: "A" }, 0, true);
30
- runtime.setRecordSelected({ id: "11", label: "B" }, 1, true);
31
- await nextTick();
32
-
33
- assert.deepEqual(runtime.selectedIds.value, ["10", "11"]);
34
- assert.equal(runtime.selectedCount.value, 2);
35
- assert.equal(runtime.allVisibleSelected([{ id: "10" }, { id: "11" }]), true);
36
- assert.equal(runtime.someVisibleSelected([{ id: "10" }, { id: "12" }]), true);
37
-
38
- await runtime.execute("archive");
39
-
40
- assert.equal(calls.length, 1);
41
- assert.deepEqual(calls[0].selectedIds, ["10", "11"]);
42
- assert.deepEqual(calls[0].ids, ["10", "11"]);
43
- assert.equal(calls[0].reload, "reload-token");
44
- assert.equal(runtime.selectedCount.value, 0);
45
- });
46
-
47
- test("defineCrudListBulkActions skips malformed and duplicate actions", async () => {
48
- const { defineCrudListBulkActions } = await import("@jskit-ai/users-web/client/bulkActions");
49
-
50
- const actions = defineCrudListBulkActions([
51
- null,
52
- { key: "archive", label: "Archive" },
53
- { key: "archive", label: "Archive again" },
54
- { key: "missing-label" },
55
- { label: "Generated key" }
56
- ]);
57
-
58
- assert.deepEqual(
59
- actions.map((action) => [action.key, action.label, action.color, action.variant]),
60
- [
61
- ["archive", "Archive", "primary", "tonal"],
62
- ["action-5", "Generated key", "primary", "tonal"]
63
- ]
64
- );
65
- });