aloha-vue 2.81.0 → 2.83.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/aloha-vue.es.js +619 -274
  3. package/dist/aloha-vue.umd.js +17 -17
  4. package/package.json +1 -1
  5. package/src/AModalForm/AModalForm.js +12 -0
  6. package/src/ui/ACheckbox/ACheckbox.js +11 -0
  7. package/src/ui/ACheckbox/ACheckboxItem/ACheckboxItem.js +6 -0
  8. package/src/ui/ADatepicker/ADatepicker.js +6 -0
  9. package/src/ui/ADatepickerRange/ADatepickerRange.js +6 -1
  10. package/src/ui/AFieldset/AFieldset.js +7 -1
  11. package/src/ui/AForm/AForm.js +6 -0
  12. package/src/ui/AFormElement/AFormElement.js +5 -0
  13. package/src/ui/AFormReadonly/AFormReadonly.js +1 -1
  14. package/src/ui/AGroup/AGroup.js +8 -1
  15. package/src/ui/AInput/AInput.js +6 -0
  16. package/src/ui/AInputCurrency/AInputCurrency.js +6 -0
  17. package/src/ui/AInputFile/AInputFile.js +40 -5
  18. package/src/ui/AInputNumber/AInputNumber.js +6 -0
  19. package/src/ui/AInputNumberRange/AInputNumberRange.js +6 -1
  20. package/src/ui/AJson/AJson.js +6 -0
  21. package/src/ui/AMultiselectOrdered/AMultiselectOrdered.js +35 -24
  22. package/src/ui/AOneCheckbox/AOneCheckbox.js +6 -0
  23. package/src/ui/ARadio/ARadio.js +11 -0
  24. package/src/ui/ARadio/ARadioItem/ARadioItem.js +6 -0
  25. package/src/ui/ARouterLinkConfig/ARouterLinkConfig.js +7 -0
  26. package/src/ui/ASelect/ASelect.js +11 -0
  27. package/src/ui/ASelectIcon/ASelectIcon.js +16 -11
  28. package/src/ui/ASelectStyle/ASelectStyle.js +16 -11
  29. package/src/ui/ASlider/ASlider.js +6 -0
  30. package/src/ui/ASwitch/ASwitch.js +11 -5
  31. package/src/ui/ATemplate/ATemplate.js +7 -2
  32. package/src/ui/ATextarea/ATextarea.js +6 -0
  33. package/src/ui/AValidatedJson/AValidatedJson.js +10 -2
  34. package/src/ui/AValidatedJson/AValidatedJsonItem/AValidatedJsonItem.js +6 -0
  35. package/src/ui/__tests__/ReadonlyValueParentClass.test.js +217 -0
  36. package/src/ui/compositionApi/UiDataFromServerAPI.js +14 -10
  37. package/src/ui/compositionApi/UiUrlAPI.js +30 -0
  38. package/src/ui/compositionApi/__tests__/UiUrlAPI.test.js +149 -0
@@ -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
+ });