@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.
- package/README.md +40 -12
- package/dist/index.d.mts +130 -20
- package/dist/index.d.ts +130 -20
- package/dist/index.mjs +95 -30
- package/package.json +11 -10
- package/src/cms/useCmsElementConfig.test.ts +38 -0
- package/src/cms/useCmsElementConfig.ts +13 -12
- package/src/cms/useCmsElementImage.test.ts +139 -0
- package/src/cms/useCmsElementImage.ts +19 -1
- package/src/index.test.ts +19 -1
- package/src/index.ts +9 -4
- package/src/types/cmsBlockTypes.ts +12 -0
- package/src/types/cmsElementTypes.ts +58 -2
- package/src/useAddToCart/useAddToCart.test.ts +17 -17
- package/src/useB2bQuoteManagement/useB2bQuoteManagement.test.ts +61 -1
- package/src/useB2bQuoteManagement/useB2bQuoteManagement.ts +121 -14
- package/src/useCategorySearch/useCategorySearch.test.ts +2 -2
- package/src/useCategorySearch/useCategorySearch.ts +3 -1
- package/src/useCmsBlock/useCmsBlock.test.ts +47 -13
- package/src/useCmsBlock/useCmsBlock.ts +17 -7
- package/src/useCmsSection/useCmsSection.test.ts +48 -5
- package/src/useCmsSection/useCmsSection.ts +11 -5
- package/src/useInternationalization/useInternationalization.test.ts +154 -0
- package/src/useInternationalization/useInternationalization.ts +21 -2
- package/src/useListing/useListing.ts +3 -1
- package/src/useNotifications/useNotifications.test.ts +19 -0
- package/src/useNotifications/useNotifications.ts +14 -1
- package/src/useProductSearch/useProductSearch.ts +1 -1
- package/src/useUser/useUser.test.ts +24 -0
- package/src/useUser/useUser.ts +2 -0
|
@@ -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["
|
|
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 () => {
|