@shopbite-de/storefront 2.5.0 → 2.6.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.
@@ -2,6 +2,7 @@ import { queryCollection } from "@nuxt/content/server";
2
2
  import { defineEventHandler } from "nuxt/server";
3
3
  import type { components } from "~~/api-types/storeApiTypes";
4
4
  import { getDiets, getMainIngredients } from "../../app/utils/product";
5
+ import { fulfillmentLeadTime } from "../../app/utils/leadTime";
5
6
  import { productDeepLink } from "../../app/utils/productUrl";
6
7
  import { splitList, toAbsoluteUrl } from "../../app/utils/seo";
7
8
  import { buildLlmsTxt, type LlmsMenuSection } from "../utils/llmsTxt";
@@ -87,9 +88,7 @@ export default defineEventHandler(async (event) => {
87
88
  storeApi<{ holidays?: { start?: string; end?: string }[] }>(
88
89
  "/shopbite/holiday",
89
90
  ),
90
- storeApi<{ isCheckoutEnabled?: boolean; deliveryTime?: number }>(
91
- "/shopbite/config",
92
- ),
91
+ storeApi<Schemas["ShopBiteConfig"]>("/shopbite/config"),
93
92
  storeApi<Schemas["SalesChannelContext"]>("/context"),
94
93
  queryCollection(event, "landingpages")
95
94
  .select("path", "title", "description")
@@ -135,7 +134,9 @@ export default defineEventHandler(async (event) => {
135
134
  businessHours: value(hours)?.businessHours,
136
135
  holidays: value(holidays)?.holidays,
137
136
  isCheckoutEnabled: value(config)?.isCheckoutEnabled,
138
- deliveryTime: value(config)?.deliveryTime,
137
+ // lead times of the delivery and pickup methods (shopbite#6)
138
+ deliveryTime: fulfillmentLeadTime(value(config), "delivery"),
139
+ pickupTime: fulfillmentLeadTime(value(config), "pickup"),
139
140
  menuUrl: toAbsoluteUrl(siteUrl, "/speisekarte"),
140
141
  menu: (value(navigation) ?? [])
141
142
  .filter((category) => category.type === "page")
@@ -40,8 +40,10 @@ export type LlmsTxtInput = {
40
40
  }[];
41
41
  holidays?: { start?: string; end?: string }[];
42
42
  isCheckoutEnabled?: boolean;
43
- /** Minutes until delivery. */
44
- deliveryTime?: number;
43
+ /** Minutes until delivery (lead time of the delivery method). */
44
+ deliveryTime?: number | null;
45
+ /** Minutes until an order is ready for pickup (pickup method). */
46
+ pickupTime?: number | null;
45
47
  menuUrl?: string;
46
48
  menu?: LlmsMenuSection[];
47
49
  pages?: { title: string; url: string; description?: string }[];
@@ -169,7 +171,9 @@ export function buildLlmsTxt(input: LlmsTxtInput): string {
169
171
  input.deliveryTime
170
172
  ? `- Lieferzeit: ca. ${input.deliveryTime} Minuten`
171
173
  : undefined,
172
- input.address?.street ? "- Abholung im Restaurant möglich" : undefined,
174
+ input.address?.street
175
+ ? `- Abholung im Restaurant möglich${input.pickupTime ? `, abholbereit in ca. ${input.pickupTime} Minuten` : ""}`
176
+ : undefined,
173
177
  ].filter((line): line is string => Boolean(line))
174
178
  : [];
175
179
 
@@ -19,7 +19,7 @@ const cachedConfig = defineCachedFunction(
19
19
  const load = createResilientLoader<ShopBiteConfig>();
20
20
 
21
21
  /**
22
- * The ShopBite plugin configuration (delivery time, checkout switch, menu
22
+ * The ShopBite plugin configuration (lead times, checkout switch, menu
23
23
  * root) for server-side rendering, `/api/shopbite/config` and the menu root.
24
24
  * When Shopware fails, the last good configuration is kept (the menu stays
25
25
  * on its root) and Shopware is asked again only after a pause, so an outage
@@ -36,10 +36,13 @@ mockNuxtImport("useUser", () => () => ({
36
36
  }));
37
37
  mockNuxtImport("useShopBiteConfig", () => () => ({
38
38
  isCheckoutEnabled: ref(true),
39
- deliveryTime: ref(30),
40
39
  refresh: vi.fn(),
41
40
  checkCheckoutEnabled: vi.fn().mockResolvedValue(true),
42
41
  }));
42
+ mockNuxtImport("useShippingLeadTime", () => () => ({
43
+ fulfillment: ref("delivery"),
44
+ leadTime: ref(30),
45
+ }));
43
46
  mockNuxtImport("useTrackEvent", () => () => ({ trackOrder: vi.fn() }));
44
47
  mockNuxtImport("useCheckoutMethodGuard", () => () => ({
45
48
  isShippingMethodBlocked: ref(false),
@@ -14,9 +14,15 @@ const { state, mocks } = vi.hoisted(() => ({
14
14
  validTime: false,
15
15
  shippingBlocked: false,
16
16
  customer: true,
17
+ fulfillment: "delivery" as "delivery" | "pickup",
17
18
  },
18
19
  }));
19
20
 
21
+ mockNuxtImport("useShippingLeadTime", () => () => ({
22
+ fulfillment: ref(state.fulfillment),
23
+ leadTime: ref(30),
24
+ }));
25
+
20
26
  mockNuxtImport("useOpeningHoursData", () => () => ({
21
27
  isLoading: ref(state.isLoading),
22
28
  hasFailed: ref(state.hasFailed),
@@ -44,6 +50,10 @@ mockNuxtImport("useShopBiteConfig", () => () => ({
44
50
  checkCheckoutEnabled: mocks.checkCheckoutEnabled,
45
51
  }));
46
52
 
53
+ // A successful order navigates to the confirmation page; loading that
54
+ // route after the test environment is torn down is an unhandled error.
55
+ mockNuxtImport("navigateTo", () => vi.fn());
56
+
47
57
  mockNuxtImport("useTrackEvent", () => () => ({
48
58
  trackOrder: vi.fn(),
49
59
  }));
@@ -61,9 +71,12 @@ vi.mock("@shopware/composables", async (importOriginal) => ({
61
71
 
62
72
  // Reports the time as DeliveryTimeSelect does once a time is selected.
63
73
  const DeliveryTimeSelectStub = defineComponent({
64
- emits: ["update:valid"],
74
+ emits: ["update:valid", "update:modelValue"],
65
75
  setup(_, { emit }) {
66
- onMounted(() => emit("update:valid", state.validTime));
76
+ onMounted(() => {
77
+ emit("update:modelValue", "19:15");
78
+ emit("update:valid", state.validTime);
79
+ });
67
80
  return () => h("div");
68
81
  },
69
82
  });
@@ -93,6 +106,9 @@ describe("Checkout Summary order button", () => {
93
106
  state.validTime = false;
94
107
  state.shippingBlocked = false;
95
108
  state.customer = true;
109
+ state.fulfillment = "delivery";
110
+ mocks.createOrder.mockReset();
111
+ mocks.checkCheckoutEnabled.mockReset();
96
112
  });
97
113
 
98
114
  it("shows a loading state while the opening hours are not loaded", async () => {
@@ -196,4 +212,27 @@ describe("Checkout Summary order button", () => {
196
212
  "konnte nicht geprüft werden",
197
213
  );
198
214
  });
215
+
216
+ // shopbite#6: the comment names the kind of time
217
+ it.each([
218
+ ["delivery", "Wunschlieferzeit: 19:15"],
219
+ ["pickup", "Wunschabholzeit: 19:15"],
220
+ ] as const)(
221
+ "stores the wished time of a %s order",
222
+ async (fulfillment, comment) => {
223
+ state.isLoading = false;
224
+ state.validTime = true;
225
+ state.fulfillment = fulfillment;
226
+ mocks.checkCheckoutEnabled.mockResolvedValue(true);
227
+ mocks.createOrder.mockResolvedValue({ id: "order-1" });
228
+
229
+ const button = await mountSummary();
230
+ await button.trigger("click");
231
+ await new Promise((resolve) => setTimeout(resolve, 0));
232
+
233
+ expect(mocks.createOrder).toHaveBeenCalledWith({
234
+ customerComment: comment,
235
+ });
236
+ },
237
+ );
199
238
  });
@@ -0,0 +1,181 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
+ import { mountSuspended, mockNuxtImport } from "@nuxt/test-utils/runtime";
3
+ import { nextTick, ref, type Ref } from "vue";
4
+ import DeliveryTimeSelect from "~/components/Checkout/DeliveryTimeSelect.vue";
5
+
6
+ // The time field follows the selected shipping method (shopbite#6):
7
+ // lead time and wording of delivery or pickup.
8
+ const { lead, hours } = vi.hoisted(() => ({
9
+ lead: {
10
+ fulfillment: "delivery" as "delivery" | "pickup",
11
+ leadTime: 45 as number | null,
12
+ // the refs of the mounted component, to switch the method
13
+ current: null as null | {
14
+ fulfillment: Ref<"delivery" | "pickup">;
15
+ leadTime: Ref<number | null>;
16
+ },
17
+ },
18
+ // "past": today's only interval has ended; "open": 11:00 to 22:00
19
+ hours: { mode: "past" as "past" | "open" },
20
+ }));
21
+
22
+ mockNuxtImport("useShippingLeadTime", () => () => {
23
+ lead.current = {
24
+ fulfillment: ref(lead.fulfillment),
25
+ leadTime: ref(lead.leadTime),
26
+ };
27
+ return lead.current;
28
+ });
29
+
30
+ mockNuxtImport("useOpeningHoursData", () => () => ({
31
+ isLoaded: ref(true),
32
+ hasFailed: ref(false),
33
+ retry: vi.fn(),
34
+ }));
35
+
36
+ mockNuxtImport("useHolidays", () => () => ({
37
+ isClosedHoliday: () => false,
38
+ }));
39
+
40
+ // "past": today's only interval ended an hour ago, no times are left.
41
+ mockNuxtImport("useBusinessHours", () => () => {
42
+ const interval = (date: Date) => {
43
+ if (hours.mode === "open") {
44
+ const start = new Date(date);
45
+ start.setHours(11, 0, 0, 0);
46
+ const end = new Date(date);
47
+ end.setHours(22, 0, 0, 0);
48
+ return { start, end };
49
+ }
50
+ const end = new Date(Date.now() - 60 * 60_000);
51
+ return { start: new Date(end.getTime() - 60 * 60_000), end };
52
+ };
53
+ const getEarliestSelectableTime = (now: Date, minutes: number | null) => {
54
+ const earliest = new Date(now.getTime() + (minutes ?? 30) * 60_000);
55
+ earliest.setSeconds(0, 0);
56
+ return earliest;
57
+ };
58
+ return {
59
+ businessHours: ref([
60
+ {
61
+ dayOfWeek: new Date().getDay(),
62
+ openingTime: "00:00",
63
+ closingTime: "00:01",
64
+ },
65
+ ]),
66
+ getServiceIntervals: (date: Date) => [interval(date)],
67
+ getEarliestSelectableTime,
68
+ findActiveInterval: (now: Date, minutes: number | null) => {
69
+ if (hours.mode === "past") return null;
70
+ const current = interval(now);
71
+ return getEarliestSelectableTime(now, minutes) <= current.end
72
+ ? current
73
+ : null;
74
+ },
75
+ };
76
+ });
77
+
78
+ async function mountSelect() {
79
+ return await mountSuspended(DeliveryTimeSelect);
80
+ }
81
+
82
+ describe("DeliveryTimeSelect wording per fulfillment", () => {
83
+ beforeEach(() => {
84
+ lead.fulfillment = "delivery";
85
+ lead.leadTime = 45;
86
+ hours.mode = "past";
87
+ });
88
+
89
+ it("asks for the delivery time with the delivery lead time", async () => {
90
+ const wrapper = await mountSelect();
91
+ const text = wrapper.text();
92
+
93
+ expect(wrapper.get("label").text()).toContain("Wunschlieferzeit");
94
+ expect(text).toContain("Lieferzeit ca. 45 Minuten");
95
+ expect(text).toContain("Heute sind keine Lieferzeiten mehr verfügbar.");
96
+ expect(text).not.toContain("Abhol");
97
+ });
98
+
99
+ it("asks for the pickup time with the pickup lead time", async () => {
100
+ lead.fulfillment = "pickup";
101
+ lead.leadTime = 20;
102
+
103
+ const wrapper = await mountSelect();
104
+ const text = wrapper.text();
105
+
106
+ expect(wrapper.get("label").text()).toContain("Wunschabholzeit");
107
+ expect(text).toContain("Abholbereit in ca. 20 Minuten");
108
+ expect(text).toContain("Heute sind keine Abholzeiten mehr verfügbar.");
109
+ expect(text).not.toContain("Lieferzeit");
110
+ });
111
+
112
+ it("leaves out the lead time hint while it is unknown", async () => {
113
+ lead.leadTime = null;
114
+
115
+ const wrapper = await mountSelect();
116
+
117
+ expect(wrapper.text()).not.toContain("ca.");
118
+ });
119
+ });
120
+
121
+ // Switching the shipping method moves the time to a valid 5-minute slot.
122
+ describe("DeliveryTimeSelect after a shipping method switch", () => {
123
+ beforeEach(() => {
124
+ vi.useFakeTimers({ toFake: ["Date"] });
125
+ vi.setSystemTime(new Date(2026, 10, 19, 16, 13, 20));
126
+ hours.mode = "open";
127
+ });
128
+
129
+ afterEach(() => {
130
+ vi.useRealTimers();
131
+ });
132
+
133
+ async function switchTo(fulfillment: "delivery" | "pickup", minutes: number) {
134
+ lead.current!.fulfillment.value = fulfillment;
135
+ lead.current!.leadTime.value = minutes;
136
+ await nextTick();
137
+ await nextTick();
138
+ }
139
+
140
+ function timeInput(wrapper: Awaited<ReturnType<typeof mountSelect>>) {
141
+ return wrapper.get<HTMLInputElement>('input[type="time"]');
142
+ }
143
+
144
+ it("moves a chosen pickup time to the next delivery slot", async () => {
145
+ lead.fulfillment = "pickup";
146
+ lead.leadTime = 15;
147
+ const wrapper = await mountSelect();
148
+ expect(timeInput(wrapper).element.value).toBe("16:30");
149
+ await timeInput(wrapper).setValue("16:30");
150
+
151
+ await switchTo("delivery", 30);
152
+
153
+ expect(timeInput(wrapper).element.value).toBe("16:45");
154
+ expect(wrapper.text()).not.toContain("5-Minuten-Schritten");
155
+ expect(wrapper.emitted("update:valid")!.at(-1)).toEqual([true]);
156
+ });
157
+
158
+ it("moves the prefilled delivery time to the earlier pickup slot", async () => {
159
+ lead.fulfillment = "delivery";
160
+ lead.leadTime = 30;
161
+ const wrapper = await mountSelect();
162
+ expect(timeInput(wrapper).element.value).toBe("16:45");
163
+
164
+ await switchTo("pickup", 15);
165
+
166
+ expect(timeInput(wrapper).element.value).toBe("16:30");
167
+ expect(wrapper.emitted("update:valid")!.at(-1)).toEqual([true]);
168
+ });
169
+
170
+ it("keeps a later time the guest chose", async () => {
171
+ lead.fulfillment = "delivery";
172
+ lead.leadTime = 30;
173
+ const wrapper = await mountSelect();
174
+ await timeInput(wrapper).setValue("18:00");
175
+
176
+ await switchTo("pickup", 15);
177
+ expect(timeInput(wrapper).element.value).toBe("18:00");
178
+ await switchTo("delivery", 30);
179
+ expect(timeInput(wrapper).element.value).toBe("18:00");
180
+ });
181
+ });
@@ -0,0 +1,78 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { mountSuspended, mockNuxtImport } from "@nuxt/test-utils/runtime";
3
+ import { ref } from "vue";
4
+ import Hero from "~/components/Home/Hero.vue";
5
+ import Facts from "~/components/Home/Facts.vue";
6
+
7
+ // The home page shows the lead times of the delivery and pickup methods
8
+ // (shopbite#6) and leaves out a time no shipping method has.
9
+ const { times } = vi.hoisted(() => ({
10
+ times: {
11
+ delivery: 45 as number | null,
12
+ pickup: 20 as number | null,
13
+ },
14
+ }));
15
+
16
+ mockNuxtImport("useShopBiteConfig", () => () => ({
17
+ deliveryTime: ref(times.delivery),
18
+ pickupTime: ref(times.pickup),
19
+ }));
20
+
21
+ mockNuxtImport("useStoreStatus", () => () => ({
22
+ status: ref({ open: true, closesAt: "22:00" }),
23
+ }));
24
+
25
+ mockNuxtImport("useBusinessHours", () => () => ({
26
+ businessHours: ref(null),
27
+ }));
28
+
29
+ const features = [
30
+ {
31
+ title: "Lieferung",
32
+ kind: "delivery" as const,
33
+ description: "Liefergebiet",
34
+ },
35
+ { title: "Abholung", kind: "pickup" as const, description: "Im Restaurant" },
36
+ ];
37
+
38
+ describe("lead times on the home page", () => {
39
+ beforeEach(() => {
40
+ times.delivery = 45;
41
+ times.pickup = 20;
42
+ });
43
+
44
+ it("shows delivery and pickup time in the hero", async () => {
45
+ const wrapper = await mountSuspended(Hero, { props: { title: "Pizza" } });
46
+ const text = wrapper.text();
47
+ expect(text).toContain("Lieferung ca. 45 Min");
48
+ expect(text).toContain("Abholung ca. 20 Min");
49
+ });
50
+
51
+ it("leaves out a time without a shipping method of that kind", async () => {
52
+ times.delivery = null;
53
+ const wrapper = await mountSuspended(Hero, { props: { title: "Pizza" } });
54
+ const text = wrapper.text();
55
+ expect(text).not.toContain("Lieferung ca.");
56
+ expect(text).toContain("Abholung ca. 20 Min");
57
+ });
58
+
59
+ it("fills the delivery and pickup facts", async () => {
60
+ const wrapper = await mountSuspended(Facts, { props: { features } });
61
+ const text = wrapper.text();
62
+ expect(text).toContain("In ca. 45 Minuten bei Ihnen");
63
+ expect(text).toContain("Abholbereit in ca. 20 Minuten");
64
+ });
65
+
66
+ it("keeps the content lead without a lead time", async () => {
67
+ times.delivery = null;
68
+ times.pickup = null;
69
+ const wrapper = await mountSuspended(Facts, {
70
+ props: {
71
+ features: [{ ...features[0]!, lead: "Frei Haus ab 15 €" }],
72
+ },
73
+ });
74
+ const text = wrapper.text();
75
+ expect(text).toContain("Frei Haus ab 15 €");
76
+ expect(text).not.toContain("Minuten");
77
+ });
78
+ });
@@ -66,6 +66,26 @@ describe("order pages with a preset (#445)", () => {
66
66
  });
67
67
  });
68
68
 
69
+ // shopbite#6: pickup orders store "Wunschabholzeit"
70
+ it("shows the wished pickup time", async () => {
71
+ mocks.loadOrderDetails.mockImplementation(async () => {
72
+ order.value = {
73
+ ...sampleOrder,
74
+ customerComment: "Wunschabholzeit: 18:40",
75
+ } as Schemas["Order"];
76
+ });
77
+ const wrapper = await mountSuspended(ConfirmationPreset, {
78
+ props: { orderId: "order-1", kind: "success" },
79
+ });
80
+ await flushPromises();
81
+
82
+ const facts = wrapper
83
+ .findAll("dl")[0]!
84
+ .findAll("div")
85
+ .map((row) => row.text());
86
+ expect(facts).toContain("Wunschzeit18:40");
87
+ });
88
+
69
89
  it("thanks the guest and shows the order after loading", async () => {
70
90
  mocks.loadOrderDetails.mockImplementation(async () => {
71
91
  order.value = sampleOrder;
@@ -4,6 +4,7 @@ import { mockNuxtImport } from "@nuxt/test-utils/runtime";
4
4
  import { useAddToCart } from "~/composables/useAddToCart";
5
5
  import type { Schemas } from "#shopware";
6
6
  import { nextTick } from "vue";
7
+ import { v5 as uuidv5 } from "uuid";
7
8
 
8
9
  // Use vi.hoisted for variables used in mocks
9
10
  const {
@@ -184,4 +185,88 @@ describe("useAddToCart", () => {
184
185
  }),
185
186
  ]);
186
187
  });
188
+ describe("line identity of configured dishes", () => {
189
+ const extra = { label: "Extra Cheese", value: "cheese", price: "" };
190
+
191
+ async function addConfigured(
192
+ without: string[],
193
+ extras: (typeof extra)[] = [],
194
+ ) {
195
+ const {
196
+ setSelectedProduct,
197
+ setSelectedExtras,
198
+ setDeselectedIngredients,
199
+ addToCart,
200
+ } = useAddToCart();
201
+ setSelectedProduct(mockProduct);
202
+ setSelectedExtras(extras);
203
+ setDeselectedIngredients(without);
204
+ mockAddProducts.mockResolvedValue({ id: "cart-123" });
205
+ await addToCart();
206
+ const items = mockAddProducts.mock.calls.at(-1)![0];
207
+ return items[0] as {
208
+ id: string;
209
+ type: string;
210
+ label: string;
211
+ payload: { productNumber: string; without: string[] };
212
+ };
213
+ }
214
+
215
+ it("keeps dishes that differ only in removed ingredients apart", async () => {
216
+ const withoutOnions = await addConfigured(["Zwiebeln"]);
217
+ const withoutOlives = await addConfigured(["Oliven"]);
218
+
219
+ expect(withoutOnions.type).toBe("container");
220
+ expect(withoutOlives.type).toBe("container");
221
+ expect(withoutOnions.id).not.toBe(withoutOlives.id);
222
+ expect(withoutOnions.label).toBe("Test Pizza -Zwiebeln");
223
+ expect(withoutOlives.label).toBe("Test Pizza -Oliven");
224
+ });
225
+
226
+ it("keeps dishes with the same extras but other removals apart", async () => {
227
+ const a = await addConfigured(["Zwiebeln"], [extra]);
228
+ const b = await addConfigured(["Oliven"], [extra]);
229
+ const c = await addConfigured([], [extra]);
230
+
231
+ expect(new Set([a.id, b.id, c.id]).size).toBe(3);
232
+ });
233
+
234
+ it("gives the same configuration the same id, so the cart adds up the quantity", async () => {
235
+ const first = await addConfigured(["Zwiebeln", "Oliven"], [extra]);
236
+ const second = await addConfigured(["Zwiebeln", "Oliven"], [extra]);
237
+
238
+ expect(first.id).toBe(second.id);
239
+ });
240
+
241
+ it("does not depend on the order or case of the removed ingredients", async () => {
242
+ const a = await addConfigured(["Zwiebeln", "Oliven"]);
243
+ const b = await addConfigured(["Oliven", "Zwiebeln"]);
244
+ const c = await addConfigured([" oliven", "ZWIEBELN "]);
245
+
246
+ expect(b.id).toBe(a.id);
247
+ expect(c.id).toBe(a.id);
248
+ });
249
+
250
+ it("keeps the id of dishes without removed ingredients", async () => {
251
+ const item = await addConfigured([], [extra]);
252
+
253
+ expect(item.id).toBe(
254
+ uuidv5("product-123cheese", "b098ef7e-0fa2-4073-b002-7ceec4360fbf"),
255
+ );
256
+ });
257
+
258
+ it("sends the removed ingredients as payload.without", async () => {
259
+ const removed = await addConfigured(["Zwiebeln", "Oliven"]);
260
+ const extrasOnly = await addConfigured([], [extra]);
261
+
262
+ expect(removed.payload).toEqual({
263
+ productNumber: "SW10123",
264
+ without: ["Zwiebeln", "Oliven"],
265
+ });
266
+ expect(extrasOnly.payload).toEqual({
267
+ productNumber: "SW10123",
268
+ without: [],
269
+ });
270
+ });
271
+ });
187
272
  });
@@ -3,9 +3,10 @@ import { mockNuxtImport } from "@nuxt/test-utils/runtime";
3
3
  import { ref } from "vue";
4
4
  import { useDeliveryTime } from "~/composables/useDeliveryTime";
5
5
 
6
- const { mockDeliveryTime, mockBusinessHours, mockHolidays } = vi.hoisted(
7
- () => ({
6
+ const { mockDeliveryTime, mockFulfillment, mockBusinessHours, mockHolidays } =
7
+ vi.hoisted(() => ({
8
8
  mockDeliveryTime: { value: 45 },
9
+ mockFulfillment: { value: "delivery" as "delivery" | "pickup" },
9
10
  mockBusinessHours: {
10
11
  value: [
11
12
  { dayOfWeek: 1, openingTime: "11:30", closingTime: "14:30" },
@@ -22,11 +23,11 @@ const { mockDeliveryTime, mockBusinessHours, mockHolidays } = vi.hoisted(
22
23
  ],
23
24
  },
24
25
  mockHolidays: { value: [] as { start: string; end: string }[] | null },
25
- }),
26
- );
26
+ }));
27
27
 
28
- mockNuxtImport("useShopBiteConfig", () => () => ({
29
- deliveryTime: mockDeliveryTime,
28
+ mockNuxtImport("useShippingLeadTime", () => () => ({
29
+ leadTime: mockDeliveryTime,
30
+ fulfillment: mockFulfillment,
30
31
  }));
31
32
 
32
33
  mockNuxtImport("useBusinessHours", () => () => ({
@@ -120,6 +121,29 @@ describe("useDeliveryTime", () => {
120
121
 
121
122
  beforeEach(() => {
122
123
  vi.clearAllMocks();
124
+ mockFulfillment.value = "delivery";
125
+ });
126
+
127
+ // shopbite#6: the lead time of the selected shipping method
128
+ it("uses the lead time of the selected shipping method", () => {
129
+ mockDeliveryTime.value = 20;
130
+ mockFulfillment.value = "pickup";
131
+ const { earliest } = useDeliveryTime(now);
132
+ expect(earliest.value.getHours()).toBe(12);
133
+ expect(earliest.value.getMinutes()).toBe(20);
134
+ });
135
+
136
+ it("speaks of pickup times for a pickup method", () => {
137
+ mockDeliveryTime.value = 30;
138
+ const late = ref(new Date("2023-10-27T22:45:00"));
139
+ mockFulfillment.value = "pickup";
140
+ expect(useDeliveryTime(late).helperText.value).toBe(
141
+ "Heute sind keine Abholzeiten mehr verfügbar.",
142
+ );
143
+ mockFulfillment.value = "delivery";
144
+ expect(useDeliveryTime(late).helperText.value).toBe(
145
+ "Heute sind keine Lieferzeiten mehr verfügbar.",
146
+ );
123
147
  });
124
148
 
125
149
  it("should calculate earliest selectable time", () => {
@@ -0,0 +1,66 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { mockNuxtImport } from "@nuxt/test-utils/runtime";
3
+ import { ref } from "vue";
4
+ import { useShippingLeadTime } from "~/composables/useShippingLeadTime";
5
+
6
+ // The checkout's time choice follows the selected shipping method
7
+ // (shopbite#6).
8
+ const DELIVERY = "0190a3b0c1d27e0f8a9b0c1d2e3f4a5b";
9
+ const PICKUP = "0190a3b0c1d27e0f8a9b0c1d2e3f4a5c";
10
+
11
+ const { mockInvoke, selected } = vi.hoisted(() => ({
12
+ mockInvoke: vi.fn(),
13
+ selected: {
14
+ current: null as null | { value: unknown },
15
+ },
16
+ }));
17
+
18
+ mockNuxtImport("useShopwareContext", () => () => ({
19
+ apiClient: { invoke: mockInvoke },
20
+ }));
21
+
22
+ mockNuxtImport("useCheckout", () => () => ({
23
+ selectedShippingMethod: selected.current,
24
+ }));
25
+
26
+ const configData = ref<unknown>(null);
27
+ mockNuxtImport(
28
+ "useAsyncData",
29
+ () => (_key: string, fetcher: () => Promise<unknown>) => ({
30
+ data: configData,
31
+ refresh: async () => {
32
+ configData.value = await fetcher();
33
+ },
34
+ }),
35
+ );
36
+
37
+ describe("useShippingLeadTime", () => {
38
+ beforeEach(() => {
39
+ configData.value = null;
40
+ selected.current = ref({ id: DELIVERY, name: "Lieferung" });
41
+ });
42
+
43
+ it("switches between delivery and pickup with the shipping method", async () => {
44
+ configData.value = {
45
+ isCheckoutEnabled: true,
46
+ shippingMethods: [
47
+ { id: DELIVERY, fulfillment: "delivery", leadTimeMinutes: 45 },
48
+ { id: PICKUP, fulfillment: "pickup", leadTimeMinutes: 20 },
49
+ ],
50
+ };
51
+
52
+ const { fulfillment, leadTime } = useShippingLeadTime();
53
+ expect(fulfillment.value).toBe("delivery");
54
+ expect(leadTime.value).toBe(45);
55
+
56
+ selected.current!.value = { id: PICKUP, name: "Abholung" };
57
+ expect(fulfillment.value).toBe("pickup");
58
+ expect(leadTime.value).toBe(20);
59
+ });
60
+
61
+ it("defaults to delivery without a lead time before the config is loaded", () => {
62
+ const { fulfillment, leadTime } = useShippingLeadTime();
63
+ expect(fulfillment.value).toBe("delivery");
64
+ expect(leadTime.value).toBeNull();
65
+ });
66
+ });