@shopbite-de/storefront 1.23.3 → 1.24.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 (153) hide show
  1. package/.env.example +19 -0
  2. package/.github/workflows/build.yaml +1 -1
  3. package/.github/workflows/ci.yaml +6 -3
  4. package/CLAUDE.md +41 -3
  5. package/README.md +139 -40
  6. package/api-gen.config.json +9 -0
  7. package/api-types/storeApiSchema.shopbite.overrides.json +35 -0
  8. package/api-types/storeApiTypes.d.ts +95 -81
  9. package/app/app.vue +37 -53
  10. package/app/assets/css/main.css +20 -4
  11. package/app/components/Address/Fields.vue +2 -21
  12. package/app/components/AnimatedSection.vue +9 -4
  13. package/app/components/BottomNavi.vue +9 -2
  14. package/app/components/Cart/Item.vue +21 -10
  15. package/app/components/Category/Header.vue +9 -3
  16. package/app/components/Category/Listing.vue +51 -42
  17. package/app/components/Checkout/PaymentAndDelivery.vue +19 -3
  18. package/app/components/Checkout/Summary.vue +65 -1
  19. package/app/components/Cta.vue +4 -2
  20. package/app/components/Food/MarqueeItem.vue +20 -8
  21. package/app/components/Footer/Contact.vue +78 -0
  22. package/app/components/Footer/StoreStatus.vue +30 -0
  23. package/app/components/Footer.vue +2 -1
  24. package/app/components/Header/Body.vue +1 -1
  25. package/app/components/Header/Right.vue +27 -13
  26. package/app/components/Header/Title.vue +1 -0
  27. package/app/components/Header.vue +5 -15
  28. package/app/components/Hero.vue +45 -2
  29. package/app/components/ImageGallery.vue +11 -5
  30. package/app/components/Product/Card.vue +9 -3
  31. package/app/components/Product/CardFooter.vue +22 -12
  32. package/app/components/User/RegistrationForm.vue +0 -1
  33. package/app/components/Wishlist.vue +2 -15
  34. package/app/composables/useAddToCart.ts +13 -13
  35. package/app/composables/useAddressAutocomplete.ts +12 -19
  36. package/app/composables/useAddressSuggestionArea.ts +16 -0
  37. package/app/composables/useAddressValidation.ts +3 -19
  38. package/app/composables/useCartMutations.ts +168 -0
  39. package/app/composables/{useCategory.ts → useCategoryById.ts} +1 -1
  40. package/app/composables/useCategorySeo.ts +22 -25
  41. package/app/composables/useCheckoutMethodGuard.ts +201 -0
  42. package/app/composables/useMatomo.ts +25 -0
  43. package/app/composables/useMatomoConfig.ts +12 -0
  44. package/app/composables/useMenuSectionSchema.ts +55 -0
  45. package/app/composables/useNavigation.ts +12 -9
  46. package/app/composables/usePageSeo.ts +50 -0
  47. package/app/composables/useRestaurantSchema.ts +64 -0
  48. package/app/composables/useScrollAnimation.ts +39 -8
  49. package/app/composables/useSearchTracking.ts +33 -0
  50. package/app/composables/useSeoUrlRoute.ts +58 -0
  51. package/app/composables/useSortingSelection.ts +28 -0
  52. package/app/composables/useStoreStatus.ts +48 -0
  53. package/app/composables/useTrackEvent.ts +29 -23
  54. package/app/pages/[...all].vue +4 -4
  55. package/app/pages/account/recover/password/index.vue +1 -0
  56. package/app/pages/anmelden.vue +4 -0
  57. package/app/pages/bestellung/[id]/erfolg.vue +1 -5
  58. package/app/pages/bestellung/[id]/fehler.vue +2 -2
  59. package/app/pages/bestellung/[id]/index.vue +9 -3
  60. package/app/pages/bestellung/bestaetigen.vue +1 -5
  61. package/app/pages/bestellung/warenkorb.vue +1 -5
  62. package/app/pages/bestellung/zahlung-versand.vue +1 -5
  63. package/app/pages/c/[...all].vue +2 -35
  64. package/app/pages/index.vue +25 -13
  65. package/app/pages/kontakt.vue +4 -0
  66. package/app/pages/konto/adressen.vue +4 -0
  67. package/app/pages/konto/bestellung/[id].vue +4 -0
  68. package/app/pages/konto/bestellungen.vue +4 -0
  69. package/app/pages/konto/index.vue +4 -0
  70. package/app/pages/konto/profil.vue +4 -0
  71. package/app/pages/maintenance.vue +6 -0
  72. package/app/pages/merkliste.vue +1 -7
  73. package/app/pages/passwort-vergessen.vue +1 -0
  74. package/app/pages/registrierung/bestaetigen.vue +4 -0
  75. package/app/pages/registrierung/index.vue +4 -0
  76. package/app/pages/speisekarte/[...all].vue +2 -36
  77. package/app/pages/suche.vue +24 -21
  78. package/app/plugins/matomo.ts +35 -0
  79. package/app/utils/hydrateWhenVisible.ts +20 -0
  80. package/app/utils/media.ts +33 -0
  81. package/app/utils/openingHours.ts +67 -0
  82. package/app/utils/schema.ts +235 -0
  83. package/app/utils/seo.ts +56 -0
  84. package/app/utils/seoPath.ts +57 -0
  85. package/content/index.yml +10 -9
  86. package/content.config.ts +3 -0
  87. package/docs/notes/2026-07-05-issue-259-matomo-broken.md +7 -0
  88. package/docs/notes/2026-09-08-issue-240-shipping-method-blocked.md +83 -0
  89. package/docs/notes/2026-09-08-issue-241-cart-lock-conflicts.md +63 -0
  90. package/docs/notes/2026-09-08-issue-244-category-url-trailing-slash.md +65 -0
  91. package/docs/notes/2026-09-08-issue-276-payment-method-blocked.md +39 -0
  92. package/docs/notes/2026-09-08-issue-277-typecheck.md +99 -0
  93. package/docs/notes/2026-09-10-issue-250-animated-section.md +23 -0
  94. package/docs/notes/2026-09-10-issue-251-shop-data-in-base-layer.md +30 -0
  95. package/docs/notes/2026-09-10-issue-272-restaurant-schema.md +27 -0
  96. package/docs/notes/2026-09-10-issue-273-performance-media.md +64 -0
  97. package/docs/notes/2026-09-10-issue-274-seo-basics.md +49 -0
  98. package/docs/notes/2026-09-10-issue-275-accessibility.md +46 -0
  99. package/docs/notes/2026-09-10-issue-290-footer-nap.md +28 -0
  100. package/docs/notes/2026-09-10-issue-291-seo-url-trailing-slash.md +24 -0
  101. package/docs/notes/2026-09-10-issue-294-matomo-without-config.md +33 -0
  102. package/docs/notes/2026-09-10-issue-295-search-hydration-mismatch.md +25 -0
  103. package/docs/notes/2026-09-10-issue-296-track-direct-search.md +19 -0
  104. package/docs/notes/2026-09-10-issue-312-store-api-criteria-post.md +64 -0
  105. package/docs/notes/2026-09-10-issue-313-wishlist-scoped-tailwind.md +29 -0
  106. package/docs/notes/2026-09-10-issue-314-mobile-js-cost.md +119 -0
  107. package/node.dockerfile +5 -2
  108. package/nuxt.config.ts +74 -15
  109. package/package.json +5 -3
  110. package/patches/@shopware__nuxt-module@1.5.1.patch +32 -0
  111. package/pnpm-workspace.yaml +2 -0
  112. package/public/hero-poster.webp +0 -0
  113. package/server/api/__sitemap__/urls.get.ts +49 -0
  114. package/server/api/category/[categoryId].get.ts +20 -9
  115. package/server/api/content/home.get.ts +14 -0
  116. package/server/api/content/page.get.ts +22 -0
  117. package/server/api/listing/[categoryId].get.ts +12 -18
  118. package/server/api/product/[productId]/cross-selling.get.ts +3 -9
  119. package/server/api/product/[productId].get.ts +4 -8
  120. package/server/plugins/site-url.ts +13 -0
  121. package/server/plugins/sitemap-trailing-slash.ts +26 -0
  122. package/server/utils/sitemap.ts +60 -0
  123. package/server/utils/storeApi.ts +34 -0
  124. package/shopware.d.ts +35 -11
  125. package/test/nuxt/AddressFields.test.ts +2 -73
  126. package/test/nuxt/AnimatedSection.test.ts +67 -0
  127. package/test/nuxt/CartItem.test.ts +95 -0
  128. package/test/nuxt/FooterContact.test.ts +102 -0
  129. package/test/nuxt/FooterStoreStatus.test.ts +48 -0
  130. package/test/nuxt/HeaderRight.test.ts +14 -10
  131. package/test/nuxt/Hero.test.ts +68 -0
  132. package/test/nuxt/PaymentAndDelivery.test.ts +67 -8
  133. package/test/nuxt/RegistrationForm.test.ts +3 -0
  134. package/test/nuxt/useAddToCart.test.ts +34 -1
  135. package/test/nuxt/useAddressAutocomplete.test.ts +2 -38
  136. package/test/nuxt/useAddressSuggestionArea.test.ts +27 -0
  137. package/test/nuxt/useBusinessHours.test.ts +1 -1
  138. package/test/nuxt/useCartMutations.test.ts +225 -0
  139. package/test/nuxt/useCheckoutMethodGuard.test.ts +386 -0
  140. package/test/nuxt/useScrollAnimation.test.ts +55 -49
  141. package/test/nuxt/useSearchTracking.test.ts +71 -0
  142. package/test/nuxt/useSeoUrlRoute.test.ts +93 -0
  143. package/test/nuxt/useStoreStatus.test.ts +77 -0
  144. package/test/nuxt/useTrackEvent.test.ts +112 -0
  145. package/test/unit/media.spec.ts +49 -0
  146. package/test/unit/openingHours.spec.ts +59 -0
  147. package/test/unit/schema.spec.ts +243 -0
  148. package/test/unit/seo.spec.ts +107 -0
  149. package/test/unit/seoPath.spec.ts +116 -0
  150. package/test/unit/sitemap.spec.ts +88 -0
  151. package/test/unit/useCategorySeo.spec.ts +40 -30
  152. package/test/unit/useSortingSelection.spec.ts +39 -0
  153. package/app/composables/useValidCitiesForDelivery.ts +0 -12
