@shopbite-de/storefront 2.0.3 → 2.1.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,291 @@
1
+ import { ApiClientError } from "@shopware/api-client";
2
+
3
+ /**
4
+ * The wishlist with configured dishes (#467). An entry is a dish as it was
5
+ * configured in the product sheet: the product (variant), the deselected
6
+ * main ingredients and the extras, i.e. the quick view configuration of the
7
+ * URL (#411). The same dish can be saved twice with different
8
+ * configurations.
9
+ *
10
+ * Logged-in customers keep their entries in the ShopBite plugin
11
+ * (`/store-api/shopbite/wishlist`, entity `shopbite_wishlist_item`), guests
12
+ * in local storage; on login the guest entries move into the account. A
13
+ * backend without these routes (older plugin) answers 404, then the
14
+ * entries stay in the browser for customers too.
15
+ */
16
+ export type WishlistConfiguration = {
17
+ productId: string;
18
+ productNumber: string;
19
+ without: string[];
20
+ extras: string[];
21
+ };
22
+
23
+ export type WishlistEntry = WishlistConfiguration & {
24
+ id: string;
25
+ createdAt: string;
26
+ };
27
+
28
+ const STORAGE_KEY = "shopbite-wishlist";
29
+ // product ids of the wishlist before #467 (`useLocalWishlist` of the
30
+ // Shopware composables)
31
+ const LEGACY_STORAGE_KEY = "sw-wishlist-items";
32
+
33
+ /** Trimmed, unique and sorted, so two configurations can be compared. */
34
+ export function normalizeWishlistList(list: readonly string[] = []): string[] {
35
+ return [...new Set(list.map((entry) => entry.trim()).filter(Boolean))].sort();
36
+ }
37
+
38
+ export function isSameConfiguration(
39
+ a: Pick<WishlistConfiguration, "productId" | "without" | "extras">,
40
+ b: Pick<WishlistConfiguration, "productId" | "without" | "extras">,
41
+ ): boolean {
42
+ return (
43
+ a.productId === b.productId &&
44
+ normalizeWishlistList(a.without).join("\n") ===
45
+ normalizeWishlistList(b.without).join("\n") &&
46
+ normalizeWishlistList(a.extras).join("\n") ===
47
+ normalizeWishlistList(b.extras).join("\n")
48
+ );
49
+ }
50
+
51
+ function isWishlistEntry(value: unknown): value is WishlistEntry {
52
+ const entry = value as Partial<WishlistEntry> | null;
53
+ return (
54
+ !!entry &&
55
+ typeof entry.id === "string" &&
56
+ typeof entry.productId === "string" &&
57
+ Array.isArray(entry.without) &&
58
+ Array.isArray(entry.extras)
59
+ );
60
+ }
61
+
62
+ function readStorage(key: string): unknown {
63
+ try {
64
+ return JSON.parse(localStorage.getItem(key) ?? "null");
65
+ } catch {
66
+ return null;
67
+ }
68
+ }
69
+
70
+ function newLocalEntry(configuration: WishlistConfiguration): WishlistEntry {
71
+ return {
72
+ id: crypto.randomUUID().replaceAll("-", ""),
73
+ productId: configuration.productId,
74
+ productNumber: configuration.productNumber,
75
+ without: normalizeWishlistList(configuration.without),
76
+ extras: normalizeWishlistList(configuration.extras),
77
+ createdAt: new Date().toISOString(),
78
+ };
79
+ }
80
+
81
+ /** Guest entries, including the plain product ids saved before #467. */
82
+ function readLocalEntries(): WishlistEntry[] {
83
+ const stored = readStorage(STORAGE_KEY);
84
+ const entries = Array.isArray(stored) ? stored.filter(isWishlistEntry) : [];
85
+ const legacy = readStorage(LEGACY_STORAGE_KEY);
86
+ if (Array.isArray(legacy)) {
87
+ for (const productId of legacy) {
88
+ if (typeof productId !== "string") continue;
89
+ const plain = { productId, productNumber: "", without: [], extras: [] };
90
+ if (!entries.some((entry) => isSameConfiguration(entry, plain))) {
91
+ entries.push(newLocalEntry(plain));
92
+ }
93
+ }
94
+ }
95
+ return entries;
96
+ }
97
+
98
+ function writeLocalEntries(entries: WishlistEntry[]) {
99
+ try {
100
+ localStorage.setItem(STORAGE_KEY, JSON.stringify(entries));
101
+ localStorage.removeItem(LEGACY_STORAGE_KEY);
102
+ } catch {
103
+ // private mode or blocked storage: the list lives for this visit only
104
+ }
105
+ }
106
+
107
+ function clearLocalEntries() {
108
+ try {
109
+ localStorage.removeItem(STORAGE_KEY);
110
+ localStorage.removeItem(LEGACY_STORAGE_KEY);
111
+ } catch {
112
+ // nothing stored
113
+ }
114
+ }
115
+
116
+ function isMissingRoute(error: unknown) {
117
+ return error instanceof ApiClientError && error.status === 404;
118
+ }
119
+
120
+ export function useWishlistEntries() {
121
+ const { apiClient } = useShopwareContext();
122
+ const { isLoggedIn } = useUser();
123
+
124
+ const entries = useState<WishlistEntry[]>(
125
+ "shopbite-wishlist-entries",
126
+ () => [],
127
+ );
128
+ const loaded = useState("shopbite-wishlist-loaded", () => false);
129
+ // the backend has no wishlist routes (plugin older than #467)
130
+ const routesMissing = useState(
131
+ "shopbite-wishlist-routes-missing",
132
+ () => false,
133
+ );
134
+ const coreMigrated = useState("shopbite-wishlist-core-migrated", () => false);
135
+
136
+ const remote = computed(() => isLoggedIn.value && !routesMissing.value);
137
+ const count = computed(() => entries.value.length);
138
+
139
+ /**
140
+ * The Shopware wishlist of a customer from before #467 holds plain product
141
+ * ids: they become entries without configuration and are removed there,
142
+ * so they do not come back after the customer deleted them.
143
+ */
144
+ async function migrateCoreWishlist() {
145
+ if (coreMigrated.value) return;
146
+ coreMigrated.value = true;
147
+ try {
148
+ const { data } = await apiClient.invoke(
149
+ "readCustomerWishlist post /customer/wishlist",
150
+ { body: { limit: 100 } },
151
+ );
152
+ const productIds = data.products.elements.map((product) => product.id);
153
+ if (!productIds.length) return;
154
+ const merged = await apiClient.invoke(
155
+ "shopbite.wishlist.merge post /shopbite/wishlist/merge",
156
+ { body: { items: productIds.map((productId) => ({ productId })) } },
157
+ );
158
+ entries.value = merged.data.elements;
159
+ await Promise.all(
160
+ productIds.map((productId) =>
161
+ apiClient.invoke(
162
+ "deleteProductOnWishlist delete /customer/wishlist/delete/{productId}",
163
+ { pathParams: { productId } },
164
+ ),
165
+ ),
166
+ );
167
+ } catch {
168
+ // no Shopware wishlist (404) or the wishlist is disabled (403)
169
+ }
170
+ }
171
+
172
+ async function load() {
173
+ if (!import.meta.client) return;
174
+ if (remote.value) {
175
+ try {
176
+ const { data } = await apiClient.invoke(
177
+ "shopbite.wishlist.list post /shopbite/wishlist",
178
+ {},
179
+ );
180
+ entries.value = data.elements;
181
+ loaded.value = true;
182
+ await migrateCoreWishlist();
183
+ return;
184
+ } catch (error) {
185
+ if (!isMissingRoute(error)) {
186
+ console.error("[wishlist][load]", error);
187
+ return;
188
+ }
189
+ routesMissing.value = true;
190
+ }
191
+ }
192
+ entries.value = readLocalEntries();
193
+ loaded.value = true;
194
+ }
195
+
196
+ /** Moves the guest entries into the account, right after the login. */
197
+ async function mergeGuestEntries() {
198
+ if (!import.meta.client || !remote.value) return load();
199
+ const local = readLocalEntries();
200
+ if (!local.length) return load();
201
+ try {
202
+ const { data } = await apiClient.invoke(
203
+ "shopbite.wishlist.merge post /shopbite/wishlist/merge",
204
+ {
205
+ body: {
206
+ items: local.map(({ productId, without, extras }) => ({
207
+ productId,
208
+ without,
209
+ extras,
210
+ })),
211
+ },
212
+ },
213
+ );
214
+ entries.value = data.elements;
215
+ loaded.value = true;
216
+ clearLocalEntries();
217
+ await migrateCoreWishlist();
218
+ } catch (error) {
219
+ if (isMissingRoute(error)) routesMissing.value = true;
220
+ else console.error("[wishlist][mergeGuestEntries]", error);
221
+ await load();
222
+ }
223
+ }
224
+
225
+ function find(configuration: Omit<WishlistConfiguration, "productNumber">) {
226
+ return entries.value.find((entry) =>
227
+ isSameConfiguration(entry, configuration),
228
+ );
229
+ }
230
+
231
+ async function add(configuration: WishlistConfiguration) {
232
+ if (find(configuration)) return;
233
+ if (remote.value) {
234
+ const { data } = await apiClient.invoke(
235
+ "shopbite.wishlist.add post /shopbite/wishlist/add",
236
+ {
237
+ body: {
238
+ productId: configuration.productId,
239
+ without: configuration.without,
240
+ extras: configuration.extras,
241
+ },
242
+ },
243
+ );
244
+ if (!entries.value.some((entry) => entry.id === data.id)) {
245
+ entries.value = [data, ...entries.value];
246
+ }
247
+ return;
248
+ }
249
+ entries.value = [newLocalEntry(configuration), ...entries.value];
250
+ writeLocalEntries(entries.value);
251
+ }
252
+
253
+ async function remove(id: string) {
254
+ if (remote.value) {
255
+ await apiClient.invoke(
256
+ "shopbite.wishlist.delete delete /shopbite/wishlist/{id}",
257
+ { pathParams: { id } },
258
+ );
259
+ }
260
+ entries.value = entries.value.filter((entry) => entry.id !== id);
261
+ if (!remote.value) writeLocalEntries(entries.value);
262
+ }
263
+
264
+ async function clear() {
265
+ if (remote.value) {
266
+ await Promise.all(
267
+ entries.value.map((entry) =>
268
+ apiClient.invoke(
269
+ "shopbite.wishlist.delete delete /shopbite/wishlist/{id}",
270
+ { pathParams: { id: entry.id } },
271
+ ),
272
+ ),
273
+ );
274
+ } else {
275
+ clearLocalEntries();
276
+ }
277
+ entries.value = [];
278
+ }
279
+
280
+ return {
281
+ entries,
282
+ count,
283
+ loaded,
284
+ load,
285
+ mergeGuestEntries,
286
+ find,
287
+ add,
288
+ remove,
289
+ clear,
290
+ };
291
+ }
@@ -1,12 +1,9 @@
1
1
  <script setup lang="ts">
