@shopware/composables 1.10.0 → 1.11.1

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 (46) hide show
  1. package/README.md +11 -30
  2. package/dist/index.d.mts +26 -9
  3. package/dist/index.d.ts +26 -9
  4. package/dist/index.mjs +37 -23
  5. package/package.json +16 -14
  6. package/src/cms/useCmsElementConfig.test.ts +8 -0
  7. package/src/cms/useCmsElementConfig.ts +3 -0
  8. package/src/cms/useCmsElementImage.test.ts +23 -0
  9. package/src/cms/useCmsElementProductBox.test.ts +21 -0
  10. package/src/devtools/plugin.ts +1 -2
  11. package/src/mocks/Configurator.ts +36 -36
  12. package/src/useAddToCart/useAddToCart.test.ts +18 -1
  13. package/src/useAddress/useAddress.test.ts +41 -2
  14. package/src/useAddress/useAddress.ts +1 -1
  15. package/src/useCart/useCart.test.ts +30 -0
  16. package/src/useCartNotification/useCartNotification.test.ts +30 -0
  17. package/src/useCheckout/useCheckout.test.ts +43 -1
  18. package/src/useCmsMeta/useCmsMeta.test.ts +26 -0
  19. package/src/useCountries/useCountries.test.ts +14 -0
  20. package/src/useLocalWishlist/useLocalWishlist.test.ts +44 -5
  21. package/src/useLocalWishlist/useLocalWishlist.ts +3 -2
  22. package/src/useNavigationContext/useNavigationContext.test.ts +25 -24
  23. package/src/useNavigationSearch/useNavigationSearch.test.ts +95 -2
  24. package/src/useNavigationSearch/useNavigationSearch.ts +18 -8
  25. package/src/useNewsletter/useNewsletter.test.ts +20 -1
  26. package/src/useNewsletter/useNewsletter.ts +7 -4
  27. package/src/useOrderDetails/useOrderDetails.test.ts +92 -3
  28. package/src/useOrderDetails/useOrderDetails.ts +7 -3
  29. package/src/useOrderPayment/useOrderPayment.test.ts +55 -1
  30. package/src/usePrice/usePrice.test.ts +10 -0
  31. package/src/usePrice/usePrice.ts +2 -7
  32. package/src/useProduct/useProduct.test.ts +14 -1
  33. package/src/useProductAssociations/useProductAssociations.spec.ts +1 -0
  34. package/src/useProductConfigurator/useProductConfigurator.spec.ts +38 -0
  35. package/src/useProductConfigurator/useProductConfigurator.ts +1 -1
  36. package/src/useProductPrice/useProductPrice.test.ts +7 -7
  37. package/src/useProductPrice/useProductPrice.ts +12 -4
  38. package/src/useProductReviews/useProductReviews.test.ts +15 -3
  39. package/src/useSalutations/useSalutations.spec.ts +13 -0
  40. package/src/useSessionContext/useSessionContext.test.ts +122 -4
  41. package/src/useSessionContext/useSessionContext.ts +13 -1
  42. package/src/useSyncWishlist/useSyncWishlist.test.ts +60 -8
  43. package/src/useUrlResolver/useUrlResolver.test.ts +6 -12
  44. package/src/useUrlResolver/useUrlResolver.ts +4 -6
  45. package/src/useUser/useUser.test.ts +107 -15
  46. package/src/useWishlist/useWishlist.test.ts +124 -26