@@ -0,0 +1,386 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { mockNuxtImport } from "@nuxt/test-utils/runtime";
3
+ import { ref } from "vue";
4
+ import {
5
+ useCheckoutMethodGuard,
6
+ hasBlockedShippingMethod,
7
+ hasBlockedPaymentMethod,
8
+ getCartErrors,
9
+ } from "~/composables/useCheckoutMethodGuard";
10
+ import type { Schemas } from "#shopware";
11
+
12
+ const {
13
+ mockRefreshCart,
14
+ mockGetShippingMethods,
15
+ mockSetShippingMethod,
16
+ mockGetPaymentMethods,
17
+ mockSetPaymentMethod,
18
+ mockToastAdd,
19
+ } = vi.hoisted(() => ({
20
+ mockRefreshCart: vi.fn(),
21
+ mockGetShippingMethods: vi.fn(),
22
+ mockSetShippingMethod: vi.fn(),
23
+ mockGetPaymentMethods: vi.fn(),
24
+ mockSetPaymentMethod: vi.fn(),
25
+ mockToastAdd: vi.fn(),
26
+ }));
27
+
28
+ // Reactive state shared with the mocked composables. Only read lazily
29
+ // inside the composable factories, i.e. after module initialisation.
30
+ const cart = ref<Schemas["Cart"] | undefined>();
31
+ const sessionContext = ref<unknown>();
32
+ const selectedShippingMethod = ref<Schemas["ShippingMethod"] | null>(null);
33
+ const selectedPaymentMethod = ref<Schemas["PaymentMethod"] | null>(null);
34
+
35
+ mockNuxtImport("useCart", () => () => ({
36
+ cart,
37
+ refreshCart: mockRefreshCart,
38
+ }));
39
+
40
+ mockNuxtImport("useCheckout", () => () => ({
41
+ getShippingMethods: mockGetShippingMethods,
42
+ setShippingMethod: mockSetShippingMethod,
43
+ selectedShippingMethod,
44
+ getPaymentMethods: mockGetPaymentMethods,
45
+ setPaymentMethod: mockSetPaymentMethod,
46
+ selectedPaymentMethod,
47
+ }));
48
+
49
+ mockNuxtImport("useSessionContext", () => () => ({
50
+ sessionContext,
51
+ }));
52
+
53
+ mockNuxtImport("useToast", () => () => ({
54
+ add: mockToastAdd,
55
+ }));
56
+
57
+ const delivery = {
58
+ id: "sm-delivery",
59
+ name: "Lieferung",
60
+ position: 1,
61
+ } as Schemas["ShippingMethod"];
62
+ const pickup = {
63
+ id: "sm-pickup",
64
+ name: "Abholung",
65
+ position: 2,
66
+ } as Schemas["ShippingMethod"];
67
+
68
+ const cash = {
69
+ id: "pm-cash",
70
+ name: "Cash",
71
+ distinguishableName: "Barzahlung",
72
+ } as Schemas["PaymentMethod"];
73
+ const paypal = {
74
+ id: "pm-paypal",
75
+ name: "PayPal",
76
+ distinguishableName: "PayPal",
77
+ } as Schemas["PaymentMethod"];
78
+
79
+ const shippingBlocked = {
80
+ code: 0,
81
+ key: "shipping-method-blocked-Lieferung",
82
+ level: 10 as const,
83
+ message: "Shipping method Lieferung not available. Reason: not allowed",
84
+ messageKey: "shipping-method-blocked",
85
+ };
86
+
87
+ const paymentBlocked = {
88
+ code: 0,
89
+ key: "payment-method-blocked-Barzahlung",
90
+ level: 10 as const,
91
+ message: "Payment method Barzahlung not available. Reason: not allowed",
92
+ messageKey: "payment-method-blocked",
93
+ };
94
+
95
+ function cartWith(errors: Schemas["Cart"]["errors"]): Schemas["Cart"] {
96
+ return { errors } as unknown as Schemas["Cart"];
97
+ }
98
+
99
+ /** Makes the next cart refresh resolve to the given cart state. */
100
+ function nextRefreshSets(errors: Schemas["Cart"]["errors"]) {
101
+ mockRefreshCart.mockImplementationOnce(async () => {
102
+ cart.value = cartWith(errors);
103
+ });
104
+ }
105
+
106
+ describe("useCheckoutMethodGuard", () => {
107
+ beforeEach(() => {
108
+ vi.clearAllMocks();
109
+ cart.value = cartWith({});
110
+ sessionContext.value = {
111
+ salesChannel: { shippingMethodId: pickup.id, paymentMethodId: paypal.id },
112
+ };
113
+ selectedShippingMethod.value = delivery;
114
+ selectedPaymentMethod.value = cash;
115
+ mockRefreshCart.mockResolvedValue(undefined);
116
+ mockSetShippingMethod.mockResolvedValue(undefined);
117
+ mockSetPaymentMethod.mockResolvedValue(undefined);
118
+ mockGetShippingMethods.mockResolvedValue(ref([delivery, pickup]));
119
+ mockGetPaymentMethods.mockResolvedValue(ref([cash, paypal]));
120
+ });
121
+
122
+ describe("cart error helpers", () => {
123
+ it("reads errors delivered as keyed object", () => {
124
+ const c = cartWith({ [shippingBlocked.key]: shippingBlocked });
125
+ expect(getCartErrors(c)).toEqual([shippingBlocked]);
126
+ expect(hasBlockedShippingMethod(c)).toBe(true);
127
+ expect(hasBlockedPaymentMethod(c)).toBe(false);
128
+ });
129
+
130
+ it("reads errors delivered as array", () => {
131
+ const c = cartWith([paymentBlocked]);
132
+ expect(hasBlockedPaymentMethod(c)).toBe(true);
133
+ expect(hasBlockedShippingMethod(c)).toBe(false);
134
+ });
135
+
136
+ it("ignores unrelated errors and missing carts", () => {
137
+ const c = cartWith({
138
+ "promotion-not-found-x": {
139
+ ...shippingBlocked,
140
+ messageKey: "promotion-not-found",
141
+ },
142
+ });
143
+ expect(hasBlockedShippingMethod(c)).toBe(false);
144
+ expect(hasBlockedPaymentMethod(c)).toBe(false);
145
+ expect(hasBlockedShippingMethod(undefined)).toBe(false);
146
+ expect(hasBlockedPaymentMethod(undefined)).toBe(false);
147
+ });
148
+ });
149
+
150
+ describe("ensureAvailableShippingMethod", () => {
151
+ it("returns true without switching when nothing is blocked", async () => {
152
+ const { ensureAvailableShippingMethod, isShippingMethodBlocked } =
153
+ useCheckoutMethodGuard();
154
+
155
+ await expect(ensureAvailableShippingMethod()).resolves.toBe(true);
156
+
157
+ expect(mockRefreshCart).toHaveBeenCalledTimes(1);
158
+ expect(mockGetShippingMethods).not.toHaveBeenCalled();
159
+ expect(mockSetShippingMethod).not.toHaveBeenCalled();
160
+ expect(mockToastAdd).not.toHaveBeenCalled();
161
+ expect(isShippingMethodBlocked.value).toBe(false);
162
+ });
163
+
164
+ it("switches to the sales-channel default shipping method when blocked", async () => {
165
+ cart.value = cartWith({ [shippingBlocked.key]: shippingBlocked });
166
+ mockRefreshCart.mockImplementationOnce(async () => {});
167
+ nextRefreshSets({});
168
+ const extra = {
169
+ id: "sm-extra",
170
+ name: "Express",
171
+ position: 0,
172
+ } as Schemas["ShippingMethod"];
173
+ mockGetShippingMethods.mockResolvedValue(ref([extra, delivery, pickup]));
174
+
175
+ const { ensureAvailableShippingMethod } = useCheckoutMethodGuard();
176
+
177
+ await expect(ensureAvailableShippingMethod()).resolves.toBe(true);
178
+
179
+ expect(mockGetShippingMethods).toHaveBeenCalledWith({
180
+ forceReload: true,
181
+ });
182
+ expect(mockSetShippingMethod).toHaveBeenCalledWith({ id: pickup.id });
183
+ expect(mockRefreshCart).toHaveBeenCalledTimes(2);
184
+ expect(mockToastAdd).toHaveBeenCalledWith(
185
+ expect.objectContaining({
186
+ title: "Versandart geändert",
187
+ description:
188
+ "Lieferung ist nicht mehr verfügbar. Abholung wurde ausgewählt.",
189
+ }),
190
+ );
191
+ });
192
+
193
+ it("falls back to the first available method when the default is not available", async () => {
194
+ cart.value = cartWith({ [shippingBlocked.key]: shippingBlocked });
195
+ sessionContext.value = {
196
+ salesChannel: { shippingMethodId: delivery.id },
197
+ };
198
+ mockRefreshCart.mockImplementationOnce(async () => {});
199
+ nextRefreshSets({});
200
+ // The blocked method is still returned by the API in some setups
201
+ mockGetShippingMethods.mockResolvedValue(ref([delivery, pickup]));
202
+
203
+ const { ensureAvailableShippingMethod } = useCheckoutMethodGuard();
204
+
205
+ await expect(ensureAvailableShippingMethod()).resolves.toBe(true);
206
+ expect(mockSetShippingMethod).toHaveBeenCalledWith({ id: pickup.id });
207
+ });
208
+
209
+ it("returns false when no alternative shipping method exists", async () => {
210
+ cart.value = cartWith({ [shippingBlocked.key]: shippingBlocked });
211
+ mockGetShippingMethods.mockResolvedValue(ref([delivery]));
212
+
213
+ const { ensureAvailableShippingMethod, isShippingMethodBlocked } =
214
+ useCheckoutMethodGuard();
215
+
216
+ await expect(ensureAvailableShippingMethod()).resolves.toBe(false);
217
+
218
+ expect(mockSetShippingMethod).not.toHaveBeenCalled();
219
+ expect(mockToastAdd).not.toHaveBeenCalled();
220
+ expect(isShippingMethodBlocked.value).toBe(true);
221
+ });
222
+
223
+ it("returns false when the cart is still blocked after switching", async () => {
224
+ cart.value = cartWith({ [shippingBlocked.key]: shippingBlocked });
225
+
226
+ const { ensureAvailableShippingMethod } = useCheckoutMethodGuard();
227
+
228
+ await expect(ensureAvailableShippingMethod()).resolves.toBe(false);
229
+
230
+ expect(mockSetShippingMethod).toHaveBeenCalledWith({ id: pickup.id });
231
+ expect(mockToastAdd).not.toHaveBeenCalled();
232
+ });
233
+ });
234
+
235
+ describe("ensureAvailablePaymentMethod", () => {
236
+ it("switches to the sales-channel default payment method when blocked", async () => {
237
+ cart.value = cartWith({ [paymentBlocked.key]: paymentBlocked });
238
+ mockRefreshCart.mockImplementationOnce(async () => {});
239
+ nextRefreshSets({});
240
+
241
+ const { ensureAvailablePaymentMethod, isPaymentMethodBlocked } =
242
+ useCheckoutMethodGuard();
243
+
244
+ await expect(ensureAvailablePaymentMethod()).resolves.toBe(true);
245
+
246
+ expect(mockGetPaymentMethods).toHaveBeenCalledWith({
247
+ forceReload: true,
248
+ });
249
+ expect(mockSetPaymentMethod).toHaveBeenCalledWith({ id: paypal.id });
250
+ expect(mockSetShippingMethod).not.toHaveBeenCalled();
251
+ expect(isPaymentMethodBlocked.value).toBe(false);
252
+ expect(mockToastAdd).toHaveBeenCalledWith(
253
+ expect.objectContaining({
254
+ title: "Zahlart geändert",
255
+ description:
256
+ "Barzahlung ist nicht mehr verfügbar. PayPal wurde ausgewählt.",
257
+ }),
258
+ );
259
+ });
260
+
261
+ it("returns false when no alternative payment method exists", async () => {
262
+ cart.value = cartWith({ [paymentBlocked.key]: paymentBlocked });
263
+ mockGetPaymentMethods.mockResolvedValue(ref([cash]));
264
+
265
+ const { ensureAvailablePaymentMethod, isPaymentMethodBlocked } =
266
+ useCheckoutMethodGuard();
267
+
268
+ await expect(ensureAvailablePaymentMethod()).resolves.toBe(false);
269
+
270
+ expect(mockSetPaymentMethod).not.toHaveBeenCalled();
271
+ expect(mockToastAdd).not.toHaveBeenCalled();
272
+ expect(isPaymentMethodBlocked.value).toBe(true);
273
+ });
274
+ });
275
+
276
+ describe("ensureAvailableCheckoutMethods", () => {
277
+ it("refreshes the cart once and returns true when nothing is blocked", async () => {
278
+ const { ensureAvailableCheckoutMethods } = useCheckoutMethodGuard();
279
+
280
+ await expect(ensureAvailableCheckoutMethods()).resolves.toBe(true);
281
+
282
+ expect(mockRefreshCart).toHaveBeenCalledTimes(1);
283
+ expect(mockSetShippingMethod).not.toHaveBeenCalled();
284
+ expect(mockSetPaymentMethod).not.toHaveBeenCalled();
285
+ });
286
+
287
+ it("resolves shipping first, then payment, when both are blocked", async () => {
288
+ cart.value = cartWith({
289
+ [shippingBlocked.key]: shippingBlocked,
290
+ [paymentBlocked.key]: paymentBlocked,
291
+ });
292
+ mockRefreshCart.mockImplementationOnce(async () => {});
293
+ // after shipping switch: only payment still blocked
294
+ nextRefreshSets({ [paymentBlocked.key]: paymentBlocked });
295
+ // after payment switch: clean
296
+ nextRefreshSets({});
297
+
298
+ const { ensureAvailableCheckoutMethods } = useCheckoutMethodGuard();
299
+
300
+ await expect(ensureAvailableCheckoutMethods()).resolves.toBe(true);
301
+
302
+ expect(mockSetShippingMethod).toHaveBeenCalledWith({ id: pickup.id });
303
+ expect(mockSetPaymentMethod).toHaveBeenCalledWith({ id: paypal.id });
304
+ expect(mockSetShippingMethod.mock.invocationCallOrder[0]).toBeLessThan(
305
+ mockSetPaymentMethod.mock.invocationCallOrder[0] as number,
306
+ );
307
+ expect(mockRefreshCart).toHaveBeenCalledTimes(3);
308
+ expect(mockToastAdd).toHaveBeenCalledTimes(2);
309
+ });
310
+
311
+ it("leaves the payment method untouched when shipping cannot be resolved", async () => {
312
+ cart.value = cartWith({
313
+ [shippingBlocked.key]: shippingBlocked,
314
+ [paymentBlocked.key]: paymentBlocked,
315
+ });
316
+ mockGetShippingMethods.mockResolvedValue(ref([delivery]));
317
+
318
+ const { ensureAvailableCheckoutMethods } = useCheckoutMethodGuard();
319
+
320
+ await expect(ensureAvailableCheckoutMethods()).resolves.toBe(false);
321
+
322
+ expect(mockGetPaymentMethods).not.toHaveBeenCalled();
323
+ expect(mockSetPaymentMethod).not.toHaveBeenCalled();
324
+ expect(mockToastAdd).not.toHaveBeenCalled();
325
+ });
326
+
327
+ it("returns false when the payment method cannot be resolved", async () => {
328
+ cart.value = cartWith({ [paymentBlocked.key]: paymentBlocked });
329
+ mockGetPaymentMethods.mockResolvedValue(ref([cash]));
330
+
331
+ const { ensureAvailableCheckoutMethods, isPaymentMethodBlocked } =
332
+ useCheckoutMethodGuard();
333
+
334
+ await expect(ensureAvailableCheckoutMethods()).resolves.toBe(false);
335
+ expect(isPaymentMethodBlocked.value).toBe(true);
336
+ });
337
+
338
+ it("serializes concurrent calls so the switch happens only once", async () => {
339
+ cart.value = cartWith({ [shippingBlocked.key]: shippingBlocked });
340
+ let releaseFirstRefresh: () => void = () => {};
341
+ mockRefreshCart.mockImplementationOnce(
342
+ () => new Promise<void>((r) => (releaseFirstRefresh = r)),
343
+ );
344
+ nextRefreshSets({});
345
+
346
+ const { ensureAvailableCheckoutMethods, ensureAvailableShippingMethod } =
347
+ useCheckoutMethodGuard();
348
+
349
+ const first = ensureAvailableCheckoutMethods();
350
+ const second = ensureAvailableShippingMethod();
351
+ await Promise.resolve();
352
+ expect(mockRefreshCart).toHaveBeenCalledTimes(1);
353
+
354
+ releaseFirstRefresh();
355
+ await expect(first).resolves.toBe(true);
356
+ await expect(second).resolves.toBe(true);
357
+
358
+ expect(mockSetShippingMethod).toHaveBeenCalledTimes(1);
359
+ expect(mockToastAdd).toHaveBeenCalledTimes(1);
360
+ // second call re-checked after the first one finished
361
+ expect(mockRefreshCart).toHaveBeenCalledTimes(3);
362
+ expect(mockRefreshCart.mock.invocationCallOrder[2]).toBeGreaterThan(
363
+ mockSetShippingMethod.mock.invocationCallOrder[0] as number,
364
+ );
365
+ });
366
+
367
+ it("still runs after a previous call failed", async () => {
368
+ mockRefreshCart.mockRejectedValueOnce(new Error("network"));
369
+
370
+ const { ensureAvailableCheckoutMethods } = useCheckoutMethodGuard();
371
+
372
+ await expect(ensureAvailableCheckoutMethods()).rejects.toThrow("network");
373
+ await expect(ensureAvailableCheckoutMethods()).resolves.toBe(true);
374
+ });
375
+
376
+ it("resets isResolving even when a request fails", async () => {
377
+ mockRefreshCart.mockRejectedValueOnce(new Error("network"));
378
+
379
+ const { ensureAvailableCheckoutMethods, isResolving } =
380
+ useCheckoutMethodGuard();
381
+
382
+ await expect(ensureAvailableCheckoutMethods()).rejects.toThrow("network");
383
+ expect(isResolving.value).toBe(false);
384
+ });
385
+ });
386
+ });
@@ -1,20 +1,35 @@
1
- import { describe, it, expect, vi, beforeEach } from "vitest";
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
2
  import { useScrollAnimation } from "~/composables/useScrollAnimation";
