@shopware/composables 1.12.1 → 1.14.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/README.md +40 -12
- package/dist/index.d.mts +130 -20
- package/dist/index.d.ts +130 -20
- package/dist/index.mjs +95 -30
- package/package.json +11 -10
- package/src/cms/useCmsElementConfig.test.ts +38 -0
- package/src/cms/useCmsElementConfig.ts +13 -12
- package/src/cms/useCmsElementImage.test.ts +139 -0
- package/src/cms/useCmsElementImage.ts +19 -1
- package/src/index.test.ts +19 -1
- package/src/index.ts +9 -4
- package/src/types/cmsBlockTypes.ts +12 -0
- package/src/types/cmsElementTypes.ts +58 -2
- package/src/useAddToCart/useAddToCart.test.ts +17 -17
- package/src/useB2bQuoteManagement/useB2bQuoteManagement.test.ts +61 -1
- package/src/useB2bQuoteManagement/useB2bQuoteManagement.ts +121 -14
- package/src/useCategorySearch/useCategorySearch.test.ts +2 -2
- package/src/useCategorySearch/useCategorySearch.ts +3 -1
- package/src/useCmsBlock/useCmsBlock.test.ts +47 -13
- package/src/useCmsBlock/useCmsBlock.ts +17 -7
- package/src/useCmsSection/useCmsSection.test.ts +48 -5
- package/src/useCmsSection/useCmsSection.ts +11 -5
- package/src/useInternationalization/useInternationalization.test.ts +154 -0
- package/src/useInternationalization/useInternationalization.ts +21 -2
- package/src/useListing/useListing.ts +3 -1
- package/src/useNotifications/useNotifications.test.ts +19 -0
- package/src/useNotifications/useNotifications.ts +14 -1
- package/src/useProductSearch/useProductSearch.ts +1 -1
- package/src/useUser/useUser.test.ts +24 -0
- package/src/useUser/useUser.ts +2 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { ref } from "vue";
|
|
2
3
|
|
|
3
4
|
import type {
|
|
4
5
|
CmsElementBuyBox,
|
|
5
6
|
CmsElementForm,
|
|
6
7
|
CmsElementImage,
|
|
8
|
+
CmsElementText,
|
|
7
9
|
} from "../types";
|
|
8
10
|
import { useCmsElementConfig } from "./useCmsElementConfig";
|
|
9
11
|
|
|
@@ -149,6 +151,42 @@ describe("useCmsElementConfig", () => {
|
|
|
149
151
|
expect(getConfigValue("defaultMailReceiver")).toEqual(false);
|
|
150
152
|
expect(getConfigValue("mailReceiver")).toEqual(["first", "second"]);
|
|
151
153
|
});
|
|
154
|
+
|
|
155
|
+
it("should not return the mapping path of a mapped value", () => {
|
|
156
|
+
const { getConfigValue } = useCmsElementConfig({
|
|
157
|
+
config: {
|
|
158
|
+
content: { source: "mapped", value: "category.name" },
|
|
159
|
+
},
|
|
160
|
+
} as unknown as CmsElementText);
|
|
161
|
+
|
|
162
|
+
expect(getConfigValue("content")).toBe(false);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("should follow a ref passed as element", () => {
|
|
166
|
+
const element = ref({
|
|
167
|
+
config: { alignment: { source: "static", value: "flex-start" } },
|
|
168
|
+
} as unknown as CmsElementBuyBox);
|
|
169
|
+
const { getConfigValue } = useCmsElementConfig(element);
|
|
170
|
+
|
|
171
|
+
element.value = {
|
|
172
|
+
config: { alignment: { source: "static", value: "center" } },
|
|
173
|
+
} as unknown as CmsElementBuyBox;
|
|
174
|
+
|
|
175
|
+
expect(getConfigValue("alignment")).toBe("center");
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("should follow a getter passed as element", () => {
|
|
179
|
+
let element = {
|
|
180
|
+
config: { alignment: { source: "static", value: "flex-start" } },
|
|
181
|
+
} as unknown as CmsElementBuyBox;
|
|
182
|
+
const { getConfigValue } = useCmsElementConfig(() => element);
|
|
183
|
+
|
|
184
|
+
element = {
|
|
185
|
+
config: { alignment: { source: "static", value: "flex-end" } },
|
|
186
|
+
} as unknown as CmsElementBuyBox;
|
|
187
|
+
|
|
188
|
+
expect(getConfigValue("alignment")).toBe("flex-end");
|
|
189
|
+
});
|
|
152
190
|
});
|
|
153
191
|
});
|
|
154
192
|
});
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { toValue } from "vue";
|
|
2
|
+
import type { MaybeRefOrGetter } from "vue";
|
|
3
|
+
|
|
1
4
|
import type { Schemas } from "#shopware";
|
|
2
5
|
|
|
3
6
|
import type { ElementConfig } from "../types";
|
|
@@ -5,26 +8,24 @@ import type { ElementConfig } from "../types";
|
|
|
5
8
|
/**
|
|
6
9
|
* Composable to get cms element config
|
|
7
10
|
*
|
|
11
|
+
* `getConfigValue` reads the element on every call, so it follows a `ref` or
|
|
12
|
+
* getter passed as `element`.
|
|
13
|
+
*
|
|
8
14
|
* @category CMS (Shopping Experiences)
|
|
9
15
|
*/
|
|
10
16
|
export function useCmsElementConfig<
|
|
11
17
|
T extends Omit<Schemas["CmsSlot"], "config"> & {
|
|
12
|
-
config:
|
|
13
|
-
[key in infer X extends keyof T["config"]]: ElementConfig<unknown>;
|
|
14
|
-
}
|
|
15
|
-
? { [key in X]: ElementConfig<T["config"][key]["value"]> }
|
|
16
|
-
: never;
|
|
18
|
+
config: Record<string, ElementConfig<unknown> | undefined>;
|
|
17
19
|
},
|
|
18
|
-
>(element: T) {
|
|
20
|
+
>(element: MaybeRefOrGetter<T>) {
|
|
19
21
|
const getConfigValue = <ELEMENT_CONFIG extends keyof T["config"]>(
|
|
20
22
|
key: ELEMENT_CONFIG,
|
|
21
|
-
):
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
): NonNullable<T["config"][ELEMENT_CONFIG]>["value"] => {
|
|
24
|
+
const config = toValue(element)?.config;
|
|
25
|
+
if (!config) {
|
|
26
|
+
return undefined as NonNullable<T["config"][ELEMENT_CONFIG]>["value"];
|
|
24
27
|
}
|
|
25
|
-
return
|
|
26
|
-
element.config[key]?.source !== "mapped" && element.config[key]?.value
|
|
27
|
-
);
|
|
28
|
+
return config[key]?.source !== "mapped" && config[key]?.value;
|
|
28
29
|
};
|
|
29
30
|
|
|
30
31
|
return {
|
|
@@ -155,6 +155,145 @@ describe("useCmsElementImage", () => {
|
|
|
155
155
|
});
|
|
156
156
|
});
|
|
157
157
|
|
|
158
|
+
it("should prefer the translated media alt over the root alt", () => {
|
|
159
|
+
const { imageAttrs } = useCmsElementImage({
|
|
160
|
+
data: {
|
|
161
|
+
media: {
|
|
162
|
+
url: "https://shopware.com/logo.png",
|
|
163
|
+
alt: "Company logo",
|
|
164
|
+
translated: {
|
|
165
|
+
alt: "Firmenlogo",
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
} as unknown as CmsElementManufacturerLogo);
|
|
170
|
+
|
|
171
|
+
expect(imageAttrs.value.alt).toBe("Firmenlogo");
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("should fall back to the root media alt when translated is missing", () => {
|
|
175
|
+
const { imageAttrs } = useCmsElementImage({
|
|
176
|
+
data: {
|
|
177
|
+
media: {
|
|
178
|
+
url: "https://shopware.com/logo.png",
|
|
179
|
+
alt: "Company logo",
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
} as unknown as CmsElementManufacturerLogo);
|
|
183
|
+
|
|
184
|
+
expect(imageAttrs.value.alt).toBe("Company logo");
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("should fall back to the root media alt when the translated alt is empty", () => {
|
|
188
|
+
const { imageAttrs } = useCmsElementImage({
|
|
189
|
+
data: {
|
|
190
|
+
media: {
|
|
191
|
+
url: "https://shopware.com/logo.png",
|
|
192
|
+
alt: "Company logo",
|
|
193
|
+
translated: {
|
|
194
|
+
alt: "",
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
} as unknown as CmsElementManufacturerLogo);
|
|
199
|
+
|
|
200
|
+
expect(imageAttrs.value.alt).toBe("Company logo");
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("should return an empty alt when the media has no alt at all", () => {
|
|
204
|
+
const { imageAttrs } = useCmsElementImage({
|
|
205
|
+
data: {
|
|
206
|
+
media: {
|
|
207
|
+
url: "https://shopware.com/logo.png",
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
} as unknown as CmsElementManufacturerLogo);
|
|
211
|
+
|
|
212
|
+
expect(imageAttrs.value.alt).toBe("");
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("should keep the alt empty when media has none, the aria label names the link", () => {
|
|
216
|
+
const { imageAttrs, ariaLabel } = useCmsElementImage({
|
|
217
|
+
data: {
|
|
218
|
+
ariaLabel: "Go to the summer collection",
|
|
219
|
+
media: {
|
|
220
|
+
url: "https://shopware.com/banner.png",
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
} as unknown as CmsElementImage);
|
|
224
|
+
|
|
225
|
+
expect(ariaLabel.value).toBe("Go to the summer collection");
|
|
226
|
+
expect(imageAttrs.value.alt).toBe("");
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("should read the aria label from config when data has none", () => {
|
|
230
|
+
const { ariaLabel } = useCmsElementImage({
|
|
231
|
+
config: {
|
|
232
|
+
ariaLabel: {
|
|
233
|
+
value: "Go to the sale",
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
} as unknown as CmsElementImage);
|
|
237
|
+
|
|
238
|
+
expect(ariaLabel.value).toBe("Go to the sale");
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("should return an empty aria label when neither data nor config has one", () => {
|
|
242
|
+
const { ariaLabel } = useCmsElementImage({
|
|
243
|
+
data: {},
|
|
244
|
+
config: {},
|
|
245
|
+
} as unknown as CmsElementImage);
|
|
246
|
+
|
|
247
|
+
expect(ariaLabel.value).toBe("");
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("should drop alternative text when the image is decorative but keep the aria label", () => {
|
|
251
|
+
const { imageAttrs, isDecorative, ariaLabel } = useCmsElementImage({
|
|
252
|
+
data: {
|
|
253
|
+
ariaLabel: "Go to the sale",
|
|
254
|
+
media: {
|
|
255
|
+
url: "https://shopware.com/pattern.png",
|
|
256
|
+
alt: "ignored",
|
|
257
|
+
translated: {
|
|
258
|
+
alt: "ignoriert",
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
config: {
|
|
263
|
+
isDecorative: {
|
|
264
|
+
value: true,
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
} as unknown as CmsElementImage);
|
|
268
|
+
|
|
269
|
+
expect(isDecorative.value).toBe(true);
|
|
270
|
+
expect(imageAttrs.value.alt).toBe("");
|
|
271
|
+
// a decorative image inside a link still needs the link named
|
|
272
|
+
expect(ariaLabel.value).toBe("Go to the sale");
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("should keep the media alt when an aria label is also set", () => {
|
|
276
|
+
const { imageAttrs } = useCmsElementImage({
|
|
277
|
+
data: {
|
|
278
|
+
ariaLabel: "Go to the sale",
|
|
279
|
+
media: {
|
|
280
|
+
url: "https://shopware.com/banner.png",
|
|
281
|
+
alt: "Two mugs on a table",
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
} as unknown as CmsElementImage);
|
|
285
|
+
|
|
286
|
+
expect(imageAttrs.value.alt).toBe("Two mugs on a table");
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it("should not be decorative by default", () => {
|
|
290
|
+
const { isDecorative } = useCmsElementImage({
|
|
291
|
+
config: {},
|
|
292
|
+
} as unknown as CmsElementImage);
|
|
293
|
+
|
|
294
|
+
expect(isDecorative.value).toBe(false);
|
|
295
|
+
});
|
|
296
|
+
|
|
158
297
|
it("should return displayMode", () => {
|
|
159
298
|
const { displayMode } = useCmsElementImage({
|
|
160
299
|
config: {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getSrcSetForMedia,
|
|
3
|
+
getTranslatedProperty,
|
|
3
4
|
relativeUrlSlash,
|
|
4
5
|
urlIsAbsolute,
|
|
5
6
|
} from "@shopware/helpers";
|
|
@@ -31,6 +32,8 @@ export type UseCmsElementImage = {
|
|
|
31
32
|
imageAttrs: ComputedRef<ImgHTMLAttributes>;
|
|
32
33
|
imageContainerAttrs: ComputedRef<ImageContainerAttrs>;
|
|
33
34
|
imageLink: ComputedRef<{ newTab: boolean; url: string }>;
|
|
35
|
+
ariaLabel: ComputedRef<string>;
|
|
36
|
+
isDecorative: ComputedRef<boolean>;
|
|
34
37
|
displayMode: ComputedRef<DisplayMode>;
|
|
35
38
|
isVideoElement: ComputedRef<boolean>;
|
|
36
39
|
mimeType: ComputedRef<string | undefined>;
|
|
@@ -74,9 +77,22 @@ export function useCmsElementImage(
|
|
|
74
77
|
return attr;
|
|
75
78
|
});
|
|
76
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Names the link the image sits in, not the image itself. Shopware exposes
|
|
82
|
+
* it on both `data` and `config`.
|
|
83
|
+
*/
|
|
84
|
+
const ariaLabel = computed(
|
|
85
|
+
() => element.data?.ariaLabel || getConfigValue("ariaLabel") || "",
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
// Config only, the element data carries no such field.
|
|
89
|
+
const isDecorative = computed(() => !!getConfigValue("isDecorative"));
|
|
90
|
+
|
|
77
91
|
const imageAttrs: ComputedRef<ImgHTMLAttributes> = computed(() => ({
|
|
78
92
|
src: element.data?.media?.url,
|
|
79
|
-
alt:
|
|
93
|
+
alt: isDecorative.value
|
|
94
|
+
? ""
|
|
95
|
+
: getTranslatedProperty(element.data?.media, "alt"),
|
|
80
96
|
srcset: getSrcSetForMedia(element.data?.media),
|
|
81
97
|
}));
|
|
82
98
|
|
|
@@ -98,6 +114,8 @@ export function useCmsElementImage(
|
|
|
98
114
|
imageAttrs,
|
|
99
115
|
imageContainerAttrs,
|
|
100
116
|
imageLink,
|
|
117
|
+
ariaLabel,
|
|
118
|
+
isDecorative,
|
|
101
119
|
displayMode,
|
|
102
120
|
isVideoElement,
|
|
103
121
|
mimeType,
|
package/src/index.test.ts
CHANGED
|
@@ -8,17 +8,30 @@ import CmsPage from "./mocks/CmsPage";
|
|
|
8
8
|
|
|
9
9
|
vi.mock("vue");
|
|
10
10
|
describe("resolveCmsComponent", () => {
|
|
11
|
-
vi.spyOn(vue, "resolveComponent").mockImplementation((element) => element);
|
|
12
11
|
it("should resolve a cms component", () => {
|
|
12
|
+
vi.spyOn(vue, "resolveComponent").mockImplementation(() => ({}));
|
|
13
13
|
const section = CmsPage.cmsPage.sections?.[0];
|
|
14
14
|
const block = section?.blocks?.[0];
|
|
15
15
|
|
|
16
16
|
const result = resolveCmsComponent(block as unknown as Schemas["CmsBlock"]);
|
|
17
17
|
expect(result.componentName).toBe("image-simple-grid");
|
|
18
18
|
expect(result.componentNameToResolve).toBe("CmsBlockImageSimpleGrid");
|
|
19
|
+
expect(result.resolvedComponent).toEqual({});
|
|
19
20
|
expect(result.isResolved).toBe(true);
|
|
20
21
|
});
|
|
21
22
|
|
|
23
|
+
it("is not resolved when Vue hands the component name back", () => {
|
|
24
|
+
// resolveComponent returns the name it was given when nothing is registered
|
|
25
|
+
vi.spyOn(vue, "resolveComponent").mockImplementation((element) => element);
|
|
26
|
+
const section = CmsPage.cmsPage.sections?.[0];
|
|
27
|
+
const block = section?.blocks?.[0];
|
|
28
|
+
|
|
29
|
+
const result = resolveCmsComponent(block as unknown as Schemas["CmsBlock"]);
|
|
30
|
+
expect(result.componentNameToResolve).toBe("CmsBlockImageSimpleGrid");
|
|
31
|
+
expect(result.resolvedComponent).toBeUndefined();
|
|
32
|
+
expect(result.isResolved).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
|
|
22
35
|
it("getDefaultApiParams", () => {
|
|
23
36
|
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
24
37
|
const result = getDefaultApiParams();
|
|
@@ -32,15 +45,20 @@ describe("resolveCmsComponent", () => {
|
|
|
32
45
|
vi.spyOn(vue, "resolveComponent").mockImplementation(() => ({}));
|
|
33
46
|
const result = resolveCmsComponent({
|
|
34
47
|
apiAlias: "cms_section",
|
|
48
|
+
type: "sidebar",
|
|
35
49
|
} as unknown as Schemas["CmsBlock"]);
|
|
50
|
+
expect(result.componentNameToResolve).toBe("CmsSectionSidebar");
|
|
36
51
|
expect(result.isResolved).toBe(true);
|
|
37
52
|
});
|
|
38
53
|
|
|
39
54
|
it("cms custom component", () => {
|
|
55
|
+
vi.spyOn(vue, "resolveComponent").mockImplementation(() => ({}));
|
|
40
56
|
const result = resolveCmsComponent({
|
|
41
57
|
apiAlias: "cms_custom",
|
|
58
|
+
type: "text",
|
|
42
59
|
} as unknown as Schemas["CmsBlock"]);
|
|
43
60
|
|
|
61
|
+
expect(result.componentNameToResolve).toBe("CmsElementText");
|
|
44
62
|
expect(result.isResolved).toBe(true);
|
|
45
63
|
});
|
|
46
64
|
|
package/src/index.ts
CHANGED
|
@@ -80,20 +80,25 @@ export function resolveCmsComponent(
|
|
|
80
80
|
|
|
81
81
|
const componentNameToResolve = pascalCase(`Cms-${type}-${componentName}`);
|
|
82
82
|
try {
|
|
83
|
-
const
|
|
83
|
+
const component = resolveComponent(componentNameToResolve);
|
|
84
|
+
// Vue returns the name it was given when nothing is registered under it.
|
|
85
|
+
const resolvedComponent =
|
|
86
|
+
typeof component !== "string" ? component : undefined;
|
|
84
87
|
|
|
85
88
|
return {
|
|
86
89
|
componentName,
|
|
87
90
|
componentNameToResolve,
|
|
88
|
-
isResolved: resolvedComponent !==
|
|
89
|
-
resolvedComponent
|
|
90
|
-
typeof resolvedComponent !== "string" ? resolvedComponent : undefined,
|
|
91
|
+
isResolved: resolvedComponent !== undefined,
|
|
92
|
+
resolvedComponent,
|
|
91
93
|
};
|
|
92
94
|
} catch (e) {
|
|
93
95
|
return {
|
|
94
96
|
componentName,
|
|
95
97
|
componentNameToResolve,
|
|
96
98
|
resolvedComponent: undefined,
|
|
99
|
+
/**
|
|
100
|
+
* @deprecated Use `isResolved` instead. Kept so the error shape is unchanged.
|
|
101
|
+
*/
|
|
97
102
|
resolved: false,
|
|
98
103
|
isResolved: false,
|
|
99
104
|
error: (e as Error).message,
|
|
@@ -34,6 +34,7 @@ export type CmsBlockImageSimpleGrid = BlockType<
|
|
|
34
34
|
export type CmsBlockImageSlider = BlockType<"imageSlider">;
|
|
35
35
|
export type CmsBlockImageGallery = BlockType<"imageGallery">;
|
|
36
36
|
|
|
37
|
+
export type CmsBlockVideo = BlockType<"video">;
|
|
37
38
|
export type CmsBlockYoutubeVideo = BlockType<"video">;
|
|
38
39
|
export type CmsBlockVimeoVideo = BlockType<"video">;
|
|
39
40
|
|
|
@@ -69,6 +70,7 @@ export type CmsBlockTextOnImage = BlockType<"content">;
|
|
|
69
70
|
export type CmsBlockSidebarFilter = BlockType<"content">;
|
|
70
71
|
export type CmsBlockCategoryNavigation = BlockType<"content">;
|
|
71
72
|
|
|
73
|
+
export type CmsBlockCategoryHeading = BlockType<"content">;
|
|
72
74
|
export type CmsBlockProductHeading = BlockType<TWO_COLUMNS>;
|
|
73
75
|
export type CmsBlockProductThreeColumn = BlockType<THREE_COLUMNS>;
|
|
74
76
|
export type CmsBlockProductListing = BlockType<"content">;
|
|
@@ -81,3 +83,13 @@ export type CmsBlockForm = BlockType<"content">;
|
|
|
81
83
|
export type CmsBlockHtml = BlockType<"content">;
|
|
82
84
|
|
|
83
85
|
export type CmsBlockImageGalleryBig = BlockType<"imageGallery">;
|
|
86
|
+
|
|
87
|
+
export type CmsBlockAppRenderer = BlockType<string> & {
|
|
88
|
+
type: "app-renderer";
|
|
89
|
+
customFields?: {
|
|
90
|
+
appBlockName?: string;
|
|
91
|
+
slotLayout?: {
|
|
92
|
+
grid?: string | null;
|
|
93
|
+
};
|
|
94
|
+
} | null;
|
|
95
|
+
};
|
|
@@ -10,6 +10,8 @@ export type DisplayMode =
|
|
|
10
10
|
| Exclude<CSSProperties["objectFit"], undefined>
|
|
11
11
|
| "standard";
|
|
12
12
|
|
|
13
|
+
export type MediaDisplayMode = "standard" | "stretch" | "cover";
|
|
14
|
+
|
|
13
15
|
export type BoxLayout = "standard" | "image" | "minimal";
|
|
14
16
|
|
|
15
17
|
export type VerticalAlign = "flex-start" | "center" | "flex-end" | "";
|
|
@@ -62,9 +64,11 @@ type ImageElementConfig = {
|
|
|
62
64
|
media: ElementConfig<string>;
|
|
63
65
|
newTab: ElementConfig<boolean>;
|
|
64
66
|
product: ElementConfig<string>;
|
|
67
|
+
ariaLabel?: ElementConfig<string | null>;
|
|
65
68
|
boxLayout: ElementConfig<BoxLayout>;
|
|
66
69
|
displayMode: ElementConfig<DisplayMode>;
|
|
67
70
|
minHeight: ElementConfig<string | number>;
|
|
71
|
+
isDecorative?: ElementConfig<boolean>;
|
|
68
72
|
verticalAlign: ElementConfig<VerticalAlign>;
|
|
69
73
|
horizontalAlign: ElementConfig<VerticalAlign>;
|
|
70
74
|
};
|
|
@@ -76,6 +80,7 @@ export type CmsElementImage = Omit<Schemas["CmsSlot"], "config"> & {
|
|
|
76
80
|
mediaId: string;
|
|
77
81
|
url: string;
|
|
78
82
|
newTab: boolean;
|
|
83
|
+
ariaLabel?: string | null;
|
|
79
84
|
apiAlias: "cms_image";
|
|
80
85
|
media: Schemas["Media"];
|
|
81
86
|
};
|
|
@@ -87,8 +92,8 @@ export type SliderElementConfig = {
|
|
|
87
92
|
minHeight: ElementConfig<string | number>;
|
|
88
93
|
verticalAlign?: ElementConfig<VerticalAlign>;
|
|
89
94
|
displayMode?: ElementConfig<"standard" | "cover" | "contain">;
|
|
90
|
-
navigationDots?: ElementConfig<"outside" | "inside" | "">;
|
|
91
|
-
navigationArrows?: ElementConfig<"outside" | "inside" | "">;
|
|
95
|
+
navigationDots?: ElementConfig<"outside" | "inside" | "none" | "">;
|
|
96
|
+
navigationArrows?: ElementConfig<"outside" | "inside" | "none" | "">;
|
|
92
97
|
};
|
|
93
98
|
|
|
94
99
|
type ImageSliderElementConfig = ImageElementConfig &
|
|
@@ -148,6 +153,41 @@ export type CmsElementImageGallery = Omit<Schemas["CmsSlot"], "config"> & {
|
|
|
148
153
|
};
|
|
149
154
|
};
|
|
150
155
|
|
|
156
|
+
// Video
|
|
157
|
+
type VideoElementConfig = {
|
|
158
|
+
media: ElementConfig<string | null>;
|
|
159
|
+
displayMode: ElementConfig<MediaDisplayMode>;
|
|
160
|
+
minHeight: ElementConfig<string | null>;
|
|
161
|
+
verticalAlign: ElementConfig<VerticalAlign | null>;
|
|
162
|
+
horizontalAlign: ElementConfig<VerticalAlign | null>;
|
|
163
|
+
ariaLabel: ElementConfig<string | null>;
|
|
164
|
+
autoPlay: ElementConfig<boolean>;
|
|
165
|
+
muted: ElementConfig<boolean>;
|
|
166
|
+
loop: ElementConfig<boolean>;
|
|
167
|
+
playsInline: ElementConfig<boolean>;
|
|
168
|
+
showControls: ElementConfig<boolean>;
|
|
169
|
+
showCover: ElementConfig<boolean>;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export type CmsElementVideo = Omit<Schemas["CmsSlot"], "config"> & {
|
|
173
|
+
type: "video";
|
|
174
|
+
config: VideoElementConfig;
|
|
175
|
+
data: {
|
|
176
|
+
mediaId: string | null;
|
|
177
|
+
url: string | null;
|
|
178
|
+
newTab: boolean | null;
|
|
179
|
+
ariaLabel: string | null;
|
|
180
|
+
apiAlias: "cms_video";
|
|
181
|
+
media:
|
|
182
|
+
| (Schemas["Media"] & {
|
|
183
|
+
extensions?: {
|
|
184
|
+
videoCoverMedia?: Schemas["Media"];
|
|
185
|
+
};
|
|
186
|
+
})
|
|
187
|
+
| null;
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
|
|
151
191
|
// YouTube video
|
|
152
192
|
type YouTubeVideoElementConfig = {
|
|
153
193
|
end: ElementConfig<string>;
|
|
@@ -383,6 +423,21 @@ export type CmsElementProductName = Omit<Schemas["CmsSlot"], "config"> & {
|
|
|
383
423
|
};
|
|
384
424
|
};
|
|
385
425
|
|
|
426
|
+
// Category Name
|
|
427
|
+
type CategoryNameElementConfig = {
|
|
428
|
+
content: ElementConfig<string>;
|
|
429
|
+
verticalAlign?: ElementConfig<VerticalAlign | null>;
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
export type CmsElementCategoryName = Omit<Schemas["CmsSlot"], "config"> & {
|
|
433
|
+
type: "category-name";
|
|
434
|
+
config: CategoryNameElementConfig;
|
|
435
|
+
data: {
|
|
436
|
+
content: string | null;
|
|
437
|
+
apiAlias: "cms_text";
|
|
438
|
+
};
|
|
439
|
+
};
|
|
440
|
+
|
|
386
441
|
// Manufacturer Logo
|
|
387
442
|
export type CmsElementManufacturerLogo = Omit<Schemas["CmsSlot"], "config"> & {
|
|
388
443
|
type: "manufacturer-logo";
|
|
@@ -391,6 +446,7 @@ export type CmsElementManufacturerLogo = Omit<Schemas["CmsSlot"], "config"> & {
|
|
|
391
446
|
mediaId: string;
|
|
392
447
|
url: string;
|
|
393
448
|
newTab: boolean;
|
|
449
|
+
ariaLabel?: string | null;
|
|
394
450
|
apiAlias: "cms_manufacturer_logo";
|
|
395
451
|
media: Schemas["Media"];
|
|
396
452
|
};
|
|
@@ -5,24 +5,24 @@ import { useSetup } from "../_test";
|
|
|
5
5
|
import ProductMocked from "../mocks/Product";
|
|
6
6
|
import { useAddToCart } from "./useAddToCart";
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}));
|
|
8
|
+
vi.mock("../useCart/useCart.ts", () => ({
|
|
9
|
+
useCart() {
|
|
10
|
+
return {
|
|
11
|
+
addProduct: () => ({}),
|
|
12
|
+
cartItems: {
|
|
13
|
+
value: [
|
|
14
|
+
{
|
|
15
|
+
referencedId: ProductMocked.id,
|
|
16
|
+
good: true,
|
|
17
|
+
quantity: 1,
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
}));
|
|
25
24
|
|
|
25
|
+
describe("useAddToCart", () => {
|
|
26
26
|
it("add product to cart", async () => {
|
|
27
27
|
const { vm } = await useSetup(() => useAddToCart(ref(ProductMocked)));
|
|
28
28
|
|
|
@@ -49,7 +49,45 @@ describe("useB2bQuoteManagement", () => {
|
|
|
49
49
|
);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
it("
|
|
52
|
+
it("createDraftQuoteVersion", async () => {
|
|
53
|
+
const { vm, injections } = useSetup(() => useB2bQuoteManagement());
|
|
54
|
+
injections.apiClient.invoke.mockResolvedValue({
|
|
55
|
+
data: { versionId: "test-version-id" },
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
expect(await vm.createDraftQuoteVersion("test-12")).toBe("test-version-id");
|
|
59
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
60
|
+
expect.stringContaining("createDraftQuoteVersion"),
|
|
61
|
+
expect.objectContaining({
|
|
62
|
+
pathParams: { id: "test-12" },
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("createDraftQuoteVersion - no versionId in response", async () => {
|
|
68
|
+
const { vm, injections } = useSetup(() => useB2bQuoteManagement());
|
|
69
|
+
injections.apiClient.invoke.mockResolvedValue({ data: {} });
|
|
70
|
+
|
|
71
|
+
await expect(vm.createDraftQuoteVersion("test-12")).rejects.toThrow(
|
|
72
|
+
/no versionId/,
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("deleteDraftQuoteVersion", async () => {
|
|
77
|
+
const { vm, injections } = useSetup(() => useB2bQuoteManagement());
|
|
78
|
+
injections.apiClient.invoke.mockResolvedValue({ data: null });
|
|
79
|
+
await vm.deleteDraftQuoteVersion("test-12", "test-version-id");
|
|
80
|
+
|
|
81
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
82
|
+
expect.stringContaining("deleteDraftQuoteVersion"),
|
|
83
|
+
expect.objectContaining({
|
|
84
|
+
pathParams: { id: "test-12" },
|
|
85
|
+
body: { versionId: "test-version-id" },
|
|
86
|
+
}),
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("declineQuote - deprecated, comment only", async () => {
|
|
53
91
|
const { vm, injections } = useSetup(() => useB2bQuoteManagement());
|
|
54
92
|
injections.apiClient.invoke.mockResolvedValue({ data: null });
|
|
55
93
|
await vm.declineQuote("test-12", "test-comment");
|
|
@@ -63,6 +101,28 @@ describe("useB2bQuoteManagement", () => {
|
|
|
63
101
|
);
|
|
64
102
|
});
|
|
65
103
|
|
|
104
|
+
it("declineQuoteWithComment", async () => {
|
|
105
|
+
const { vm, injections } = useSetup(() => useB2bQuoteManagement());
|
|
106
|
+
injections.apiClient.invoke.mockResolvedValue({ data: null });
|
|
107
|
+
await vm.declineQuoteWithComment("test-12", {
|
|
108
|
+
comment: "test-comment",
|
|
109
|
+
lineItemId: "test-line-item-id",
|
|
110
|
+
versionId: "test-version-id",
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
114
|
+
expect.stringContaining("declineQuote"),
|
|
115
|
+
expect.objectContaining({
|
|
116
|
+
pathParams: { id: "test-12" },
|
|
117
|
+
body: {
|
|
118
|
+
comment: "test-comment",
|
|
119
|
+
lineItemId: "test-line-item-id",
|
|
120
|
+
versionId: "test-version-id",
|
|
121
|
+
},
|
|
122
|
+
}),
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
|
|
66
126
|
it("requestChangeQuote", async () => {
|
|
67
127
|
const { vm, injections } = useSetup(() => useB2bQuoteManagement());
|
|
68
128
|
injections.apiClient.invoke.mockResolvedValue({ data: null });
|