@shopbite-de/storefront 1.25.0 → 1.26.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.
@@ -0,0 +1,49 @@
1
+ # Checkout steps: hydration mismatches on direct load
2
+
3
+ Date: 2026-09-16. Branch `fix/339-checkout-stepper-step`, issue #339.
4
+
5
+ ## Reproduced
6
+
7
+ Production build against the demo backend, guest session with one cart item
8
+ created through the Store API, `sw-context-token` cookie set in Playwright,
9
+ each step loaded directly:
10
+
11
+ | Step | Before | After |
12
+ | ----------------------------- | -------------------------------- | ---------------------- |
13
+ | `/bestellung/warenkorb` | no warning, "Warenkorb" active | unchanged |
14
+ | `/bestellung/zahlung-versand` | mismatch, "Warenkorb" active | no warning, step 2 |
15
+ | `/bestellung/bestaetigen` | mismatch, "Warenkorb" active | no warning, step 3 |
16
+
17
+ ## Two causes, one pattern
18
+
19
+ Both mismatches came from a child component changing state of its parent
20
+ during its setup. With SSR the parent's markup rendered before that change
21
+ reached it (or, in the second case, after it), while the browser hydrated with
22
+ the other value. Vue does not patch attributes and classes in production.
23
+
24
+ 1. **Stepper** (the cause suspected in the issue): the step pages called
25
+ `setStep(n)` of the Pinia checkout store in their setup, after
26
+ `bestellung.vue` had rendered `<UStepper>` with step 0. The serialized store
27
+ state carried the new step, so the browser hydrated with step n.
28
+ Fix: `bestellung.vue` derives the step from `route.path` (index in
29
+ `stepRoutes`); its setter navigates. The store and `useCheckoutStore` had no
30
+ other users (also none in `demos/` and `masala-mio/`) and are removed.
31
+ Pinia is still registered as a module but has no store now.
32
+ 2. **Order button on `/bestellung/bestaetigen`**, found only after fixing the
33
+ stepper (the dev server prints the mismatching node):
34
+ `Checkout/DeliveryTimeSelect.vue` emits `update:valid` from an immediate
35
+ watch. No time is selected before the business hours load in the browser
36
+ (`app.vue` on mount), so it always emits `false` first. On the server the
37
+ button renders after that emit ("Wir haben aktuell leider geschlossen",
38
+ lock icon, disabled); `Summary.vue` started with `isValidTime = ref(true)`,
39
+ so the browser hydrated "Jetzt bestellen!". Fix: start with `false`.
40
+
41
+ ## Verified
42
+
43
+ - Production build: no hydration warning on any step, correct active step.
44
+ - Client-side navigation: stepper click back to "Zahlung & Versand" and
45
+ "Warenkorb", "Weiter zu Prüfen & Bestellen" button forward.
46
+ - After the business hours load the order button reads "Jetzt bestellen!" and
47
+ is enabled (demo shop open).
48
+ - `pnpm typecheck` (0 errors), `pnpm prettier`, `pnpm eslint`,
49
+ `pnpm test:unit` without the Matomo variables (264 tests).
@@ -0,0 +1,39 @@
1
+ # Order button: loading state for the opening hours
2
+
3
+ Date: 2026-09-16. Branch `fix/349-order-button-loading`, issue #349.
4
+
5
+ ## Problem
6
+
7
+ `app.vue` loads business hours and holidays after mounting. Until then
8
+ `Checkout/DeliveryTimeSelect.vue` has no time to select and reports
9
+ `valid = false`, and `Checkout/Summary.vue` labelled the order button
10
+ "Wir haben aktuell leider geschlossen". The server HTML carried that label as
11
+ well, so the confirmation step always said "closed" first.
12
+
13
+ ## Change
14
+
15
+ `Summary.vue` reads `businessHours` and `holidays` from `useBusinessHours` and
16
+ `useHolidays` (the same "loaded" check as `useStoreStatus`). While either is
17
+ missing and customer data is available, the button is disabled, shows the
18
+ spinner and the label "Lade Öffnungszeiten …". "Einloggen oder Kundendaten
19
+ erfassen" keeps priority, it does not depend on the hours.
20
+
21
+ `DeliveryTimeSelect` was left unchanged: emitting a second state from it would
22
+ repeat the pattern of #339 (a child changing parent state during setup).
23
+ Reading the shared `useAsyncData` state directly renders the same on the
24
+ server and at hydration (both without data).
25
+
26
+ A failed request leaves the data empty, so the button keeps the loading state,
27
+ as the "Lade Öffnungszeiten..." badge of `DeliveryTimeSelect` already does.
28
+ Neither retries the request.
29
+
30
+ ## Verified
31
+
32
+ - `test/nuxt/CheckoutSummary.test.ts`: loading, closed after loading, order
33
+ possible with a valid time. The loading test fails without the change.
34
+ - Production build against the demo backend with a guest session: the server
35
+ HTML has the loading label, the button then goes from
36
+ "Lade Öffnungszeiten …" (disabled, spinner) straight to "Jetzt bestellen!"; no "closed" in
37
+ between, no hydration warning.
38
+ - `pnpm typecheck` (0 errors), `pnpm prettier`, `pnpm eslint`,
39
+ `pnpm test:unit` without the Matomo variables (267 tests).
@@ -0,0 +1,41 @@
1
+ # Remove Pinia
2
+
3
+ Date: 2026-09-16. Branch `feature/350-remove-pinia`, issue #350.
4
+
5
+ ## Why
6
+
7
+ #348 (#339) removed the only store, `useCheckoutStore`: the checkout stepper
8
+ derives its step from the route. Shared state is `useState`/`useAsyncData` in
9
+ composables everywhere else. `@shopware/composables`, `@shopware/nuxt-module`
10
+ and the demo shops (`demos/`, `masala-mio/`) do not use Pinia.
11
+
12
+ ## Changes
13
+
14
+ - `@pinia/nuxt` removed from `package.json` and `modules`, `pinia` removed from
15
+ the `framework` code splitting group in `nuxt.config.ts`.
16
+ - `README.md` project structure: no `stores/` directory.
17
+ - Monorepo `CLAUDE.md` (not versioned): "Pinia for state" replaced.
18
+
19
+ `pinia` stays in `pnpm-lock.yaml` as an optional peer dependency of
20
+ `vue-router` and `@sentry/vue`; neither installs nor bundles it for us.
21
+
22
+ Shops extending the layer no longer get Pinia through it. A shop with its own
23
+ stores adds `@pinia/nuxt` to its own dependencies and `modules`.
24
+
25
+ ## Measured
26
+
27
+ Production build, JS files the home page references (37 files):
28
+
29
+ | | Before | After |
30
+ | -------- | ---------- | ---------- |
31
+ | raw | 1,175.1 KB | 1,171.5 KB |
32
+ | gzip | 341.3 KB | 339.7 KB |
33
+ | `pinia` | 1 chunk | 0 chunks |
34
+
35
+ ## Verified
36
+
37
+ - `pnpm build`, home page, category page and `/bestellung/warenkorb` in the
38
+ browser without console errors (apart from the demo data icon
39
+ `lucide:french-fries`, unrelated).
40
+ - `pnpm typecheck` (0 errors), `pnpm prettier`, `pnpm eslint`,
41
+ `pnpm test:unit` without the Matomo variables (264 tests).
@@ -0,0 +1,57 @@
1
+ # Opening hours: error state and retry in the checkout
2
+
3
+ Date: 2026-09-16. Branch `fix/355-opening-hours-error`, issue #355.
4
+
5
+ ## Problem
6
+
7
+ When the business hours or holidays request failed in the browser, the
8
+ confirmation step kept its loading state (#349): order button disabled with
9
+ spinner, delivery time section "Lade Öffnungszeiten...". Nothing retried.
10
+
11
+ ## Decision (Lirim)
12
+
13
+ Retry automatically first, then show an error with a button: two more attempts
14
+ after 1 s and 3 s; if they fail too, the delivery time section shows an alert
15
+ "Öffnungszeiten konnten nicht geladen werden" with "Erneut versuchen", and the
16
+ order button carries the same text (disabled, no spinner).
17
+
18
+ ## Implementation
19
+
20
+ - `utils/retry.ts`: `withRetries(request, delays)`.
21
+ - `useBusinessHours`/`useHolidays`: the request is wrapped in `withRetries` with
22
+ `OPENING_HOURS_RETRY_DELAYS` in the browser only; on the server a retry would
23
+ delay every page (the footer prefetches the hours). Both now return `status`.
24
+ - `useOpeningHoursData`: `isLoaded` (both there), `hasFailed` (a missing one has
25
+ status `error` and no missing one is `pending`), `isLoading`, `retry()`
26
+ (refreshes only what is missing).
27
+ - `Checkout/Summary.vue` and `Checkout/DeliveryTimeSelect.vue` use it. The time
28
+ input and the holiday badge now need both data sets; before, the input showed
29
+ without bounds when only the holidays were loaded.
30
+
31
+ ## Findings
32
+
33
+ - Nuxt's `useAsyncData` keeps `error` set while a refresh runs and resets `data`
34
+ to the default on failure; `status` is the reliable signal (`pending` during
35
+ a retry).
36
+ - On checkout pages the business hours are in the SSR payload
37
+ (`Footer/Contact.vue` prefetches them), and `app.vue`'s refresh on mount is
38
+ served from that payload while hydrating. The browser then requests only the
39
+ holidays, so a browser-side failure of the business hours request does not
40
+ happen on a first load.
41
+ - The footer renders after the checkout on the server. If its prefetch fails,
42
+ the payload carries the error and the browser would hydrate `status: error`
43
+ while the server rendered the checkout without it. `hasFailed` is therefore
44
+ `false` until the component is mounted.
45
+
46
+ ## Verified
47
+
48
+ - Tests: `test/unit/retry.spec.ts`, `test/nuxt/useOpeningHoursData.test.ts`
49
+ (including "no failure before mounting"), `test/nuxt/CheckoutSummary.test.ts`
50
+ (error label).
51
+ - Production build against the demo backend, guest session, holidays request
52
+ answered with 500 in Playwright: three attempts, 4–6 s after loading the alert and
53
+ the button text, no hydration warning; "Erneut versuchen" with the request
54
+ unblocked loads the holidays and the button reads "Jetzt bestellen!". Without
55
+ blocking: unchanged flow, time input present.
56
+ - `pnpm typecheck` (0 errors), `pnpm prettier`, `pnpm eslint`,
57
+ `pnpm test:unit` without the Matomo variables (276 tests).
@@ -0,0 +1,63 @@
1
+ # Quick view: compact options and extras
2
+
3
+ The product quick view (`Product/QuickView.vue` → `Product/Detail.vue`) needed
4
+ a lot of scrolling for products with many extras. Measured on the demo shop
5
+ (Pizza Romana: 2 sizes, 8 extras, 6 ingredients, 390×844 viewport) the drawer
6
+ body was 775 px high with 598 px visible. Menus imported from Lieferando often
7
+ have 20–40 extras per product.
8
+
9
+ ## Causes
10
+
11
+ - The ingredients were listed three times: in the description, as chips at the
12
+ top of the body and again as the "Ohne" buttons at the bottom.
13
+ - Every extra was a pill with label and price. The pills were wider than half
14
+ the drawer, so each one took a full row (~47 px).
15
+ - After scrolling, the customer no longer saw what they had chosen.
16
+
17
+ ## Changes
18
+
19
+ - The body shows only the diet badges at the top. Ingredients are listed once,
20
+ in the deselectable "Zutaten" section (`DeselectIngredient.vue`), placed
21
+ before the extras.
22
+ - `CrossSelling.vue`: every cross-selling group is a collapsible section whose
23
+ header summarises the selection ("2 gewählt · +2,10 €"). Only the first group
24
+ starts open. Extras are checkbox rows with the price right-aligned. A group
25
+ with more than 8 entries shows the first 6 plus "Alle N anzeigen", and more
26
+ than 15 entries add a search field.
27
+ - `Detail.vue` fills the drawer body, so the add-to-cart button sits at the
28
+ bottom of the desktop side panel.
29
+
30
+ Result on the demo product: 681 px body height (was 775). With 24 extras and a
31
+ second group (mocked response) the body is 727 px, and 1490 px once all 24
32
+ extras are shown.
33
+
34
+ ## No height jumps
35
+
36
+ The phone drawer is as high as its content (up to 92vh), so anything that
37
+ changes the content height while choosing makes it jump:
38
+
39
+ - A first version showed a summary line above the button ("+ Extra Käse ·
40
+ ohne Salami"). It appeared with the first choice and grew the drawer by
41
+ 31 px. It was removed; the choices stay visible in the ingredient chips and
42
+ in the extras group header.
43
+ - Deselected ingredient chips used to gain an X icon, which made the chip wider
44
+ and could wrap the row. Both states now carry an icon of the same size (X to
45
+ remove, plus to add back).
46
+
47
+ Checked on the production menu of La Fattoria (12 pizzas with up to 34 extras, 360
48
+ and 390 px wide): toggling every ingredient and ticking an extra keeps the
49
+ drawer height constant.
50
+
51
+ ## Performance and hydration
52
+
53
+ Measured against a `main` build with the same settings:
54
+
55
+ - JS on the first load of `/speisekarte/`: unchanged (326.6 KB gzip both).
56
+ - Entry CSS: +114 B gzip (UCheckbox theme).
57
+ - Quick view chunk loaded when the drawer opens: +2.4 KB raw (~0.9 KB gzip).
58
+ - Only the first 6 extras of a long group are rendered initially.
59
+
60
+ Opening `/speisekarte/?produkt=LF-27` directly reports the same two hydration
61
+ mismatches on `main` and on this branch (built with `debug.hydration`): the
62
+ `useId`-based id of the account dropdown in the header and a fragment node.
63
+ They are not caused by the quick view changes.
package/nuxt.config.ts CHANGED
@@ -175,7 +175,6 @@ export default defineNuxtConfig({
175
175
  "@nuxt/scripts",
176
176
  "nuxt-vitalizer",
177
177
  "@nuxt/eslint",
178
- "@pinia/nuxt",
179
178
  ],
180
179
 
181
180
  content: {
@@ -275,7 +274,7 @@ export default defineNuxtConfig({
275
274
  groups: [
276
275
  {
277
276
  name: "framework",
278
- test: /node_modules\/(\.pnpm\/)?(vue|@vue\+|@vue\/|vue-router|unhead|@unhead|nuxt@|hookable|ofetch|ufo|defu|h3|devalue|klona|destr|cookie-es|radix3|rou3|unctx|pinia)[@/]/,
277
+ test: /node_modules\/(\.pnpm\/)?(vue|@vue\+|@vue\/|vue-router|unhead|@unhead|nuxt@|hookable|ofetch|ufo|defu|h3|devalue|klona|destr|cookie-es|radix3|rou3|unctx)[@/]/,
279
278
  minShareCount: 2,
280
279
  priority: 20,
281
280
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopbite-de/storefront",
3
- "version": "1.25.0",
3
+ "version": "1.26.1",
4
4
  "main": "nuxt.config.ts",
5
5
  "description": "Shopware storefront for food delivery shops",
6
6
  "keywords": [
@@ -28,7 +28,6 @@
28
28
  "@nuxt/ui": "^4.11.1",
29
29
  "@nuxtjs/robots": "^6.2.0",
30
30
  "@nuxtjs/sitemap": "^8.5.0",
31
- "@pinia/nuxt": "1.0.2",
32
31
  "@sentry/nuxt": "^10.73.0",
33
32
  "@shopware/api-client": "^1.5.1",
34
33
  "@shopware/api-gen": "^1.5.1",
@@ -57,7 +56,7 @@
57
56
  "@typescript-eslint/eslint-plugin": "^8.70.0",
58
57
  "@typescript-eslint/parser": "^8.70.0",
59
58
  "@vitejs/plugin-vue": "^6.0.8",
60
- "@vitest/ui": "5.0.0",
59
+ "@vitest/ui": "5.0.1",
61
60
  "@vue/compiler-dom": "^3.5.42",
62
61
  "@vue/server-renderer": "^3.5.42",
63
62
  "@vue/test-utils": "^2.5.0",
@@ -0,0 +1,127 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { mountSuspended, mockNuxtImport } from "@nuxt/test-utils/runtime";
3
+ import { defineComponent, h, onMounted, ref } from "vue";
4
+ import Summary from "~/components/Checkout/Summary.vue";
5
+
6
+ const { state } = vi.hoisted(() => ({
7
+ state: {
8
+ isLoading: true,
9
+ hasFailed: false,
10
+ validTime: false,
11
+ },
12
+ }));
13
+
14
+ mockNuxtImport("useOpeningHoursData", () => () => ({
15
+ isLoading: ref(state.isLoading),
16
+ hasFailed: ref(state.hasFailed),
17
+ }));
18
+
19
+ mockNuxtImport("useCheckout", () => () => ({
20
+ createOrder: vi.fn(),
21
+ selectedPaymentMethod: ref({ id: "pm1" }),
22
+ selectedShippingMethod: ref({ id: "sm1" }),
23
+ }));
24
+
25
+ mockNuxtImport("useCart", () => () => ({
26
+ refreshCart: vi.fn(),
27
+ }));
28
+
29
+ mockNuxtImport("useUser", () => () => ({
30
+ isLoggedIn: ref(false),
31
+ isGuestSession: ref(true),
32
+ refreshUser: vi.fn(),
33
+ }));
34
+
35
+ mockNuxtImport("useShopBiteConfig", () => () => ({
36
+ isCheckoutEnabled: ref(true),
37
+ refresh: vi.fn(),
38
+ }));
39
+
40
+ mockNuxtImport("useTrackEvent", () => () => ({
41
+ trackOrder: vi.fn(),
42
+ }));
43
+
44
+ mockNuxtImport("useCheckoutMethodGuard", () => () => ({
45
+ isShippingMethodBlocked: ref(false),
46
+ isPaymentMethodBlocked: ref(false),
47
+ ensureAvailableCheckoutMethods: vi.fn().mockResolvedValue(true),
48
+ }));
49
+
50
+ vi.mock("@shopware/composables", async (importOriginal) => ({
51
+ ...(await importOriginal<typeof import("@shopware/composables")>()),
52
+ useOrderPayment: () => ({ handlePayment: vi.fn(), paymentUrl: ref(null) }),
53
+ }));
54
+
55
+ // Reports the time as DeliveryTimeSelect does once a time is selected.
56
+ const DeliveryTimeSelectStub = defineComponent({
57
+ emits: ["update:valid"],
58
+ setup(_, { emit }) {
59
+ onMounted(() => emit("update:valid", state.validTime));
60
+ return () => h("div");
61
+ },
62
+ });
63
+
64
+ async function mountSummary() {
65
+ const wrapper = await mountSuspended(Summary, {
66
+ global: {
67
+ stubs: {
68
+ UserDetail: true,
69
+ CheckoutPaymentMethod: true,
70
+ CheckoutShippingMethod: true,
71
+ CheckoutDeliveryTimeSelect: DeliveryTimeSelectStub,
72
+ CheckoutVoucherInput: true,
73
+ QuickView: true,
74
+ },
75
+ },
76
+ });
77
+ await new Promise((resolve) => setTimeout(resolve, 0));
78
+ // The order button is the only button besides the stubbed children.
79
+ return wrapper.get("button");
80
+ }
81
+
82
+ describe("Checkout Summary order button", () => {
83
+ beforeEach(() => {
84
+ state.isLoading = true;
85
+ state.hasFailed = false;
86
+ state.validTime = false;
87
+ });
88
+
89
+ it("shows a loading state while the opening hours are not loaded", async () => {
90
+ const button = await mountSummary();
91
+
92
+ expect(button.text()).toBe("Lade Öffnungszeiten …");
93
+ expect(button.attributes("disabled")).toBeDefined();
94
+ expect(button.find(".animate-spin").exists()).toBe(true);
95
+ });
96
+
97
+ it("says the opening hours could not be loaded when loading failed", async () => {
98
+ state.isLoading = false;
99
+ state.hasFailed = true;
100
+
101
+ const button = await mountSummary();
102
+
103
+ expect(button.text()).toBe("Öffnungszeiten konnten nicht geladen werden");
104
+ expect(button.attributes("disabled")).toBeDefined();
105
+ expect(button.find(".animate-spin").exists()).toBe(false);
106
+ });
107
+
108
+ it("says the shop is closed once loaded without a valid time", async () => {
109
+ state.isLoading = false;
110
+
111
+ const button = await mountSummary();
112
+
113
+ expect(button.text()).toBe("Wir haben aktuell leider geschlossen");
114
+ expect(button.attributes("disabled")).toBeDefined();
115
+ expect(button.find(".animate-spin").exists()).toBe(false);
116
+ });
117
+
118
+ it("allows ordering once loaded with a valid time", async () => {
119
+ state.isLoading = false;
120
+ state.validTime = true;
121
+
122
+ const button = await mountSummary();
123
+
124
+ expect(button.text()).toBe("Jetzt bestellen!");
125
+ expect(button.attributes("disabled")).toBeUndefined();
126
+ });
127
+ });
@@ -0,0 +1,99 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { mountSuspended, mockNuxtImport } from "@nuxt/test-utils/runtime";
3
+ import ProductCrossSelling from "~/components/Product/CrossSelling.vue";
4
+ import type { AssociationItem } from "~/types/Association";
5
+
6
+ mockNuxtImport("useCommercePrice", () => () => ({
7
+ getFormattedPrice: (price: number) => `${price.toFixed(2)} €`,
8
+ }));
9
+
10
+ const group = (label: string, count: number): AssociationItem => ({
11
+ label,
12
+ products: Array.from({ length: count }, (_, index) => ({
13
+ label: `${label} ${index + 1}`,
14
+ value: `${label}-${index + 1}`,
15
+ price: "1.00 €",
16
+ unitPrice: 1,
17
+ })),
18
+ });
19
+
20
+ const rows = (wrapper: Awaited<ReturnType<typeof mountSuspended>>) =>
21
+ wrapper.findAll('[role="checkbox"]');
22
+
23
+ describe("ProductCrossSelling", () => {
24
+ it("opens only the first group", async () => {
25
+ const wrapper = await mountSuspended(ProductCrossSelling, {
26
+ props: { associations: [group("Extras", 3), group("Saucen", 2)] },
27
+ });
28
+
29
+ const toggles = wrapper.findAll("button[aria-expanded]");
30
+ expect(toggles.map((toggle) => toggle.attributes("aria-expanded"))).toEqual(
31
+ ["true", "false"],
32
+ );
33
+ expect(rows(wrapper)).toHaveLength(3);
34
+
35
+ await toggles[1]!.trigger("click");
36
+ expect(rows(wrapper)).toHaveLength(5);
37
+ });
38
+
39
+ it("shows every entry of a short list", async () => {
40
+ const wrapper = await mountSuspended(ProductCrossSelling, {
41
+ props: { associations: [group("Extras", 8)] },
42
+ });
43
+
44
+ expect(rows(wrapper)).toHaveLength(8);
45
+ expect(wrapper.text()).not.toContain("anzeigen");
46
+ });
47
+
48
+ it("shows the first entries of a long list and the rest on request", async () => {
49
+ const wrapper = await mountSuspended(ProductCrossSelling, {
50
+ props: { associations: [group("Extras", 12)] },
51
+ });
52
+
53
+ expect(rows(wrapper)).toHaveLength(6);
54
+ const showAll = wrapper
55
+ .findAll("button")
56
+ .find((button) => button.text().includes("Alle 12 anzeigen"));
57
+ await showAll!.trigger("click");
58
+ expect(rows(wrapper)).toHaveLength(12);
59
+ });
60
+
61
+ it("offers a search field for very long lists", async () => {
62
+ const wrapper = await mountSuspended(ProductCrossSelling, {
63
+ props: { associations: [group("Extras", 20)] },
64
+ });
65
+
66
+ const search = wrapper.find('input[aria-label="Extras durchsuchen"]');
67
+ await search.setValue("extras 1");
68
+ // "Extras 1" and "Extras 10" … "Extras 19"
69
+ expect(rows(wrapper)).toHaveLength(11);
70
+
71
+ await search.setValue("nichts");
72
+ expect(rows(wrapper)).toHaveLength(0);
73
+ expect(wrapper.text()).toContain("Keine Treffer");
74
+ });
75
+
76
+ it("emits the selection and summarises it in the group header", async () => {
77
+ const wrapper = await mountSuspended(ProductCrossSelling, {
78
+ props: { associations: [group("Extras", 3), group("Saucen", 2)] },
79
+ });
80
+
81
+ expect(wrapper.text()).toContain("optional");
82
+ await rows(wrapper)[0]!.trigger("click");
83
+ await rows(wrapper)[2]!.trigger("click");
84
+
85
+ const emitted = wrapper.emitted("extras-selected")!;
86
+ expect(emitted.at(-1)![0]).toMatchObject([
87
+ { value: "Extras-1" },
88
+ { value: "Extras-3" },
89
+ ]);
90
+ expect(wrapper.find("button[aria-expanded]").text()).toContain(
91
+ "2 gewählt · +2.00 €",
92
+ );
93
+
94
+ await rows(wrapper)[0]!.trigger("click");
95
+ expect(wrapper.emitted("extras-selected")!.at(-1)![0]).toMatchObject([
96
+ { value: "Extras-3" },
97
+ ]);
98
+ });
99
+ });
@@ -0,0 +1,120 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { mountSuspended, mockNuxtImport } from "@nuxt/test-utils/runtime";
3
+ import { defineComponent, h, nextTick, ref, type Ref } from "vue";
4
+
5
+ // Refs are created per test in beforeEach; the mocks read them lazily.
6
+ const { state } = vi.hoisted(() => ({
7
+ state: {
8
+ refreshBusinessHours: vi.fn(),
9
+ refreshHolidays: vi.fn(),
10
+ } as {
11
+ businessHours: Ref<unknown>;
12
+ businessHoursStatus: Ref<string>;
13
+ holidays: Ref<unknown>;
14
+ holidaysStatus: Ref<string>;
15
+ refreshBusinessHours: ReturnType<typeof vi.fn>;
16
+ refreshHolidays: ReturnType<typeof vi.fn>;
17
+ },
18
+ }));
19
+
20
+ mockNuxtImport("useBusinessHours", () => () => ({
21
+ businessHours: state.businessHours,
22
+ status: state.businessHoursStatus,
23
+ refresh: state.refreshBusinessHours,
24
+ }));
25
+
26
+ mockNuxtImport("useHolidays", () => () => ({
27
+ holidays: state.holidays,
28
+ status: state.holidaysStatus,
29
+ refresh: state.refreshHolidays,
30
+ }));
31
+
32
+ /** Also returns `hasFailed` as the first render (server, hydration) saw it. */
33
+ async function mountComposable() {
34
+ let result!: ReturnType<typeof useOpeningHoursData>;
35
+ let hasFailedOnRender!: boolean;
36
+ await mountSuspended(
37
+ defineComponent({
38
+ setup() {
39
+ result = useOpeningHoursData();
40
+ hasFailedOnRender = result.hasFailed.value;
41
+ return () => h("div");
42
+ },
43
+ }),
44
+ );
45
+ return { ...result, hasFailedOnRender };
46
+ }
47
+
48
+ describe("useOpeningHoursData", () => {
49
+ beforeEach(() => {
50
+ vi.clearAllMocks();
51
+ state.businessHours = ref(null);
52
+ state.businessHoursStatus = ref("idle");
53
+ state.holidays = ref(null);
54
+ state.holidaysStatus = ref("idle");
55
+ });
56
+
57
+ it("is loading until business hours and holidays are there", async () => {
58
+ state.businessHours.value = [];
59
+ state.businessHoursStatus.value = "success";
60
+ state.holidaysStatus.value = "pending";
61
+
62
+ const { isLoaded, isLoading, hasFailed } = await mountComposable();
63
+
64
+ expect(isLoaded.value).toBe(false);
65
+ expect(isLoading.value).toBe(true);
66
+ expect(hasFailed.value).toBe(false);
67
+
68
+ state.holidays.value = [];
69
+ state.holidaysStatus.value = "success";
70
+ await nextTick();
71
+
72
+ expect(isLoaded.value).toBe(true);
73
+ expect(isLoading.value).toBe(false);
74
+ });
75
+
76
+ it("has failed when a request failed and none is running", async () => {
77
+ state.businessHoursStatus.value = "error";
78
+ state.holidaysStatus.value = "pending";
79
+
80
+ const { isLoading, hasFailed } = await mountComposable();
81
+
82
+ expect(hasFailed.value).toBe(false);
83
+
84
+ state.holidays.value = [];
85
+ state.holidaysStatus.value = "success";
86
+ await nextTick();
87
+
88
+ expect(hasFailed.value).toBe(true);
89
+ expect(isLoading.value).toBe(false);
90
+ });
91
+
92
+ it("does not report a failure before mounting (hydration)", async () => {
93
+ state.businessHoursStatus.value = "error";
94
+ state.holidaysStatus.value = "error";
95
+
96
+ const { hasFailed, hasFailedOnRender } = await mountComposable();
97
+
98
+ expect(hasFailedOnRender).toBe(false);
99
+ expect(hasFailed.value).toBe(true);
100
+ });
101
+
102
+ it("loads again when retrying", async () => {
103
+ state.businessHours.value = [];
104
+ state.businessHoursStatus.value = "success";
105
+ state.holidaysStatus.value = "error";
106
+
107
+ const { hasFailed, isLoading, retry } = await mountComposable();
108
+ expect(hasFailed.value).toBe(true);
109
+
110
+ state.refreshHolidays.mockImplementation(async () => {
111
+ state.holidaysStatus.value = "pending";
112
+ });
113
+ await retry();
114
+
115
+ expect(state.refreshHolidays).toHaveBeenCalledTimes(1);
116
+ expect(state.refreshBusinessHours).not.toHaveBeenCalled();
117
+ expect(hasFailed.value).toBe(false);
118
+ expect(isLoading.value).toBe(true);
119
+ });
120
+ });