aloha-vue 2.82.0 → 2.84.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aloha-vue",
3
- "version": "2.82.0",
3
+ "version": "2.84.0",
4
4
  "description": "Aloha-vue is a JavaScript library that provides a wide range of accessible components and directives for Vue.js. Accessibility is of paramount importance to us, and we have designed all our components to meet accessibility compliance criteria. This library is a valuable tool for frontend developers and has already been used in three projects, including two large-scale ones",
5
5
  "keywords": [
6
6
  "accessibility compliance criteria",
@@ -41,6 +41,16 @@ export default {
41
41
  required: false,
42
42
  default: undefined,
43
43
  },
44
+ classColumns: {
45
+ type: [String, Object],
46
+ required: false,
47
+ default: undefined,
48
+ },
49
+ classColumnDefault: {
50
+ type: [String, Object],
51
+ required: false,
52
+ default: undefined,
53
+ },
44
54
  classExtra: {
45
55
  type: [String, Object],
46
56
  required: false,
@@ -361,6 +371,8 @@ export default {
361
371
  }),
362
372
  this.hasDataForm && h(AForm, {
363
373
  alwaysTranslate: this.alwaysTranslate,
374
+ classColumns: this.classColumns,
375
+ classColumnDefault: this.classColumnDefault,
364
376
  modelValue: this.modelValue,
365
377
  data: this.dataForm,
366
378
  errors: this.errors,
@@ -530,12 +530,9 @@ export default {
530
530
  modelIsTableWithoutScrollComputed,
531
531
  } = SimpleTableAPI(props);
532
532
 
533
- const {
534
- countAllRowsLocal,
535
- } = CountAPI(props);
536
-
537
533
  const {
538
534
  columnsScrollInvisible,
535
+ currentMultipleActions,
539
536
  indexFirstScrollInvisibleColumn,
540
537
  isMultipleActionsActive,
541
538
  modelColumnsVisibleLocal,
@@ -572,10 +569,10 @@ export default {
572
569
  const {
573
570
  columnsOrderedFromSimpleTable,
574
571
  renderedGroupedColumns,
575
- } = ColumnsGroupedAPI(props, {
576
- modelSort: modelSortLocal,
577
- slots: context.slots,
578
- });
572
+ } = ColumnsGroupedAPI(props, {
573
+ modelSort: modelSortLocal,
574
+ slots: context.slots,
575
+ });
579
576
 
580
577
  const {
581
578
  columnIdsGroupByLocked,
@@ -609,6 +606,7 @@ export default {
609
606
 
610
607
  const {
611
608
  addRow,
609
+ dataFiltered,
612
610
  deleteRow,
613
611
  hasRows,
614
612
  rowsLocal,
@@ -617,13 +615,21 @@ export default {
617
615
  stopRenderRows,
618
616
  updateRow,
619
617
  } = RowsAPI(props, {
618
+ currentMultipleActions,
620
619
  dataSorted,
620
+ isMultipleActionsActive,
621
621
  limit,
622
622
  offset,
623
623
  setEmptySelectedRowsIndexes,
624
624
  usePaginationLocal,
625
625
  });
626
626
 
627
+ const {
628
+ countAllRowsLocal,
629
+ } = CountAPI(props, {
630
+ data: dataFiltered,
631
+ });
632
+
627
633
  const {
628
634
  columnActionsBtnGroupMaxWidthStyle,
629
635
  columnActionsWidthLocal,
@@ -678,7 +684,6 @@ export default {
678
684
  areAllVisibleRowsSelected,
679
685
  areSomeRowsSelected,
680
686
  closeMultipleActionsActive,
681
- currentMultipleActions,
682
687
  hasMultipleActions,
683
688
  selectedRows,
684
689
  selectedRowsIndexes,
@@ -688,6 +693,7 @@ export default {
688
693
  toggleMultipleActionsActive,
689
694
  } = MultipleActionAPI(props, context, {
690
695
  checkVisibleColumns,
696
+ currentMultipleActions,
691
697
  isMultipleActionsActive,
692
698
  rowsLocalAll,
693
699
  rowsLocalLength,
@@ -1001,7 +1007,7 @@ export default {
1001
1007
  onSetSelectedRowsIndexes: this.setSelectedRowsIndexes,
1002
1008
  columnsForRender: this.renderedGroupedColumns,
1003
1009
  }) :
1004
- h(ATableHeader, {
1010
+ h(ATableHeader, {
1005
1011
  areAllRowsSelected: this.areAllRowsSelected,
1006
1012
  areAllVisibleRowsSelected: this.areAllVisibleRowsSelected,
1007
1013
  areSomeRowsSelected: this.areSomeRowsSelected,
@@ -1014,8 +1020,8 @@ export default {
1014
1020
  rowsLocalLength: this.rowsLocalLength,
1015
1021
  showFirstSortingSequenceNumber: this.showFirstSortingSequenceNumber,
1016
1022
  sortingSequenceNumberClass: this.sortingSequenceNumberClass,
1017
- onSetSelectedRowsIndexes: this.setSelectedRowsIndexes,
1018
- }, this.$slots),
1023
+ onSetSelectedRowsIndexes: this.setSelectedRowsIndexes,
1024
+ }, this.$slots),
1019
1025
  h("div", {
1020
1026
  class: "a_table__loading",
1021
1027
  }, [
@@ -1050,10 +1056,10 @@ export default {
1050
1056
  level: 1,
1051
1057
  row,
1052
1058
  rowActionsClass: this.rowActionsClass,
1053
- rowClass: this.rowClass,
1054
- rowIndex,
1055
- rowIndexPath: `${ rowIndex }`,
1056
- rowsLength: this.rowsLocal.length,
1059
+ rowClass: this.rowClass,
1060
+ rowIndex,
1061
+ rowIndexPath: `${ rowIndex }`,
1062
+ rowsLength: this.rowsLocal.length,
1057
1063
  selectedRowsIndexes: this.selectedRowsIndexes,
1058
1064
  onSetSelectedRowsIndexes: this.setSelectedRowsIndexes,
1059
1065
  }, {
@@ -1101,10 +1107,10 @@ export default {
1101
1107
  level: 1,
1102
1108
  row,
1103
1109
  rowActionsClass: this.rowActionsClass,
1104
- rowClass: this.rowClass,
1105
- rowIndex,
1106
- rowIndexPath: `${ rowIndex }`,
1107
- rowsLength: this.rowsFooter.length,
1110
+ rowClass: this.rowClass,
1111
+ rowIndex,
1112
+ rowIndexPath: `${ rowIndex }`,
1113
+ rowsLength: this.rowsFooter.length,
1108
1114
  selectedRowsIndexes: this.selectedRowsIndexes,
1109
1115
  onSetSelectedRowsIndexes: this.setSelectedRowsIndexes,
1110
1116
  }, {
@@ -0,0 +1,86 @@
1
+ import {
2
+ nextTick,
3
+ ref,
4
+ } from "vue";
5
+ import {
6
+ describe,
7
+ expect,
8
+ it,
9
+ vi,
10
+ } from "vitest";
11
+
12
+ import CountAPI from "../compositionAPI/CountAPI";
13
+ import MultipleActionAPI from "../compositionAPI/MultipleActionAPI";
14
+ import RowsAPI from "../compositionAPI/RowsAPI";
15
+ import VariablesAPI from "../compositionAPI/VariablesAPI";
16
+
17
+ describe("ATable multiple action row filtering", () => {
18
+ it("filters before pagination, updates counts and selection, and restores rows on close", async() => {
19
+ const data = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }];
20
+ const callback = vi.fn(({ row }) => row.id === 2);
21
+ const props = {
22
+ clearSelectedRowsOnDataChange: true,
23
+ data,
24
+ multipleActions: [],
25
+ pagination: { isOutside: false },
26
+ rowsCountRenderPerTick: 0,
27
+ };
28
+ const {
29
+ currentMultipleActions,
30
+ isMultipleActionsActive,
31
+ } = VariablesAPI();
32
+ const clearSelection = vi.fn();
33
+ const rows = RowsAPI(props, {
34
+ currentMultipleActions,
35
+ dataSorted: ref(data),
36
+ isMultipleActionsActive,
37
+ limit: ref(2),
38
+ offset: ref(0),
39
+ setEmptySelectedRowsIndexes: clearSelection,
40
+ usePaginationLocal: ref(true),
41
+ });
42
+ const { countAllRowsLocal } = CountAPI(props, { data: rows.dataFiltered });
43
+ const actions = MultipleActionAPI(props, { emit: vi.fn() }, {
44
+ currentMultipleActions,
45
+ isMultipleActionsActive,
46
+ rowsLocalAll: rows.rowsLocalAll,
47
+ rowsLocalLength: rows.rowsLocalLength,
48
+ });
49
+
50
+ currentMultipleActions.value = { isRowHiddenCallback: callback };
51
+ expect(rows.rowsLocal.value).toEqual(data.slice(0, 2));
52
+ expect(callback).not.toHaveBeenCalled();
53
+
54
+ isMultipleActionsActive.value = true;
55
+ await nextTick();
56
+
57
+ expect(rows.rowsLocal.value).toEqual([data[0], data[2]]);
58
+ expect(countAllRowsLocal.value).toBe(3);
59
+ expect(callback).toHaveBeenCalledWith({ row: data[1], rowIndex: 1 });
60
+ expect(clearSelection).toHaveBeenCalledOnce();
61
+ actions.setSelectedRowsIndexes({ isAll: true });
62
+ expect(actions.selectedRows.value).toEqual([data[0], data[2]]);
63
+
64
+ actions.closeMultipleActionsActive();
65
+ await nextTick();
66
+
67
+ expect(rows.rowsLocal.value).toEqual(data.slice(0, 2));
68
+ expect(countAllRowsLocal.value).toBe(4);
69
+ expect(actions.selectedRows.value).toEqual([]);
70
+ expect(props.data).toEqual(data);
71
+ });
72
+
73
+ it.each([undefined, {}, { isRowHiddenCallback: true }, { isHiddenCallback: () => true }])(
74
+ "keeps rows when the active action has no row callback: %j",
75
+ action => {
76
+ const data = [{ id: 1 }];
77
+ const { rowsLocal } = RowsAPI({ pagination: {}, rowsCountRenderPerTick: 0 }, {
78
+ currentMultipleActions: ref(action),
79
+ dataSorted: ref(data),
80
+ isMultipleActionsActive: ref(true),
81
+ });
82
+
83
+ expect(rowsLocal.value).toEqual(data);
84
+ },
85
+ );
86
+ });
@@ -14,9 +14,10 @@ import {
14
14
  isPlainObject,
15
15
  } from "lodash-es";
16
16
 
17
- export default function CountAPI(props) {
17
+ export default function CountAPI(props, {
18
+ data = toRef(props, "data"),
19
+ } = {}) {
18
20
  const countAllRows = toRef(props, "countAllRows");
19
- const data = toRef(props, "data");
20
21
  const isTree = toRef(props, "isTree");
21
22
  const keyChildren = toRef(props, "keyChildren");
22
23
  const keyCountAllRowsInData = toRef(props, "keyCountAllRowsInData");
@@ -21,6 +21,7 @@ import {
21
21
 
22
22
  export default function MultipleActionAPI(props, { emit }, {
23
23
  checkVisibleColumns = () => {},
24
+ currentMultipleActions = ref(undefined),
24
25
  isMultipleActionsActive = ref(undefined),
25
26
  rowsLocalAll = computed(() => []),
26
27
  rowsLocalLength = computed(() => 0),
@@ -28,7 +29,6 @@ export default function MultipleActionAPI(props, { emit }, {
28
29
  const id = toRef(props, "id");
29
30
  const multipleActions = toRef(props, "multipleActions");
30
31
 
31
- const currentMultipleActions = ref(undefined);
32
32
  const selectedRowsIndexes = ref({});
33
33
  const areAllRowsSelected = ref(false);
34
34
 
@@ -7,11 +7,14 @@ import {
7
7
 
8
8
  import {
9
9
  isEqual,
10
+ isFunction,
10
11
  map,
11
12
  } from "lodash-es";
12
13
 
13
14
  export default function RowsAPI(props, {
15
+ currentMultipleActions = ref(undefined),
14
16
  dataSorted = computed(() => []),
17
+ isMultipleActionsActive = ref(undefined),
15
18
  limit = ref(0),
16
19
  offset = ref(0),
17
20
  setEmptySelectedRowsIndexes = () => {},
@@ -27,13 +30,22 @@ export default function RowsAPI(props, {
27
30
  let rowsLocalIndex = 0;
28
31
  let rowsLocalInterval = undefined;
29
32
 
33
+ const dataFiltered = computed(() => {
34
+ if (isMultipleActionsActive.value && isFunction(currentMultipleActions.value?.isRowHiddenCallback)) {
35
+ return dataSorted.value.filter((row, rowIndex) => {
36
+ return !currentMultipleActions.value.isRowHiddenCallback({ row, rowIndex });
37
+ });
38
+ }
39
+ return dataSorted.value;
40
+ });
41
+
30
42
  const dataPaginated = computed(() => {
31
43
  if (limit.value && !pagination.value.isOutside && usePaginationLocal.value) {
32
44
  const INDEX_START = offset.value;
33
45
  const INDEX_END = INDEX_START + limit.value;
34
- return dataSorted.value.slice(INDEX_START, INDEX_END);
46
+ return dataFiltered.value.slice(INDEX_START, INDEX_END);
35
47
  }
36
- return dataSorted.value;
48
+ return dataFiltered.value;
37
49
  });
38
50
 
39
51
  const rowsLocalAll = computed(() => {
@@ -110,6 +122,7 @@ export default function RowsAPI(props, {
110
122
 
111
123
  return {
112
124
  addRow,
125
+ dataFiltered,
113
126
  deleteRow,
114
127
  hasRows,
115
128
  rowsLocal,
@@ -4,6 +4,7 @@ import {
4
4
 
5
5
  export default function VariablesAPI() {
6
6
  const columnsScrollInvisible = ref([]);
7
+ const currentMultipleActions = ref(undefined);
7
8
  const indexFirstScrollInvisibleColumn = ref(undefined);
8
9
  const isMultipleActionsActive = ref(undefined);
9
10
  const modelColumnsVisibleLocal = ref({});
@@ -12,6 +13,7 @@ export default function VariablesAPI() {
12
13
 
13
14
  return {
14
15
  columnsScrollInvisible,
16
+ currentMultipleActions,
15
17
  indexFirstScrollInvisibleColumn,
16
18
  isMultipleActionsActive,
17
19
  modelColumnsVisibleLocal,
@@ -386,6 +386,11 @@ export default {
386
386
  required: false,
387
387
  default: undefined,
388
388
  },
389
+ urlTemplateData: {
390
+ type: Object,
391
+ required: false,
392
+ default: undefined,
393
+ },
389
394
  },
390
395
  emits: [
391
396
  "focusin",
@@ -478,6 +478,11 @@ export default {
478
478
  required: false,
479
479
  default: undefined,
480
480
  },
481
+ urlTemplateData: {
482
+ type: Object,
483
+ required: false,
484
+ default: undefined,
485
+ },
481
486
  },
482
487
  emits: [
483
488
  "blur",
@@ -397,6 +397,11 @@ export default {
397
397
  required: false,
398
398
  default: undefined,
399
399
  },
400
+ urlTemplateData: {
401
+ type: Object,
402
+ required: false,
403
+ default: undefined,
404
+ },
400
405
  },
401
406
  emits: [
402
407
  "focusin",
@@ -537,6 +537,11 @@ export default {
537
537
  required: false,
538
538
  default: undefined,
539
539
  },
540
+ urlTemplateData: {
541
+ type: Object,
542
+ required: false,
543
+ default: undefined,
544
+ },
540
545
  },
541
546
  emits: [
542
547
  "blur",
@@ -6,6 +6,7 @@ import {
6
6
  } from "vue";
7
7
 
8
8
  import AHttpAPI from "../../compositionAPI/AHttpAPI";
9
+ import UiUrlAPI from "./UiUrlAPI";
9
10
 
10
11
  import {
11
12
  ADataRetrievePluginOptions,
@@ -48,11 +49,14 @@ export default function UiDataFromServerAPI(props, {
48
49
  const modelValue = toRef(props, "modelValue");
49
50
  const searchApiKey = toRef(props, "searchApiKey");
50
51
  const type = toRef(props, "type");
51
- const url = toRef(props, "url");
52
52
  const urlRetrieve = toRef(props, "urlRetrieve");
53
53
  const urlParams = toRef(props, "urlParams");
54
54
  const urlRetrieveParams = toRef(props, "urlRetrieveParams");
55
55
 
56
+ const {
57
+ urlLocal,
58
+ } = UiUrlAPI(props);
59
+
56
60
  const loadingSearchApi = ref(false);
57
61
  const loadingDataFromServer = ref(undefined);
58
62
  const loadingRequestCount = ref(0);
@@ -72,7 +76,7 @@ export default function UiDataFromServerAPI(props, {
72
76
  };
73
77
 
74
78
  const searchApiLocal = computed(() => {
75
- return !!(searchApi.value && searchApiKey.value && url.value);
79
+ return !!(searchApi.value && searchApiKey.value && urlLocal.value);
76
80
  });
77
81
 
78
82
  const retrieveCallback = computed(() => {
@@ -80,7 +84,7 @@ export default function UiDataFromServerAPI(props, {
80
84
  });
81
85
 
82
86
  const urlRetrieveLocal = computed(() => {
83
- return urlRetrieve.value || url.value;
87
+ return urlRetrieve.value || urlLocal.value;
84
88
  });
85
89
 
86
90
  const urlRetrieveParamsLocal = computed(() => {
@@ -97,7 +101,7 @@ export default function UiDataFromServerAPI(props, {
97
101
  const urlPropsComputed = computed(() => {
98
102
  return [
99
103
  apiSaveId.value,
100
- url.value,
104
+ urlLocal.value,
101
105
  urlParams.value,
102
106
  ];
103
107
  });
@@ -143,13 +147,13 @@ export default function UiDataFromServerAPI(props, {
143
147
  };
144
148
 
145
149
  const loadDataFromServer = () => {
146
- if (!url.value || searchApiLocal.value) {
150
+ if (!urlLocal.value || searchApiLocal.value) {
147
151
  dataFromServer.value = [];
148
152
  return;
149
153
  }
150
154
  startLoading();
151
155
  getListHttp({
152
- url: url.value,
156
+ url: urlLocal.value,
153
157
  urlParams: urlParams.value,
154
158
  apiSaveId: apiSaveId.value,
155
159
  }).then(
@@ -241,7 +245,7 @@ export default function UiDataFromServerAPI(props, {
241
245
 
242
246
  const isRetrieveInvalidEntries = computed(() => {
243
247
  return !searchApiLocal.value &&
244
- !!(url.value || data.value?.length);
248
+ !!(urlLocal.value || data.value?.length);
245
249
  });
246
250
 
247
251
  const prepareRetrieveResponse = ({ response = [] } = {}) => {
@@ -291,7 +295,7 @@ export default function UiDataFromServerAPI(props, {
291
295
  }
292
296
  loadingSearchApi.value = true;
293
297
  getListHttp({
294
- url: url.value,
298
+ url: urlLocal.value,
295
299
  urlParams: {
296
300
  ...(urlParams.value || {}),
297
301
  [searchApiKey.value]: search,
@@ -335,7 +339,7 @@ export default function UiDataFromServerAPI(props, {
335
339
  },
336
340
  };
337
341
  return getListHttp({
338
- url: url.value,
342
+ url: urlLocal.value,
339
343
  urlParams: URL_PARAMS,
340
344
  }).then(
341
345
  response => {
@@ -400,7 +404,7 @@ export default function UiDataFromServerAPI(props, {
400
404
  });
401
405
 
402
406
  watch(data, (newVal, oldVal) => {
403
- if (!url.value &&
407
+ if (!urlLocal.value &&
404
408
  !isEqual(newVal, oldVal)) {
405
409
  syncDataFromRetrieve();
406
410
  loadDataFromServerForRetrieve();
@@ -0,0 +1,30 @@
1
+ import {
2
+ computed,
3
+ toRef,
4
+ } from "vue";
5
+
6
+ import UtilsAPI from "../../ATranslation/compositionAPI/UtilsAPI";
7
+
8
+ export default function UiUrlAPI(props) {
9
+ const url = toRef(props, "url");
10
+ const urlTemplateData = toRef(props, "urlTemplateData");
11
+
12
+ const {
13
+ replaceText,
14
+ } = UtilsAPI();
15
+
16
+ const urlLocal = computed(() => {
17
+ if (!url.value?.includes("{{") || !url.value.includes("}}")) {
18
+ return url.value;
19
+ }
20
+
21
+ return replaceText({
22
+ text: url.value,
23
+ object: urlTemplateData.value,
24
+ });
25
+ });
26
+
27
+ return {
28
+ urlLocal,
29
+ };
30
+ }
@@ -0,0 +1,149 @@
1
+ import {
2
+ effectScope,
3
+ nextTick,
4
+ reactive,
5
+ watch,
6
+ } from "vue";
7
+ import {
8
+ afterEach,
9
+ describe,
10
+ expect,
11
+ it,
12
+ vi,
13
+ } from "vitest";
14
+ import {
15
+ flushPromises,
16
+ } from "@vue/test-utils";
17
+
18
+ import UiDataFromServerAPI from "../UiDataFromServerAPI";
19
+ import UiUrlAPI from "../UiUrlAPI";
20
+
21
+ const { getListHttp } = vi.hoisted(() => ({
22
+ getListHttp: vi.fn(() => Promise.resolve([])),
23
+ }));
24
+
25
+ vi.mock("../../../compositionAPI/AHttpAPI", () => ({
26
+ default: () => ({ getListHttp }),
27
+ }));
28
+
29
+ let scope;
30
+
31
+ afterEach(() => {
32
+ scope?.stop();
33
+ getListHttp.mockClear();
34
+ });
35
+
36
+ describe("UI URL templates", () => {
37
+ it.each([undefined, "", "foo/bar/", "foo/{{ id/"])("preserves URL %s without a complete placeholder", url => {
38
+ const props = reactive({ url, urlTemplateData: { id: 1 } });
39
+ const { urlLocal } = UiUrlAPI(props);
40
+
41
+ expect(urlLocal.value).toBe(url);
42
+ props.urlTemplateData.id = 2;
43
+ expect(urlLocal.value).toBe(url);
44
+ });
45
+
46
+ it("uses translation placeholders with nested paths and repeated values", () => {
47
+ const props = reactive({
48
+ url: "foo/{{ id }}/bar/{{ aloha.bar }}/{{id}}/",
49
+ urlTemplateData: { id: 0, aloha: { bar: false } },
50
+ });
51
+ const { urlLocal } = UiUrlAPI(props);
52
+
53
+ expect(urlLocal.value).toBe("foo/0/bar/false/0/");
54
+ props.urlTemplateData.aloha.bar = "baz";
55
+ expect(urlLocal.value).toBe("foo/0/bar/baz/0/");
56
+ });
57
+
58
+ it.each([false, true])("only calls the URL watcher when the resolved URL changes (deep: %s)", async deep => {
59
+ const props = reactive({
60
+ url: "foo/{{ id }}/bar/{{ aloha.bar }}/",
61
+ urlTemplateData: { id: 1, aloha: { bar: "baz" }, unused: 0 },
62
+ });
63
+ const callback = vi.fn();
64
+ let api;
65
+ scope = effectScope();
66
+ scope.run(() => {
67
+ api = UiDataFromServerAPI(props);
68
+ watch(api.urlPropsComputed, callback, { deep });
69
+ });
70
+
71
+ props.urlTemplateData.unused++;
72
+ await nextTick();
73
+ props.urlTemplateData = { id: 1, aloha: { bar: "baz" }, unused: 2 };
74
+ await nextTick();
75
+ props.urlTemplateData.id = "1";
76
+ await nextTick();
77
+ expect(callback).not.toHaveBeenCalled();
78
+
79
+ props.urlTemplateData.aloha.bar = "new";
80
+ await nextTick();
81
+ expect(callback).toHaveBeenCalledTimes(1);
82
+ expect(api.urlPropsComputed.value[1]).toBe("foo/1/bar/new/");
83
+
84
+ props.url = "other/{{ id }}/";
85
+ await nextTick();
86
+ expect(callback).toHaveBeenCalledTimes(2);
87
+ });
88
+
89
+ it("reloads using the resolved URL and resets the model only when it changes", async() => {
90
+ const props = reactive({
91
+ url: "foo/{{ id }}/",
92
+ urlTemplateData: { id: 1 },
93
+ urlParams: { limit: 10 },
94
+ });
95
+ const changeModel = vi.fn();
96
+ scope = effectScope();
97
+ scope.run(() => {
98
+ const api = UiDataFromServerAPI(props, { changeModel });
99
+ watch(api.urlPropsComputed, api.updateUrlPropsComputed);
100
+ api.loadDataFromServer();
101
+ });
102
+ await flushPromises();
103
+ expect(getListHttp).toHaveBeenLastCalledWith(expect.objectContaining({
104
+ url: "foo/1/",
105
+ urlParams: { limit: 10 },
106
+ }));
107
+
108
+ props.urlTemplateData = { id: 1, unused: true };
109
+ await flushPromises();
110
+ expect(getListHttp).toHaveBeenCalledTimes(1);
111
+ expect(changeModel).not.toHaveBeenCalled();
112
+
113
+ props.urlTemplateData.id = 2;
114
+ await flushPromises();
115
+ expect(getListHttp).toHaveBeenCalledTimes(2);
116
+ expect(getListHttp).toHaveBeenLastCalledWith(expect.objectContaining({ url: "foo/2/" }));
117
+ expect(changeModel).toHaveBeenCalledTimes(1);
118
+ });
119
+
120
+ it("uses the resolved URL for search and the retrieve fallback", async() => {
121
+ const props = reactive({
122
+ url: "foo/{{ id }}/",
123
+ urlTemplateData: { id: 1 },
124
+ searchApi: true,
125
+ searchApiKey: "search",
126
+ keyId: "pk",
127
+ modelValue: 42,
128
+ });
129
+ scope = effectScope();
130
+ const api = scope.run(() => UiDataFromServerAPI(props));
131
+
132
+ api.onSearchInApi({ search: "hello" });
133
+ await flushPromises();
134
+ expect(getListHttp).toHaveBeenLastCalledWith({
135
+ url: "foo/1/",
136
+ urlParams: { search: "hello" },
137
+ });
138
+
139
+ await api.loadDataFromServerForRetrieve();
140
+ expect(getListHttp).toHaveBeenLastCalledWith({
141
+ url: "foo/1/",
142
+ urlParams: { pk: [42], limit: 1 },
143
+ });
144
+
145
+ props.urlRetrieve = "retrieve/";
146
+ await flushPromises();
147
+ expect(getListHttp).toHaveBeenLastCalledWith(expect.objectContaining({ url: "retrieve/" }));
148
+ });
149
+ });