2
- import { useWishlist } from "@shopware/composables";
3
-
4
2
  useSeoMeta({
5
3
  title: "Anmelden",
6
4
  });
7
5
 
8
6
  const { isLoggedIn } = useUser();
9
- const { mergeWishlistProducts } = useWishlist();
10
7
 
11
8
  onBeforeMount(async () => {
12
9
  if (import.meta.client && isLoggedIn.value) {
@@ -20,8 +17,8 @@ watch(isLoggedIn, (newValue) => {
20
17
  }
21
18
  });
22
19
 
20
+ // app.vue moves the guest's wishlist into the account (#467).
23
21
  function handleLoginSuccess() {
24
- mergeWishlistProducts();
25
22
  navigateTo("/");
26
23
  }
27
24
  </script>
@@ -10,7 +10,6 @@ const route = useRoute();
10
10
  const { apiClient } = useShopwareContext();
11
11
  const { refreshSessionContext } = useSessionContext();
12
12
  const { refreshCart } = useCart();
13
- const { mergeWishlistProducts } = useWishlist();
14
13
 
15
14
  type ConfirmError = "invalid" | "already-confirmed";
16
15
 
@@ -61,7 +60,6 @@ async function confirmRegistration() {
61
60
  // context token, so load the new session before opening the account.
62
61
  await refreshSessionContext();
63
62
  refreshCart();
64
- mergeWishlistProducts();
65
63
  await navigateTo({ path: "/konto" });
66
64
  }
67
65
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopbite-de/storefront",
3
- "version": "2.0.3",
3
+ "version": "2.1.1",
4
4
  "main": "nuxt.config.ts",
5
5
  "description": "Shopware storefront for food delivery shops",
6
6
  "keywords": [
@@ -0,0 +1,90 @@
1
+ import { describe, it, expect, vi } from "vitest";
2
+ import { mountSuspended } from "@nuxt/test-utils/runtime";
3
+ import type { VueWrapper } from "@vue/test-utils";
4
+ import { ref } from "vue";
5
+ import MobileTop from "~/components/Navigation/MobileTop.vue";
6
+
7
+ // La Fattoria's menu: Fleischgerichte has sub-categories, Pizza has none.
8
+ vi.mock("~/composables/useNavigation", () => ({
9
+ useNavigation: () => ({
10
+ menuCardNavigation: ref([
11
+ { id: "pizza", name: "Pizza", seoUrl: "/speisekarte/pizza/" },
12
+ {
13
+ id: "fleisch",
14
+ name: "Fleischgerichte",
15
+ seoUrl: "/speisekarte/fleischgerichte/",
16
+ children: [
17
+ {
18
+ id: "rind",
19
+ name: "Vom Rind",
20
+ seoUrl: "/speisekarte/fleischgerichte/vom-rind/",
21
+ },
22
+ {
23
+ id: "kalb",
24
+ name: "Vom Kalb",
25
+ seoUrl: "/speisekarte/fleischgerichte/vom-kalb/",
26
+ },
27
+ ],
28
+ },
29
+ ]),
30
+ }),
31
+ }));
32
+
33
+ type Row = {
34
+ label: string | undefined;
35
+ links: { text: string; current: string | undefined }[];
36
+ };
37
+
38
+ function chips(wrapper: VueWrapper): Row[] {
39
+ return wrapper.findAll("ul").map((list) => ({
40
+ label: list.attributes("aria-label"),
41
+ links: list.findAll("a").map((link) => ({
42
+ text: link.text(),
43
+ current: link.attributes("aria-current"),
44
+ })),
45
+ }));
46
+ }
47
+
48
+ describe("NavigationMobileTop", () => {
49
+ it("shows only the sections on a section without sub-categories", async () => {
50
+ const wrapper = await mountSuspended(MobileTop, {
51
+ route: "/speisekarte/pizza/",
52
+ });
53
+
54
+ const rows = chips(wrapper);
55
+ expect(rows).toHaveLength(1);
56
+ expect(rows[0]!.links).toEqual([
57
+ { text: "Pizza", current: "page" },
58
+ { text: "Fleischgerichte", current: undefined },
59
+ ]);
60
+ });
61
+
62
+ it("lists the sub-categories of the open section in a second row", async () => {
63
+ const wrapper = await mountSuspended(MobileTop, {
64
+ route: "/speisekarte/fleischgerichte/",
65
+ });
66
+
67
+ const rows = chips(wrapper);
68
+ expect(rows[1]!.label).toBe("Unterkategorien von Fleischgerichte");
69
+ expect(rows[1]!.links).toEqual([
70
+ { text: "Alle", current: "page" },
71
+ { text: "Vom Rind", current: undefined },
72
+ { text: "Vom Kalb", current: undefined },
73
+ ]);
74
+ });
75
+
76
+ it("keeps the section and its row open on a sub-category", async () => {
77
+ const wrapper = await mountSuspended(MobileTop, {
78
+ route: "/speisekarte/fleischgerichte/vom-kalb/",
79
+ });
80
+
81
+ const rows = chips(wrapper);
82
+ const section = wrapper.find("[data-section]");
83
+ expect(section.text()).toBe("Fleischgerichte");
84
+ expect(section.classes()).toContain("bg-sb-ink");
85
+ expect(rows[1]!.links.find((link) => link.current)).toEqual({
86
+ text: "Vom Kalb",
87
+ current: "page",
88
+ });
89
+ });
90
+ });
@@ -33,11 +33,6 @@ mockNuxtImport("useSessionContext", () => () => ({
33
33
  const refreshCartMock = vi.fn();
34
34
  mockNuxtImport("useCart", () => () => ({ refreshCart: refreshCartMock }));
35
35
 
36
- const mergeWishlistProductsMock = vi.fn();
37
- mockNuxtImport("useWishlist", () => () => ({
38
- mergeWishlistProducts: mergeWishlistProductsMock,
39
- }));
40
-
41
36
  const { navigateToMock } = vi.hoisted(() => ({ navigateToMock: vi.fn() }));
42
37
  mockNuxtImport("navigateTo", () => navigateToMock);
43
38
 
@@ -64,7 +59,7 @@ describe("registrierung/bestaetigen", () => {
64
59
  );
65
60
  expect(refreshSessionContextMock).toHaveBeenCalled();
66
61
  expect(refreshCartMock).toHaveBeenCalled();
67
- expect(mergeWishlistProductsMock).toHaveBeenCalled();
62
+ // the wishlist moves into the account in app.vue (login watch, #467)
68
63
  expect(navigateToMock).toHaveBeenCalledWith({ path: "/konto" });
69
64
  });
70
65
 
@@ -0,0 +1,44 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { mountSuspended } from "@nuxt/test-utils/runtime";
3
+ import { defineComponent, h } from "vue";
4
+ import { DialogTitle } from "reka-ui";
5
+ import SbSheet from "~/components/Sb/Sheet.vue";
6
+
7
+ // A custom header (product sheet) gets its own row below the actions, so
8
+ // a long dish name is not squeezed next to three 44 px buttons.
9
+ describe("SbSheet header", () => {
10
+ it("puts the actions and close into a toolbar above a custom header", async () => {
11
+ const Host = defineComponent(
12
+ () => () =>
13
+ h(
14
+ SbSheet,
15
+ { open: true, title: "Hähnchenbrustfilet Paniert m. Kroketten" },
16
+ {
17
+ header: () =>
18
+ h(DialogTitle, { "data-test": "title" }, () => "Titel"),
19
+ actions: () => h("button", { "data-test": "save" }, "Merken"),
20
+ default: () => h("p", "Inhalt"),
21
+ },
22
+ ),
23
+ );
24
+ await mountSuspended(Host);
25
+
26
+ const header = document.body.querySelector("header")!;
27
+ const [toolbar, content] = [...header.children];
28
+ expect(toolbar!.querySelector('[data-test="save"]')).not.toBeNull();
29
+ expect(toolbar!.querySelector('[aria-label="Schließen"]')).not.toBeNull();
30
+ expect(content!.querySelector('[data-test="title"]')).not.toBeNull();
31
+ });
32
+
33
+ it("keeps title and close in one row without a custom header", async () => {
34
+ const Host = defineComponent(
35
+ () => () =>
36
+ h(SbSheet, { open: true, title: "Warenkorb" }, () => h("p", "Inhalt")),
37
+ );
38
+ await mountSuspended(Host);
39
+
40
+ const header = [...document.body.querySelectorAll("header")].at(-1)!;
41
+ expect(header.className).toContain("items-start");
42
+ expect(header.textContent).toContain("Warenkorb");
43
+ });
44
+ });
@@ -0,0 +1,107 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { mountSuspended, mockNuxtImport } from "@nuxt/test-utils/runtime";
3
+ import { flushPromises } from "@vue/test-utils";
4
+ import { ref } from "vue";
5
+ import Wishlist from "~/components/Wishlist.vue";
6
+
7
+ const { invoke, addLineItems } = vi.hoisted(() => ({
8
+ invoke: vi.fn(),
9
+ addLineItems: vi.fn(),
10
+ }));
11
+ mockNuxtImport("useShopwareContext", () => () => ({
12
+ apiClient: { invoke },
13
+ }));
14
+ mockNuxtImport("useUser", () => () => ({ isLoggedIn: ref(false) }));
15
+ mockNuxtImport("useCartMutations", () => () => ({
16
+ addLineItems,
17
+ isMutating: ref(false),
18
+ }));
19
+
20
+ const pizza = {
21
+ id: "p1",
22
+ productNumber: "21",
23
+ name: "Pizza Mix",
24
+ translated: { name: "Pizza Mix" },
25
+ calculatedPrice: { unitPrice: 8.5 },
26
+ childCount: 0,
27
+ };
28
+ const salami = {
29
+ id: "x1",
30
+ productNumber: "X1",
31
+ name: "Extra Salami",
32
+ translated: { name: "Extra Salami" },
33
+ calculatedPrice: { unitPrice: 1.5 },
34
+ };
35
+
36
+ describe("wishlist page (#467)", () => {
37
+ beforeEach(async () => {
38
+ vi.clearAllMocks();
39
+ localStorage.clear();
40
+ invoke.mockImplementation(
41
+ async (_operation: string, options: { body: { ids?: string[] } }) => ({
42
+ data: { elements: options.body.ids ? [pizza] : [salami] },
43
+ }),
44
+ );
45
+ addLineItems.mockResolvedValue({ id: "cart" });
46
+ const wishlist = useWishlistEntries();
47
+ wishlist.entries.value = [];
48
+ await wishlist.add({
49
+ productId: "p1",
50
+ productNumber: "21",
51
+ without: ["Pilze"],
52
+ extras: ["X1"],
53
+ });
54
+ wishlist.loaded.value = true;
55
+ });
56
+
57
+ it("names the dish with its configuration and today's price", async () => {
58
+ const wrapper = await mountSuspended(Wishlist);
59
+ await flushPromises();
60
+
61
+ const row = wrapper.get("li");
62
+ expect(row.attributes("aria-label")).toBe(
63
+ "Pizza Mix (+Extra Salami, ohne Pilze)",
64
+ );
65
+ expect(row.text()).toContain("+Extra Salami, ohne Pilze");
66
+ expect(row.text()).toMatch(/10,00\s?€/);
67
+ });
68
+
69
+ it("adds the same container line item as the product sheet", async () => {
70
+ const wrapper = await mountSuspended(Wishlist);
71
+ await flushPromises();
72
+
73
+ const add = wrapper
74
+ .findAll("button")
75
+ .find((button) => button.text().startsWith("In den Warenkorb"))!;
76
+ await add.trigger("click");
77
+ await flushPromises();
78
+
79
+ const [items] = addLineItems.mock.calls[0]!;
80
+ expect(items).toHaveLength(1);
81
+ expect(items[0]).toMatchObject({
82
+ type: "container",
83
+ quantity: 1,
84
+ label: "Pizza Mix +Extra Salami -Pilze",
85
+ payload: { productNumber: "21" },
86
+ });
87
+ expect(items[0].children).toEqual(
88
+ expect.arrayContaining([
89
+ expect.objectContaining({ referencedId: "p1", type: "product" }),
90
+ expect.objectContaining({ id: "x1", type: "product" }),
91
+ ]),
92
+ );
93
+ });
94
+
95
+ it("opens the product sheet with the saved configuration", async () => {
96
+ const wrapper = await mountSuspended(Wishlist);
97
+ await flushPromises();
98
+
99
+ const customize = wrapper
100
+ .findAll("a")
101
+ .find((link) => link.text().startsWith("Anpassen"))!;
102
+ const href = new URL(customize.attributes("href")!, "http://shop");
103
+ expect(href.searchParams.get("produkt")).toBe("21");
104
+ expect(href.searchParams.get("ohne")).toBe("Pilze");
105
+ expect(href.searchParams.get("extras")).toBe("X1");
106
+ });
107
+ });
@@ -0,0 +1,67 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { mountSuspended, mockNuxtImport } from "@nuxt/test-utils/runtime";
3
+ import { flushPromises } from "@vue/test-utils";
4
+ import { ref } from "vue";
5
+ import WishlistSaveButton from "~/components/WishlistSaveButton.vue";
6
+
7
+ const { invoke } = vi.hoisted(() => ({ invoke: vi.fn() }));
8
+ mockNuxtImport("useShopwareContext", () => () => ({
9
+ apiClient: { invoke },
10
+ }));
11
+ mockNuxtImport("useUser", () => () => ({ isLoggedIn: ref(false) }));
12
+
13
+ const selection = {
14
+ productId: "p1",
15
+ productNumber: "21",
16
+ without: ["Pilze"],
17
+ extras: ["X1"],
18
+ };
19
+
20
+ describe("WishlistSaveButton (#467)", () => {
21
+ beforeEach(() => {
22
+ localStorage.clear();
23
+ useWishlistEntries().entries.value = [];
24
+ });
25
+
26
+ it("saves the configuration and shows it as pressed", async () => {
27
+ const wrapper = await mountSuspended(WishlistSaveButton, {
28
+ props: { selection, name: "Pizza Mix" },
29
+ });
30
+ const button = wrapper.get("button");
31
+ expect(button.attributes("aria-label")).toBe("Pizza Mix merken");
32
+ expect(button.attributes("aria-pressed")).toBe("false");
33
+
34
+ await button.trigger("click");
35
+ await flushPromises();
36
+
37
+ expect(button.attributes("aria-pressed")).toBe("true");
38
+ expect(useWishlistEntries().entries.value).toMatchObject([
39
+ { productId: "p1", without: ["Pilze"], extras: ["X1"] },
40
+ ]);
41
+ });
42
+
43
+ it("is not pressed for another configuration of the same dish", async () => {
44
+ await useWishlistEntries().add(selection);
45
+ const wrapper = await mountSuspended(WishlistSaveButton, {
46
+ props: { selection: { ...selection, extras: [] }, name: "Pizza Mix" },
47
+ });
48
+
49
+ expect(wrapper.get("button").attributes("aria-pressed")).toBe("false");
50
+
51
+ await wrapper.setProps({ selection });
52
+ expect(wrapper.get("button").attributes("aria-pressed")).toBe("true");
53
+ });
54
+
55
+ it("removes the saved configuration on a second click", async () => {
56
+ await useWishlistEntries().add(selection);
57
+ const wrapper = await mountSuspended(WishlistSaveButton, {
58
+ props: { selection, name: "Pizza Mix" },
59
+ });
60
+
61
+ await wrapper.get("button").trigger("click");
62
+ await flushPromises();
63
+
64
+ expect(wrapper.get("button").attributes("aria-pressed")).toBe("false");
65
+ expect(useWishlistEntries().entries.value).toEqual([]);
66
+ });
67
+ });