3
3
  import { mount } from "@vue/test-utils";
4
4
  import { defineComponent, nextTick } from "vue";
5
5
 
6
+ const TestComponent = defineComponent({
7
+ setup() {
8
+ const { isHidden, elementRef } = useScrollAnimation();
9
+ return { isHidden, elementRef };
10
+ },
11
+ template: '<div ref="elementRef"></div>',
12
+ });
13
+
6
14
  describe("useScrollAnimation", () => {
7
15
  let observeMock: ReturnType<typeof vi.fn>;
8
16
  let unobserveMock: ReturnType<typeof vi.fn>;
9
17
  let disconnectMock: ReturnType<typeof vi.fn>;
10
18
  let intersectionCallback: IntersectionObserverCallback;
11
19
 
20
+ const intersect = (isIntersecting: boolean) =>
21
+ intersectionCallback(
22
+ [
23
+ { isIntersecting, target: document.createElement("div") },
24
+ ] as unknown as IntersectionObserverEntry[],
25
+ {} as IntersectionObserver,
26
+ );
27
+
12
28
  beforeEach(() => {
13
29
  observeMock = vi.fn();
14
30
  unobserveMock = vi.fn();
15
31
  disconnectMock = vi.fn();
16
32
 
17
- // Mock IntersectionObserver
18
33
  global.IntersectionObserver = vi.fn().mockImplementation(function (
19
34
  this: IntersectionObserver,
20
35
  callback: IntersectionObserverCallback,
@@ -26,76 +41,67 @@ describe("useScrollAnimation", () => {
26
41
  this.disconnect =
27
42
  disconnectMock as unknown as IntersectionObserver["disconnect"];
28
43
  }) as unknown as typeof IntersectionObserver;
44
+
45
+ vi.stubGlobal("matchMedia", () => ({ matches: false }));
29
46
  });
30
47
 
31
- it("should initialize with isVisible false", () => {
32
- const TestComponent = defineComponent({
33
- setup() {
34
- const { isVisible, elementRef } = useScrollAnimation();
35
- return { isVisible, elementRef };
36
- },
37
- template: '<div ref="elementRef"></div>',
38
- });
48
+ afterEach(() => {
49
+ vi.unstubAllGlobals();
50
+ });
39
51
 
52
+ it("renders visible before mount and starts observing on mount", async () => {
40
53
  const wrapper = mount(TestComponent);
41
- expect(wrapper.vm.isVisible).toBe(false);
54
+ expect(wrapper.vm.isHidden).toBe(false);
55
+
56
+ await nextTick();
57
+ expect(global.IntersectionObserver).toHaveBeenCalledWith(
58
+ expect.any(Function),
59
+ expect.objectContaining({ rootMargin: "100000px 0px -100px 0px" }),
60
+ );
61
+ expect(observeMock).toHaveBeenCalled();
42
62
  });
43
63
 
44
- it("should start observing on mount", async () => {
45
- const TestComponent = defineComponent({
46
- setup() {
47
- const { isVisible, elementRef } = useScrollAnimation();
48
- return { isVisible, elementRef };
49
- },
50
- template: '<div ref="elementRef"></div>',
51
- });
64
+ it("keeps an element that is already in view visible and stops observing", async () => {
65
+ const wrapper = mount(TestComponent);
66
+ await nextTick();
52
67
 
53
- mount(TestComponent);
68
+ intersect(true);
54
69
  await nextTick();
55
70
 
56
- expect(global.IntersectionObserver).toHaveBeenCalled();
57
- expect(observeMock).toHaveBeenCalled();
71
+ expect(wrapper.vm.isHidden).toBe(false);
72
+ expect(unobserveMock).toHaveBeenCalled();
58
73
  });
59
74
 
60
- it("should set isVisible to true when intersecting and stop observing", async () => {
61
- const TestComponent = defineComponent({
62
- setup() {
63
- const { isVisible, elementRef } = useScrollAnimation();
64
- return { isVisible, elementRef };
65
- },
66
- template: '<div ref="elementRef"></div>',
67
- });
68
-
75
+ it("hides an element below the fold until it scrolls into view", async () => {
69
76
  const wrapper = mount(TestComponent);
70
77
  await nextTick();
71
78
 
72
- // Simulate intersection
73
- const mockEntry = { isIntersecting: true, target: wrapper.element };
74
- intersectionCallback([mockEntry]);
79
+ intersect(false);
80
+ await nextTick();
81
+ expect(wrapper.vm.isHidden).toBe(true);
82
+ expect(unobserveMock).not.toHaveBeenCalled();
75
83
 
84
+ intersect(true);
76
85
  await nextTick();
77
- expect(wrapper.vm.isVisible).toBe(true);
78
- expect(unobserveMock).toHaveBeenCalledWith(wrapper.element);
86
+ expect(wrapper.vm.isHidden).toBe(false);
87
+ expect(unobserveMock).toHaveBeenCalled();
79
88
  });
80
89
 
81
- it("should not set isVisible to true when not intersecting", async () => {
82
- const TestComponent = defineComponent({
83
- setup() {
84
- const { isVisible, elementRef } = useScrollAnimation();
85
- return { isVisible, elementRef };
86
- },
87
- template: '<div ref="elementRef"></div>',
88
- });
90
+ it("never hides content for users who prefer reduced motion", async () => {
91
+ vi.stubGlobal("matchMedia", () => ({ matches: true }));
89
92
 
90
93
  const wrapper = mount(TestComponent);
91
94
  await nextTick();
92
95
 
93
- // Simulate non-intersection
94
- const mockEntry = { isIntersecting: false, target: wrapper.element };
95
- intersectionCallback([mockEntry]);
96
+ expect(global.IntersectionObserver).not.toHaveBeenCalled();
97
+ expect(wrapper.vm.isHidden).toBe(false);
98
+ });
96
99
 
100
+ it("disconnects the observer on unmount", async () => {
101
+ const wrapper = mount(TestComponent);
97
102
  await nextTick();
98
- expect(wrapper.vm.isVisible).toBe(false);
99
- expect(unobserveMock).not.toHaveBeenCalled();
103
+
104
+ wrapper.unmount();
105
+ expect(disconnectMock).toHaveBeenCalled();
100
106
  });
101
107
  });
@@ -0,0 +1,71 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { mockNuxtImport } from "@nuxt/test-utils/runtime";
3
+ import { nextTick, ref } from "vue";
4
+ import type { Schemas } from "#shopware";
5
+ import { useSearchTracking } from "../../app/composables/useSearchTracking";
6
+
7
+ const { mockTrackSearch } = vi.hoisted(() => ({ mockTrackSearch: vi.fn() }));
8
+
9
+ mockNuxtImport("useTrackEvent", () => () => ({
10
+ trackSearch: mockTrackSearch,
11
+ }));
12
+
13
+ const products = (...numbers: string[]) =>
14
+ numbers.map((productNumber) => ({ productNumber }) as Schemas["Product"]);
15
+
16
+ describe("useSearchTracking", () => {
17
+ beforeEach(() => {
18
+ vi.clearAllMocks();
19
+ });
20
+
21
+ it("tracks results that are already present on setup (direct page load)", () => {
22
+ useSearchTracking(ref("pizza"), ref(products("21", "22")), ref(false));
23
+
24
+ expect(mockTrackSearch).toHaveBeenCalledTimes(1);
25
+ expect(mockTrackSearch).toHaveBeenCalledWith("pizza", ["21", "22"]);
26
+ });
27
+
28
+ it("waits for the skeleton to disappear (client-side navigation)", async () => {
29
+ const elements = ref(products());
30
+ const showSkeleton = ref(true);
31
+ useSearchTracking(ref("pizza"), elements, showSkeleton);
32
+
33
+ expect(mockTrackSearch).not.toHaveBeenCalled();
34
+
35
+ elements.value = products("21");
36
+ showSkeleton.value = false;
37
+ await nextTick();
38
+
39
+ expect(mockTrackSearch).toHaveBeenCalledTimes(1);
40
+ expect(mockTrackSearch).toHaveBeenCalledWith("pizza", ["21"]);
41
+ });
42
+
43
+ it("tracks a new term once and ignores re-fetches of the same term", async () => {
44
+ const query = ref("pizza");
45
+ const elements = ref(products("21"));
46
+ useSearchTracking(query, elements, ref(false));
47
+ expect(mockTrackSearch).toHaveBeenCalledTimes(1);
48
+
49
+ // sorting change: same term, new results
50
+ elements.value = products("22", "21");
51
+ await nextTick();
52
+ expect(mockTrackSearch).toHaveBeenCalledTimes(1);
53
+
54
+ // new search
55
+ query.value = "salat";
56
+ elements.value = products("12");
57
+ await nextTick();
58
+ expect(mockTrackSearch).toHaveBeenCalledTimes(2);
59
+ expect(mockTrackSearch).toHaveBeenLastCalledWith("salat", ["12"]);
60
+ });
61
+
62
+ it("does not track without a search term", async () => {
63
+ const elements = ref(products());
64
+ useSearchTracking(ref(""), elements, ref(false));
65
+
66
+ elements.value = products("21");
67
+ await nextTick();
68
+
69
+ expect(mockTrackSearch).not.toHaveBeenCalled();
70
+ });
71
+ });