@@ -59,7 +59,10 @@ describe("useNavigationSearch", () => {
59
59
  const { vm, injections } = useSetup(useNavigationSearch);
60
60
  injections.apiClient.invoke.mockResolvedValue({ data: { elements: [] } });
61
61
 
62
- await vm.resolvePath("/landingPage/test");
62
+ await expect(vm.resolvePath("/landingPage/test")).resolves.toMatchObject({
63
+ routeName: "frontend.landing.page",
64
+ foreignKey: "test",
65
+ });
63
66
 
64
67
  expect(injections.apiClient.invoke).toHaveBeenCalledWith(
65
68
  expect.stringContaining("readSeoUrl"),
@@ -80,7 +83,10 @@ describe("useNavigationSearch", () => {
80
83
  const { vm, injections } = useSetup(useNavigationSearch);
81
84
  injections.apiClient.invoke.mockResolvedValue({ data: { elements: [] } });
82
85
 
83
- await vm.resolvePath("/detail/test/");
86
+ await expect(vm.resolvePath("/detail/test/")).resolves.toMatchObject({
87
+ routeName: "frontend.detail.page",
88
+ foreignKey: "test",
89
+ });
84
90
 
85
91
  expect(injections.apiClient.invoke).toHaveBeenCalledWith(
86
92
  expect.stringContaining("readSeoUrl"),
@@ -97,6 +103,93 @@ describe("useNavigationSearch", () => {
97
103
  }),
98
104
  );
99
105
  });
106
+ it("should resolve navigation technical url by pathInfo", async () => {
107
+ const { vm, injections } = useSetup(useNavigationSearch);
108
+ const navigationSeoResponse = {
109
+ ...mockedResponse,
110
+ routeName: "frontend.navigation.page",
111
+ foreignKey: "12b149be1e924fc45e4e43b5cdc49225",
112
+ pathInfo: "/navigation/12b149be1e924fc45e4e43b5cdc49225",
113
+ };
114
+ injections.apiClient.invoke.mockResolvedValue({
115
+ data: { elements: [navigationSeoResponse] },
116
+ });
117
+
118
+ expect(
119
+ await vm.resolvePath("/navigation/12b149be1e924fc45e4e43b5cdc49225"),
120
+ ).toStrictEqual(navigationSeoResponse);
121
+
122
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
123
+ expect.stringContaining("readSeoUrl"),
124
+ expect.objectContaining({
125
+ body: {
126
+ filter: [
127
+ {
128
+ type: "equals",
129
+ field: "pathInfo",
130
+ value: "/navigation/12b149be1e924fc45e4e43b5cdc49225",
131
+ },
132
+ ],
133
+ },
134
+ }),
135
+ );
136
+ });
137
+
138
+ it("should synthesize navigation route when API returns no seo mapping for technical url", async () => {
139
+ const { vm, injections } = useSetup(useNavigationSearch);
140
+ injections.apiClient.invoke.mockResolvedValue({ data: { elements: [] } });
141
+
142
+ await expect(
143
+ vm.resolvePath("/navigation/12b149be1e924fc45e4e43b5cdc49225"),
144
+ ).resolves.toMatchObject({
145
+ routeName: "frontend.navigation.page",
146
+ foreignKey: "12b149be1e924fc45e4e43b5cdc49225",
147
+ });
148
+ });
149
+
150
+ it("should normalize navigation technical url with trailing slash", async () => {
151
+ const { vm, injections } = useSetup(useNavigationSearch);
152
+ injections.apiClient.invoke.mockResolvedValue({ data: { elements: [] } });
153
+
154
+ await expect(
155
+ vm.resolvePath("/navigation/12b149be1e924fc45e4e43b5cdc49225/"),
156
+ ).resolves.toMatchObject({
157
+ routeName: "frontend.navigation.page",
158
+ foreignKey: "12b149be1e924fc45e4e43b5cdc49225",
159
+ });
160
+
161
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
162
+ expect.stringContaining("readSeoUrl"),
163
+ expect.objectContaining({
164
+ body: {
165
+ filter: [
166
+ {
167
+ type: "equals",
168
+ field: "pathInfo",
169
+ value: "/navigation/12b149be1e924fc45e4e43b5cdc49225",
170
+ },
171
+ ],
172
+ },
173
+ }),
174
+ );
175
+ });
176
+
177
+ it("should return null for non-technical path when API returns no mapping", async () => {
178
+ const { vm, injections } = useSetup(useNavigationSearch);
179
+ injections.apiClient.invoke.mockResolvedValue({ data: { elements: [] } });
180
+
181
+ expect(
182
+ await vm.resolvePath("/some-seo-path-that-does-not-exist"),
183
+ ).toBeNull();
184
+ });
185
+
186
+ it("should return null when technical path has no seo row and does not match a resolvable segment", async () => {
187
+ const { vm, injections } = useSetup(useNavigationSearch);
188
+ injections.apiClient.invoke.mockResolvedValue({ data: { elements: [] } });
189
+
190
+ expect(await vm.resolvePath("/navigation/cat/extra/segment")).toBeNull();
191
+ });
192
+
100
193
  it("should not invoke api call for / search ", async () => {
101
194
  const { vm, injections } = useSetup(useNavigationSearch);
102
195
  injections.apiClient.invoke.mockResolvedValue({
@@ -1,3 +1,8 @@
1
+ import {
2
+ getRouteFromPathInfo,
3
+ isTechnicalPath,
4
+ normalizePath,
5
+ } from "@shopware/helpers";
1
6
  import { useSessionContext, useShopwareContext } from "#imports";
2
7
  import type { Schemas } from "#shopware";
3
8
 
@@ -30,16 +35,11 @@ export function useNavigationSearch(): UseNavigationSearchReturn {
30
35
  } as Schemas["SeoUrl"];
31
36
  }
32
37
 
33
- const isTechnicalUrl =
34
- path.startsWith("/navigation/") ||
35
- path.startsWith("/detail/") ||
36
- path.startsWith("/landingPage/");
38
+ const isTechnicalUrl = isTechnicalPath(path);
37
39
 
38
40
  // remove leading slash in case of seo url or remove trailing slash in case of technical url
39
41
  const normalizedPath = isTechnicalUrl
40
- ? path.endsWith("/")
41
- ? path.slice(0, -1)
42
- : path
42
+ ? normalizePath(path)
43
43
  : path.substring(1);
44
44
 
45
45
  const seoResult = await apiClient.invoke("readSeoUrl post /seo-url", {
@@ -54,7 +54,17 @@ export function useNavigationSearch(): UseNavigationSearchReturn {
54
54
  },
55
55
  });
56
56
 
57
- return seoResult.data.elements?.[0] ?? null;
57
+ const element = seoResult.data.elements?.[0];
58
+ if (element) {
59
+ return element;
60
+ }
61
+
62
+ const fallback = getRouteFromPathInfo(path);
63
+ if (fallback) {
64
+ return fallback as Schemas["SeoUrl"];
65
+ }
66
+
67
+ return null;
58
68
  }
59
69
 
60
70
  return {
@@ -5,7 +5,9 @@ import { useNewsletter } from "./useNewsletter";
5
5
  describe("useNewsletter", () => {
6
6
  it("newsletter subscribe", async () => {
7
7
  const { vm, injections } = useSetup(useNewsletter);
8
- injections.apiClient.invoke.mockResolvedValue({ data: {} });
8
+ injections.apiClient.invoke.mockResolvedValue({
9
+ data: { status: "direct" },
10
+ });
9
11
 
10
12
  await vm.newsletterSubscribe({
11
13
  email: "test@shopware.com",
@@ -16,6 +18,7 @@ describe("useNewsletter", () => {
16
18
  expect.stringContaining("subscribeToNewsletter"),
17
19
  expect.anything(),
18
20
  );
21
+ expect(vm.newsletterStatus).toBe("direct");
19
22
  });
20
23
 
21
24
  it("newsletter unsubscribe", async () => {
@@ -52,4 +55,20 @@ describe("useNewsletter", () => {
52
55
  vm.newsletterStatus = "direct";
53
56
  expect(vm.isNewsletterSubscriber).toBe(true);
54
57
  });
58
+
59
+ it("confirmationNeeded when status is notSet", async () => {
60
+ const { vm, injections } = useSetup(useNewsletter);
61
+ injections.apiClient.invoke.mockResolvedValue({
62
+ data: { status: "notSet" },
63
+ });
64
+
65
+ await vm.getNewsletterStatus();
66
+ expect(vm.confirmationNeeded).toBe(true);
67
+ });
68
+
69
+ it("returns SUBSRIBE_KEY and UNSUBSCRIBE_KEY", () => {
70
+ const { vm } = useSetup(useNewsletter);
71
+ expect(vm.SUBSCRIBE_KEY).toBe("subscribe");
72
+ expect(vm.UNSUBSCRIBE_KEY).toBe("unsubscribe");
73
+ });
55
74
  });
@@ -13,7 +13,9 @@ export type UseNewsletterReturn = {
13
13
  operations["subscribeToNewsletter post /newsletter/subscribe"]["body"],
14
14
  "storefrontUrl"
15
15
  >,
16
- ): Promise<void>;
16
+ ): Promise<
17
+ operations["subscribeToNewsletter post /newsletter/subscribe"]["response"]
18
+ >;
17
19
  /**
18
20
  * Removes the email from the newsletter
19
21
  * @param email
@@ -40,7 +42,7 @@ export type UseNewsletterReturn = {
40
42
  /**
41
43
  * Subscribe key
42
44
  */
43
- SUBSRIBE_KEY: string;
45
+ SUBSCRIBE_KEY: string;
44
46
  /**
45
47
  * Unsubscribe key
46
48
  */
@@ -53,7 +55,7 @@ export type UseNewsletterReturn = {
53
55
  * @category Customer & Account
54
56
  */
55
57
  export function useNewsletter(): UseNewsletterReturn {
56
- const SUBSRIBE_KEY = "subscribe";
58
+ const SUBSCRIBE_KEY = "subscribe";
57
59
  const UNSUBSCRIBE_KEY = "unsubscribe";
58
60
 
59
61
  const { apiClient } = useShopwareContext();
@@ -76,6 +78,7 @@ export function useNewsletter(): UseNewsletterReturn {
76
78
  },
77
79
  },
78
80
  );
81
+ newsletterStatus.value = result.data.status;
79
82
  return result.data;
80
83
  }
81
84
 
@@ -116,7 +119,7 @@ export function useNewsletter(): UseNewsletterReturn {
116
119
  getNewsletterStatus,
117
120
  newsletterStatus,
118
121
  confirmationNeeded,
119
- SUBSRIBE_KEY,
122
+ SUBSCRIBE_KEY,
120
123
  UNSUBSCRIBE_KEY,
121
124
  };
122
125
  }
@@ -6,12 +6,21 @@ import { useOrderDetails } from "./useOrderDetails";
6
6
  describe("useOrderDetails", () => {
7
7
  it("init details", async () => {
8
8
  const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
9
+
10
+ expect(vm.documents).toStrictEqual([]);
11
+
9
12
  injections.apiClient.invoke.mockResolvedValue({ data: Order });
10
13
 
11
14
  await vm.loadOrderDetails();
15
+ expect(vm.hasDocuments).toBe(false);
16
+ expect(vm.documents).toStrictEqual([]);
12
17
  expect(injections.apiClient.invoke).toHaveBeenCalledWith(
13
18
  expect.stringContaining("readOrder"),
14
- expect.objectContaining({}),
19
+ expect.objectContaining({
20
+ body: expect.objectContaining({
21
+ associations: expect.anything(),
22
+ }),
23
+ }),
15
24
  );
16
25
 
17
26
  expect(vm.personalDetails).toEqual({
@@ -26,11 +35,25 @@ describe("useOrderDetails", () => {
26
35
  id === Order.orders.elements?.[0]?.billingAddressId,
27
36
  ),
28
37
  );
38
+
39
+ expect(vm.order).toBeDefined();
40
+ expect(vm.status).toBe(
41
+ Order.orders.elements?.[0]?.stateMachineState.translated.name,
42
+ );
43
+ expect(vm.statusTechnicalName).toBe(
44
+ Order.orders.elements?.[0]?.stateMachineState.technicalName,
45
+ );
46
+ expect(vm.shippingAddress).toBeUndefined();
47
+ expect(vm.total).toBe(Order.orders.elements?.[0]?.price?.totalPrice);
48
+ expect(vm.subtotal).toBe(Order.orders.elements?.[0]?.price?.positionPrice);
49
+ expect(vm.shippingCosts).toBe(Order.orders.elements?.[0]?.shippingTotal);
29
50
  });
30
51
 
31
52
  it("should handle setting the order payment", async () => {
32
53
  const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
33
- injections.apiClient.invoke.mockResolvedValue({ data: {} });
54
+ injections.apiClient.invoke.mockResolvedValue({
55
+ data: { redirectUrl: "https://payment.example.com" },
56
+ });
34
57
  await vm.handlePayment();
35
58
 
36
59
  expect(injections.apiClient.invoke).toHaveBeenCalledWith(
@@ -43,6 +66,24 @@ describe("useOrderDetails", () => {
43
66
  },
44
67
  }),
45
68
  );
69
+ expect(vm.paymentUrl).toBe("https://payment.example.com");
70
+ });
71
+
72
+ it("should handle payment with success and error URLs", async () => {
73
+ const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
74
+ injections.apiClient.invoke.mockResolvedValue({ data: {} });
75
+ await vm.handlePayment("https://success.com", "https://error.com");
76
+
77
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
78
+ expect.stringContaining("handlePaymentMethod"),
79
+ expect.objectContaining({
80
+ body: {
81
+ orderId: "123-test",
82
+ finishUrl: "https://success.com",
83
+ errorUrl: "https://error.com",
84
+ },
85
+ }),
86
+ );
46
87
  });
47
88
 
48
89
  it("should cancel the order", async () => {
@@ -112,7 +153,7 @@ describe("useOrderDetails", () => {
112
153
  it("getPaymentMethods", async () => {
113
154
  const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
114
155
  injections.apiClient.invoke.mockResolvedValue({ data: {} });
115
- await vm.getPaymentMethods();
156
+ const result = await vm.getPaymentMethods();
116
157
 
117
158
  expect(injections.apiClient.invoke).toHaveBeenCalledWith(
118
159
  expect.stringContaining("readPaymentMethod"),
@@ -122,6 +163,18 @@ describe("useOrderDetails", () => {
122
163
  },
123
164
  }),
124
165
  );
166
+ expect(result).toEqual([]);
167
+ });
168
+
169
+ it("getPaymentMethods returns elements when available", async () => {
170
+ const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
171
+ const paymentMethods = [{ id: "1", name: "Invoice" }];
172
+ injections.apiClient.invoke.mockResolvedValue({
173
+ data: { elements: paymentMethods },
174
+ });
175
+ const result = await vm.getPaymentMethods();
176
+
177
+ expect(result).toEqual(paymentMethods);
125
178
  });
126
179
 
127
180
  it("paymentChangeable", async () => {
@@ -132,6 +185,42 @@ describe("useOrderDetails", () => {
132
185
  expect(vm.paymentChangeable).toEqual(true);
133
186
  });
134
187
 
188
+ it("loadOrderDetails with custom associations", async () => {
189
+ const customAssociations = { lineItems: { associations: { cover: {} } } };
190
+ const { vm, injections } = useSetup(() =>
191
+ useOrderDetails("123-test", customAssociations),
192
+ );
193
+ injections.apiClient.invoke.mockResolvedValue({ data: Order });
194
+ await vm.loadOrderDetails();
195
+
196
+ const call = injections.apiClient.invoke.mock.calls.at(0);
197
+ expect(call).toBeDefined();
198
+ if (call) {
199
+ const args = call[1] as { body: { associations: unknown } };
200
+ expect(call[0]).toContain("readOrder");
201
+ expect(args.body.associations).toMatchObject(customAssociations);
202
+ }
203
+ });
204
+
205
+ it("hasDocuments and documents when order has documents", async () => {
206
+ const orderElement = Order.orders.elements[0];
207
+ const orderWithDocs = {
208
+ ...orderElement,
209
+ documents: [{ id: "doc-1", deepLinkCode: "abc" }],
210
+ };
211
+ const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
212
+ injections.apiClient.invoke.mockResolvedValue({
213
+ data: {
214
+ orders: { elements: [orderWithDocs] },
215
+ paymentChangeable: { "123-test": true },
216
+ },
217
+ });
218
+ await vm.loadOrderDetails();
219
+
220
+ expect(vm.hasDocuments).toBe(true);
221
+ expect(vm.documents).toStrictEqual([{ id: "doc-1", deepLinkCode: "abc" }]);
222
+ });
223
+
135
224
  it("should return current payment method", async () => {
136
225
  const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
137
226
  injections.apiClient.invoke.mockResolvedValue({
@@ -97,12 +97,12 @@ export type UseOrderDetailsReturn = {
97
97
  * Get order documents
98
98
  * @param {string} documentId
99
99
  * @param {string} deepLinkCode
100
- * @returns
100
+ * @returns Binary document content (PDF, HTML, or XML)
101
101
  */
102
102
  getDocumentFile: (
103
103
  documentId: string,
104
104
  deepLinkCode: string,
105
- ) => Promise<Schemas["Document"]>;
105
+ ) => Promise<Blob | string>;
106
106
  /**
107
107
  * Check if order has documents
108
108
  */
@@ -258,7 +258,10 @@ export function useOrderDetails(
258
258
  return response.data;
259
259
  }
260
260
 
261
- async function getDocumentFile(documentId: string, deepLinkCode: string) {
261
+ async function getDocumentFile(
262
+ documentId: string,
263
+ deepLinkCode: string,
264
+ ): Promise<Blob | string> {
262
265
  const response = await apiClient.invoke(
263
266
  "download post /document/download/{documentId}/{deepLinkCode}",
264
267
  {
@@ -266,6 +269,7 @@ export function useOrderDetails(
266
269
  documentId,
267
270
  deepLinkCode,
268
271
  },
272
+ accept: "application/pdf",
269
273
  },
270
274
  );
271
275
 
@@ -32,6 +32,8 @@ describe("useOrderPayment", () => {
32
32
  expect(vm.activeTransaction).toEqual(
33
33
  Order.orders.elements?.[0]?.transactions[0],
34
34
  );
35
+ expect(vm.paymentMethod).toBeDefined();
36
+ expect(vm.state).toBeDefined();
35
37
 
36
38
  vm.changePaymentMethod("test");
37
39
 
@@ -47,13 +49,45 @@ describe("useOrderPayment", () => {
47
49
  });
48
50
 
49
51
  it("should not invoke API calls for empty order", async () => {
50
- const { vm } = useSetup(() =>
52
+ const { vm, injections } = useSetup(() =>
51
53
  useOrderPayment(
52
54
  computed(() => null) as unknown as ComputedRef<Schemas["Order"]>,
53
55
  ),
54
56
  );
55
57
  await expect(vm.changePaymentMethod("test")).resolves.toBeUndefined();
56
58
  await expect(vm.handlePayment()).resolves.toBeUndefined();
59
+ expect(injections.apiClient.invoke).not.toHaveBeenCalled();
60
+ });
61
+
62
+ it("handlePayment returns response", async () => {
63
+ const { vm, injections } = useSetup(() =>
64
+ useOrderPayment(
65
+ computed(() => Order.orders.elements?.[0]) as unknown as ComputedRef<
66
+ Schemas["Order"]
67
+ >,
68
+ ),
69
+ );
70
+ const response = { data: { redirectUrl: "https://pay.example.com" } };
71
+ injections.apiClient.invoke.mockResolvedValue(response);
72
+ const result = await vm.handlePayment();
73
+
74
+ expect(result).toEqual(response);
75
+ expect(vm.paymentUrl).toBe("https://pay.example.com");
76
+ });
77
+
78
+ it("changePaymentMethod returns response data", async () => {
79
+ const { vm, injections } = useSetup(() =>
80
+ useOrderPayment(
81
+ computed(() => Order.orders.elements?.[0]) as unknown as ComputedRef<
82
+ Schemas["Order"]
83
+ >,
84
+ ),
85
+ );
86
+ const responseData = { success: true };
87
+ injections.apiClient.invoke.mockResolvedValue({ data: responseData });
88
+ const result = await vm.changePaymentMethod("new-method-id");
89
+
90
+ expect(result).toEqual(responseData);
57
91
  });
58
92
 
59
93
  it("should be a asynchronous payment", () => {
@@ -76,4 +110,24 @@ describe("useOrderPayment", () => {
76
110
 
77
111
  expect(vm.isAsynchronous).toBe(true);
78
112
  });
113
+
114
+ it("should be synchronous when afterOrderEnabled is false", () => {
115
+ const { vm } = useSetup(() =>
116
+ useOrderPayment(
117
+ computed(() => ({
118
+ transactions: [
119
+ {
120
+ paymentMethod: {
121
+ active: true,
122
+ asynchronous: true,
123
+ afterOrderEnabled: false,
124
+ },
125
+ },
126
+ ],
127
+ })) as unknown as ComputedRef<Schemas["Order"]>,
128
+ ),
129
+ );
130
+
131
+ expect(vm.isAsynchronous).toBeFalsy();
132
+ });
79
133
  });
@@ -65,6 +65,16 @@ describe("usePrice", () => {
65
65
  expect(vm.getFormattedPrice("2")).toBe("$2.00");
66
66
  });
67
67
 
68
+ it("should init price object with params and undefined localeCode", () => {
69
+ const { vm } = useSetup(() =>
70
+ usePrice({
71
+ currencyCode: "EUR",
72
+ }),
73
+ );
74
+
75
+ expect(vm.currencyCode).toBe("EUR");
76
+ });
77
+
68
78
  it("should update config", async () => {
69
79
  const { vm } = useSetup(usePrice);
70
80
 
@@ -38,13 +38,8 @@ function _usePrice(params?: {
38
38
  }): UsePriceReturn {
39
39
  const { sessionContext } = useSessionContext();
40
40
  const { browserLocale } = useShopwareContext();
41
- const currencyLocale = ref<string>(browserLocale);
42
- const currencyCode = ref<string>("");
43
-
44
- if (params) {
45
- currencyCode.value = params.currencyCode;
46
- _setLocaleCode(params.localeCode);
47
- }
41
+ const currencyCode = ref<string>(params?.currencyCode ?? "");
42
+ const currencyLocale = ref<string>(params?.localeCode || browserLocale);
48
43
 
49
44
  function update(params: {
50
45
  localeCode?: string | undefined;
@@ -1,6 +1,8 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import { ref } from "vue";
3
+ import type { Schemas } from "#shopware";
3
4
  import { useSetup } from "../_test";
5
+ import mockedConfigurator from "../mocks/Configurator";
4
6
  import mockedProduct from "../mocks/Product";
5
7
  import { useProduct } from "./useProduct";
6
8
 
@@ -11,13 +13,24 @@ describe("useProduct", () => {
11
13
  expect(vm.product).toStrictEqual(mockedProduct);
12
14
  });
13
15
 
16
+ it("should return configurator when provided", () => {
17
+ const { vm } = useSetup(() =>
18
+ useProduct(
19
+ mockedProduct,
20
+ mockedConfigurator as unknown as Schemas["PropertyGroup"][],
21
+ ),
22
+ );
23
+
24
+ expect(vm.configurator).toStrictEqual(mockedConfigurator);
25
+ });
26
+
14
27
  it("changeVariant - should merge the current product with the new variant data", () => {
15
28
  const { vm } = useSetup(() => useProduct(mockedProduct));
16
29
  expect(vm.changeVariant()).toBeUndefined();
17
30
  });
18
31
 
19
32
  it("changeVariant - empty", () => {
20
- const { vm } = useSetup(useProduct);
33
+ const { vm } = useSetup(() => useProduct(mockedProduct));
21
34
 
22
35
  vm.changeVariant(Object.assign({ ...mockedProduct }, { id: "new-id" }));
23
36
  expect(vm.product.id).toBe("new-id");
@@ -19,6 +19,7 @@ describe("useProductAssociations", () => {
19
19
  );
20
20
 
21
21
  expect(vm.productAssociations).toStrictEqual([]);
22
+ expect(vm.isLoading).toBe(false);
22
23
  });
23
24
 
24
25
  it("load productAssociations - GET - Error", async () => {
@@ -74,4 +74,42 @@ describe("useProductConfigurator", () => {
74
74
  expect(vm.isLoadingOptions).toBe(true);
75
75
  expect(vm.getOptionGroups).toStrictEqual([]);
76
76
  });
77
+
78
+ it("getSelectedOptions returns selected options", () => {
79
+ vi.mocked(useProduct).mockReturnValue({
80
+ configurator: ref(mockedConfigurator),
81
+ product: ref(mockedProduct),
82
+ } as unknown as ReturnType<typeof useProduct>);
83
+ const { vm } = useSetup(useProductConfigurator);
84
+
85
+ expect(vm.getSelectedOptions).toEqual({
86
+ Colour: "cc02c6cf39ad43d5856a25f8928490bf",
87
+ });
88
+ });
89
+
90
+ it("handleChange without callback", async () => {
91
+ vi.mocked(useProduct).mockReturnValue({
92
+ configurator: ref(mockedConfigurator),
93
+ product: ref(mockedProduct),
94
+ } as unknown as ReturnType<typeof useProduct>);
95
+ const { vm } = useSetup(useProductConfigurator);
96
+
97
+ await vm.handleChange("test-group", "test-option");
98
+ expect(vm.getSelectedOptions).toMatchObject({
99
+ "test-group": "test-option",
100
+ });
101
+ });
102
+
103
+ it("getSelectedOptions skips optionIds not in configurator", () => {
104
+ vi.mocked(useProduct).mockReturnValue({
105
+ configurator: ref(mockedConfigurator),
106
+ product: ref({
107
+ ...mockedProduct,
108
+ optionIds: ["non-existent-option-id"],
109
+ }),
110
+ } as unknown as ReturnType<typeof useProduct>);
111
+ const { vm } = useSetup(useProductConfigurator);
112
+
113
+ expect(vm.getSelectedOptions).toEqual({});
114
+ });
77
115
  });
@@ -11,7 +11,7 @@ export type UseProductConfiguratorReturn = {
11
11
  handleChange(
12
12
  attribute: string,
13
13
  option: string,
14
- onChangeHandled: () => void,
14
+ onChangeHandled?: () => void,
15
15
  ): Promise<void>;
16
16
 
17
17
  findVariantForSelectedOptions(options?: {