@shopware/composables 1.12.1 → 1.14.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.
@@ -54,4 +54,23 @@ describe("useNotifications", () => {
54
54
  vm.pushSuccess("test");
55
55
  expect(vm.notifications.length).toBe(1);
56
56
  });
57
+
58
+ it("stores an optional action and keeps actionable toasts longer", () => {
59
+ const { vm } = useSetup(useNotifications);
60
+
61
+ vm.pushSuccess("Wooden Chair has been added to cart.", {
62
+ action: { label: "View cart", to: "/checkout/cart" },
63
+ });
64
+
65
+ expect(vm.notifications[0]?.action).toEqual({
66
+ label: "View cart",
67
+ to: "/checkout/cart",
68
+ });
69
+
70
+ vi.advanceTimersByTime(2500);
71
+ expect(vm.notifications.length).toBe(1);
72
+
73
+ vi.advanceTimersByTime(2500);
74
+ expect(vm.notifications.length).toBe(0);
75
+ });
57
76
  });
@@ -3,6 +3,16 @@ import type { ComputedRef, Ref } from "vue";
3
3
 
4
4
  type NotificationType = "info" | "warning" | "success" | "danger";
5
5
 
6
+ /**
7
+ * Optional CTA rendered next to a notification message (e.g. "View cart").
8
+ *
9
+ * @private
10
+ */
11
+ export type NotificationAction = {
12
+ label: string;
13
+ to: string;
14
+ };
15
+
6
16
  /**
7
17
  * @private
8
18
  */
@@ -10,6 +20,7 @@ export type Notification = {
10
20
  type: NotificationType;
11
21
  message: string;
12
22
  id: number;
23
+ action?: NotificationAction;
13
24
  };
14
25
 
15
26
  /**
@@ -22,6 +33,7 @@ export type NotificationOptions = {
22
33
  type?: NotificationType;
23
34
  timeout?: number;
24
35
  persistent?: boolean;
36
+ action?: NotificationAction;
25
37
  };
26
38
 
27
39
  /**
@@ -86,7 +98,7 @@ export function useNotifications(): UseNotificationsReturn {
86
98
  message: string,
87
99
  options: Required<Pick<NotificationOptions, "type">> & NotificationOptions,
88
100
  ) {
89
- const timeout = options.timeout || 2500;
101
+ const timeout = options.timeout || (options.action ? 5000 : 2500);
90
102
  const persistent = !!options.persistent;
91
103
  _notifications.value = _notifications.value || [];
92
104
 
@@ -95,6 +107,7 @@ export function useNotifications(): UseNotificationsReturn {
95
107
  id: messageId,
96
108
  type: options.type,
97
109
  message,
110
+ ...(options.action ? { action: options.action } : {}),
98
111
  });
99
112
  if (!persistent) {
100
113
  setTimeout(() => {
@@ -9,7 +9,7 @@ import { cmsAssociations } from "../cms/cmsAssociations";
9
9
  type UseProductSearchReturnOptions = {
10
10
  withCmsAssociations?: boolean;
11
11
  criteria?: Partial<Schemas["Criteria"]>;
12
- associations?: Partial<Schemas["Association"]>;
12
+ associations?: Partial<Schemas["Associations"]>;
13
13
  };
14
14
 
15
15
  export type UseProductSearchReturn = {
@@ -92,6 +92,30 @@ describe("useUser", () => {
92
92
  }),
93
93
  );
94
94
  expect(result).toEqual(registeredCustomer);
95
+ expect(refreshSessionContextSpy).toHaveBeenCalled();
96
+ expect(refreshCartSpy).toHaveBeenCalled();
97
+ });
98
+
99
+ it("register does not resolve before the cart refresh completes", async () => {
100
+ const { vm, injections } = useSetup(() => useUser());
101
+ injections.apiClient.invoke.mockResolvedValue({
102
+ data: { id: "reg-2", email: "test@test.testwwww" },
103
+ });
104
+
105
+ let cartRefreshCompleted = false;
106
+ refreshCartSpy.mockImplementationOnce(
107
+ () =>
108
+ new Promise((resolve) =>
109
+ setTimeout(() => {
110
+ cartRefreshCompleted = true;
111
+ resolve(undefined);
112
+ }, 0),
113
+ ),
114
+ );
115
+
116
+ await vm.register(REGISTRATION_DATA);
117
+
118
+ expect(cartRefreshCompleted).toBe(true);
95
119
  });
96
120
 
97
121
  it("register function with refresh", async () => {
@@ -193,6 +193,8 @@ export function useUser(): UseUserReturn {
193
193
  _user.value = data;
194
194
  }
195
195
  await refreshSessionContext();
196
+
197
+ await refreshCart();
196
198
  return data;
197
199
  }
198
200