@shopware/composables 1.9.1 → 1.11.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 +12 -5
- package/dist/index.d.mts +116 -34
- package/dist/index.d.ts +116 -34
- package/dist/index.mjs +117 -74
- package/package.json +13 -12
- package/src/cms/cmsAssociations.ts +5 -1
- package/src/cms/useCmsElementConfig.test.ts +8 -0
- package/src/cms/useCmsElementConfig.ts +4 -1
- package/src/cms/useCmsElementImage.test.ts +23 -0
- package/src/cms/useCmsElementProductBox.test.ts +21 -0
- package/src/devtools/plugin.ts +1 -2
- package/src/mocks/Configurator.ts +36 -36
- package/src/types/cmsBlockTypes.ts +2 -0
- package/src/types/cmsElementTypes.ts +24 -18
- package/src/useAddToCart/useAddToCart.test.ts +18 -1
- package/src/useAddress/useAddress.test.ts +41 -2
- package/src/useAddress/useAddress.ts +1 -1
- package/src/useCart/useCart.test.ts +42 -0
- package/src/useCart/useCart.ts +17 -0
- package/src/useCartNotification/useCartNotification.test.ts +30 -0
- package/src/useCheckout/useCheckout.test.ts +43 -1
- package/src/useCmsMeta/useCmsMeta.test.ts +26 -0
- package/src/useCountries/useCountries.test.ts +14 -0
- package/src/useCustomerOrders/useCustomerOrders.ts +1 -1
- package/src/useDefaultOrderAssociations/useDefaultOrderAssociations.test.ts +19 -21
- package/src/useDefaultOrderAssociations/useDefaultOrderAssociations.ts +23 -30
- package/src/useLandingSearch/useLandingSearch.test.ts +1 -1
- package/src/useLandingSearch/useLandingSearch.ts +1 -1
- package/src/useListing/useListing.test.ts +73 -0
- package/src/useListing/useListing.ts +10 -3
- package/src/useLocalWishlist/useLocalWishlist.test.ts +44 -5
- package/src/useLocalWishlist/useLocalWishlist.ts +3 -2
- package/src/useNavigationContext/useNavigationContext.test.ts +25 -24
- package/src/useNewsletter/useNewsletter.test.ts +16 -0
- package/src/useNewsletter/useNewsletter.ts +13 -0
- package/src/useOrderDetails/useOrderDetails.test.ts +92 -3
- package/src/useOrderDetails/useOrderDetails.ts +12 -14
- package/src/useOrderPayment/useOrderPayment.test.ts +55 -1
- package/src/useOrderPayment/useOrderPayment.ts +1 -0
- package/src/usePrice/usePrice.test.ts +10 -0
- package/src/usePrice/usePrice.ts +2 -7
- package/src/useProduct/useProduct.test.ts +14 -1
- package/src/useProductAssociations/useProductAssociations.spec.ts +1 -0
- package/src/useProductConfigurator/useProductConfigurator.spec.ts +38 -0
- package/src/useProductConfigurator/useProductConfigurator.ts +1 -1
- package/src/useProductPrice/useProductPrice.test.ts +7 -7
- package/src/useProductPrice/useProductPrice.ts +12 -4
- package/src/useProductReviews/useProductReviews.test.ts +15 -3
- package/src/useProductWishlist/useProductWishlist.ts +2 -2
- package/src/useSalutations/useSalutations.spec.ts +13 -0
- package/src/useSessionContext/useSessionContext.test.ts +122 -4
- package/src/useSessionContext/useSessionContext.ts +14 -2
- package/src/useSyncWishlist/useSyncWishlist.test.ts +94 -25
- package/src/useSyncWishlist/useSyncWishlist.ts +27 -8
- package/src/useUrlResolver/useUrlResolver.test.ts +6 -12
- package/src/useUrlResolver/useUrlResolver.ts +4 -6
- package/src/useUser/useUser.test.ts +233 -18
- package/src/useUser/useUser.ts +6 -1
- package/src/useWishlist/useWishlist.test.ts +133 -26
- package/src/useWishlist/useWishlist.ts +22 -6
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { ref } from "vue";
|
|
2
3
|
import { useSetup } from "../_test";
|
|
3
4
|
import CountryMock from "../mocks/Country";
|
|
4
5
|
import { useCountries } from "./useCountries";
|
|
@@ -102,4 +103,17 @@ describe("useCountries", () => {
|
|
|
102
103
|
|
|
103
104
|
expect(vm.getCountriesOptions).toStrictEqual([]);
|
|
104
105
|
});
|
|
106
|
+
|
|
107
|
+
it("should not fetch when swCountries already populated", async () => {
|
|
108
|
+
const preloadedCountries = ref(CountryMock.elements);
|
|
109
|
+
const { vm, injections } = await useSetup(useCountries, {
|
|
110
|
+
apiClient: { invoke: vi.fn() },
|
|
111
|
+
swCountries: preloadedCountries,
|
|
112
|
+
} as Parameters<typeof useSetup>[1]);
|
|
113
|
+
|
|
114
|
+
await vm.mountedCallback();
|
|
115
|
+
|
|
116
|
+
expect(injections.apiClient.invoke).not.toHaveBeenCalled();
|
|
117
|
+
expect(vm.getCountries).toStrictEqual(CountryMock.elements);
|
|
118
|
+
});
|
|
105
119
|
});
|
|
@@ -49,7 +49,7 @@ export function useCustomerOrders(): UseCustomerOrdersReturn {
|
|
|
49
49
|
|
|
50
50
|
const totalOrderItemsCount: Ref<number> = ref(0);
|
|
51
51
|
|
|
52
|
-
const currentParams = ref<
|
|
52
|
+
const currentParams = ref<operations["readOrder post /order"]["body"]>({});
|
|
53
53
|
|
|
54
54
|
const loadOrders = async (
|
|
55
55
|
parameters: operations["readOrder post /order"]["body"] = {},
|
|
@@ -8,31 +8,29 @@ describe("useDefaultOrderAssociations", () => {
|
|
|
8
8
|
|
|
9
9
|
expect(vm).toMatchInlineSnapshot(`
|
|
10
10
|
{
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"stateMachineState": {},
|
|
18
|
-
},
|
|
11
|
+
"addresses": {},
|
|
12
|
+
"deliveries": {
|
|
13
|
+
"associations": {
|
|
14
|
+
"shippingMethod": {},
|
|
15
|
+
"shippingOrderAddress": {},
|
|
16
|
+
"stateMachineState": {},
|
|
19
17
|
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
},
|
|
18
|
+
},
|
|
19
|
+
"lineItems": {
|
|
20
|
+
"associations": {
|
|
21
|
+
"cover": {},
|
|
22
|
+
"downloads": {
|
|
23
|
+
"associations": {
|
|
24
|
+
"media": {},
|
|
27
25
|
},
|
|
28
26
|
},
|
|
29
27
|
},
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
},
|
|
28
|
+
},
|
|
29
|
+
"stateMachineState": {},
|
|
30
|
+
"transactions": {
|
|
31
|
+
"associations": {
|
|
32
|
+
"paymentMethod": {},
|
|
33
|
+
"stateMachineState": {},
|
|
36
34
|
},
|
|
37
35
|
},
|
|
38
36
|
}
|
|
@@ -1,45 +1,38 @@
|
|
|
1
1
|
import type { Schemas } from "#shopware";
|
|
2
2
|
|
|
3
|
-
export type UseDefaultOrderAssociationsReturn = Schemas["Criteria"] & {
|
|
4
|
-
checkPromotion?: boolean;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
3
|
/**
|
|
8
4
|
* Returns default order associations. You can override this composable in your project.
|
|
9
5
|
* @public
|
|
10
6
|
* @category Order
|
|
11
7
|
*/
|
|
12
|
-
export function useDefaultOrderAssociations():
|
|
13
|
-
const orderAssociations
|
|
14
|
-
{
|
|
8
|
+
export function useDefaultOrderAssociations(): Schemas["Criteria"]["associations"] {
|
|
9
|
+
const orderAssociations = {
|
|
10
|
+
stateMachineState: {},
|
|
11
|
+
lineItems: {
|
|
15
12
|
associations: {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
associations: {
|
|
19
|
-
cover: {},
|
|
20
|
-
downloads: {
|
|
21
|
-
associations: {
|
|
22
|
-
media: {},
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
addresses: {},
|
|
28
|
-
deliveries: {
|
|
29
|
-
associations: {
|
|
30
|
-
shippingMethod: {},
|
|
31
|
-
shippingOrderAddress: {},
|
|
32
|
-
stateMachineState: {},
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
transactions: {
|
|
13
|
+
cover: {},
|
|
14
|
+
downloads: {
|
|
36
15
|
associations: {
|
|
37
|
-
|
|
38
|
-
stateMachineState: {},
|
|
16
|
+
media: {},
|
|
39
17
|
},
|
|
40
18
|
},
|
|
41
19
|
},
|
|
42
|
-
}
|
|
20
|
+
},
|
|
21
|
+
addresses: {},
|
|
22
|
+
deliveries: {
|
|
23
|
+
associations: {
|
|
24
|
+
shippingMethod: {},
|
|
25
|
+
shippingOrderAddress: {},
|
|
26
|
+
stateMachineState: {},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
transactions: {
|
|
30
|
+
associations: {
|
|
31
|
+
paymentMethod: {},
|
|
32
|
+
stateMachineState: {},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
43
36
|
|
|
44
37
|
return orderAssociations;
|
|
45
38
|
}
|
|
@@ -23,7 +23,7 @@ describe("useLandingSearch", () => {
|
|
|
23
23
|
expect.stringContaining("readLandingPage"),
|
|
24
24
|
expect.objectContaining({
|
|
25
25
|
pathParams: { landingPageId: "test" },
|
|
26
|
-
body: { associations: cmsAssociations },
|
|
26
|
+
body: { associations: cmsAssociations.associations },
|
|
27
27
|
}),
|
|
28
28
|
);
|
|
29
29
|
});
|
|
@@ -37,7 +37,7 @@ export function useLandingSearch(): {
|
|
|
37
37
|
},
|
|
38
38
|
) => {
|
|
39
39
|
const associations: operations["readLandingPage post /landing-page/{landingPageId}"]["body"]["associations"] =
|
|
40
|
-
options?.withCmsAssociations ? cmsAssociations : {};
|
|
40
|
+
options?.withCmsAssociations ? cmsAssociations.associations : {};
|
|
41
41
|
const result = await apiClient.invoke(
|
|
42
42
|
"readLandingPage post /landing-page/{landingPageId}",
|
|
43
43
|
{
|
|
@@ -246,4 +246,77 @@ describe("useListing", () => {
|
|
|
246
246
|
);
|
|
247
247
|
expect(vm.getAvailableFilters).toEqual([]);
|
|
248
248
|
});
|
|
249
|
+
|
|
250
|
+
it("should accept initialListing parameter", async () => {
|
|
251
|
+
const mockListing = {
|
|
252
|
+
apiAlias: "product_listing",
|
|
253
|
+
elements: [
|
|
254
|
+
{
|
|
255
|
+
id: "product-1",
|
|
256
|
+
name: "Test Product",
|
|
257
|
+
} as Schemas["Product"],
|
|
258
|
+
],
|
|
259
|
+
page: 1,
|
|
260
|
+
limit: 10,
|
|
261
|
+
total: 25,
|
|
262
|
+
} as Schemas["ProductListingResult"];
|
|
263
|
+
|
|
264
|
+
const { vm } = await useSetup(() =>
|
|
265
|
+
useListing({
|
|
266
|
+
listingType: "productSearchListing",
|
|
267
|
+
initialListing: mockListing,
|
|
268
|
+
}),
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
expect(vm.getInitialListing).toEqual(mockListing);
|
|
272
|
+
expect(vm.getCurrentListing).toEqual(mockListing);
|
|
273
|
+
expect(vm.getElements).toEqual(mockListing.elements);
|
|
274
|
+
expect(vm.getTotal).toBe(25);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it("should handle null initialListing parameter", async () => {
|
|
278
|
+
const { vm } = await useSetup(() =>
|
|
279
|
+
useListing({
|
|
280
|
+
listingType: "productSearchListing",
|
|
281
|
+
initialListing: null,
|
|
282
|
+
}),
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
expect(vm.getInitialListing).toBeNull();
|
|
286
|
+
expect(vm.getCurrentListing).toBeNull();
|
|
287
|
+
expect(vm.getElements).toEqual([]);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("should work without initialListing parameter (backward compatibility)", async () => {
|
|
291
|
+
const { vm } = await useSetup(() =>
|
|
292
|
+
useListing({
|
|
293
|
+
listingType: "productSearchListing",
|
|
294
|
+
}),
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
expect(vm.getInitialListing).toBeNull();
|
|
298
|
+
expect(vm.getCurrentListing).toBeNull();
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it("should initialize category listing with initialListing", async () => {
|
|
302
|
+
const mockListing = {
|
|
303
|
+
apiAlias: "product_listing",
|
|
304
|
+
elements: [{ id: "product-1" } as Schemas["Product"]],
|
|
305
|
+
page: 1,
|
|
306
|
+
limit: 10,
|
|
307
|
+
total: 1,
|
|
308
|
+
} as Schemas["ProductListingResult"];
|
|
309
|
+
|
|
310
|
+
const { vm } = await useSetup(() =>
|
|
311
|
+
useListing({
|
|
312
|
+
listingType: "categoryListing",
|
|
313
|
+
categoryId: "test-category",
|
|
314
|
+
initialListing: mockListing,
|
|
315
|
+
}),
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
expect(vm.getInitialListing).toEqual(mockListing);
|
|
319
|
+
expect(vm.getElements).toHaveLength(1);
|
|
320
|
+
expect(vm.getTotal).toBe(1);
|
|
321
|
+
});
|
|
249
322
|
});
|
|
@@ -183,6 +183,7 @@ export function useListing(params?: {
|
|
|
183
183
|
listingType: ListingType;
|
|
184
184
|
categoryId?: string;
|
|
185
185
|
defaultSearchCriteria?: operations["searchPage post /search"]["body"];
|
|
186
|
+
initialListing?: Schemas["ProductListingResult"] | null;
|
|
186
187
|
}): UseListingReturn {
|
|
187
188
|
const listingType = params?.listingType || "categoryListing";
|
|
188
189
|
let categoryId = params?.categoryId || null;
|
|
@@ -241,13 +242,17 @@ export function useListing(params?: {
|
|
|
241
242
|
searchDefaults:
|
|
242
243
|
params?.defaultSearchCriteria ||
|
|
243
244
|
({} as operations["searchPage post /search"]["body"]), //getDefaults(),
|
|
245
|
+
initialListing: params?.initialListing,
|
|
244
246
|
});
|
|
245
247
|
}
|
|
246
248
|
|
|
247
249
|
const [_createCategoryListingContext, _categoryListingContext] =
|
|
248
250
|
createInjectionState(
|
|
249
|
-
() => {
|
|
250
|
-
return useListing({
|
|
251
|
+
(initialListing?: Schemas["ProductListingResult"] | null) => {
|
|
252
|
+
return useListing({
|
|
253
|
+
listingType: "categoryListing",
|
|
254
|
+
initialListing,
|
|
255
|
+
});
|
|
251
256
|
},
|
|
252
257
|
{
|
|
253
258
|
injectionKey: "categoryListing",
|
|
@@ -292,6 +297,7 @@ export function createListingComposable({
|
|
|
292
297
|
searchMethod,
|
|
293
298
|
searchDefaults,
|
|
294
299
|
listingKey,
|
|
300
|
+
initialListing,
|
|
295
301
|
}: {
|
|
296
302
|
searchMethod(
|
|
297
303
|
searchParams:
|
|
@@ -300,6 +306,7 @@ export function createListingComposable({
|
|
|
300
306
|
): Promise<Schemas["ProductListingResult"]>;
|
|
301
307
|
searchDefaults: operations["searchPage post /search"]["body"];
|
|
302
308
|
listingKey: string;
|
|
309
|
+
initialListing?: Schemas["ProductListingResult"] | null;
|
|
303
310
|
}): UseListingReturn {
|
|
304
311
|
// const COMPOSABLE_NAME = "createListingComposable";
|
|
305
312
|
// const contextName = COMPOSABLE_NAME;
|
|
@@ -319,7 +326,7 @@ export function createListingComposable({
|
|
|
319
326
|
// const { sharedRef } = useSharedState();
|
|
320
327
|
const _storeInitialListing = inject<
|
|
321
328
|
Ref<Schemas["ProductListingResult"] | null>
|
|
322
|
-
>(`useListingInitial-${listingKey}`, ref(null));
|
|
329
|
+
>(`useListingInitial-${listingKey}`, ref(initialListing ?? null));
|
|
323
330
|
provide(`useListingInitial-${listingKey}`, _storeInitialListing);
|
|
324
331
|
// const _storeInitialListing = sharedRef<Schemas["ProductListingResult"]>(
|
|
325
332
|
// `${cacheKey}-initialListing-${listingKey}`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
2
|
import { useSetup } from "../_test";
|
|
3
3
|
import { useLocalWishlist } from "./useLocalWishlist";
|
|
4
4
|
|
|
@@ -10,6 +10,13 @@ describe("useLocalWishlist", () => {
|
|
|
10
10
|
vm.addToWishlist("some-id");
|
|
11
11
|
expect(vm.items.length).toBe(1);
|
|
12
12
|
});
|
|
13
|
+
|
|
14
|
+
it("addToWishlist does not add duplicate", () => {
|
|
15
|
+
const { vm } = useSetup(useLocalWishlist);
|
|
16
|
+
vm.addToWishlist("some-id");
|
|
17
|
+
vm.addToWishlist("some-id");
|
|
18
|
+
expect(vm.items.length).toBe(1);
|
|
19
|
+
});
|
|
13
20
|
});
|
|
14
21
|
|
|
15
22
|
describe("removeFromWishlist", () => {
|
|
@@ -18,14 +25,23 @@ describe("useLocalWishlist", () => {
|
|
|
18
25
|
vm.removeFromWishlist("some-id");
|
|
19
26
|
expect(vm.items.length).toBe(0);
|
|
20
27
|
});
|
|
28
|
+
|
|
29
|
+
it("should remove existing product from the wishlist", () => {
|
|
30
|
+
const { vm } = useSetup(useLocalWishlist);
|
|
31
|
+
vm.addToWishlist("id-to-remove");
|
|
32
|
+
vm.addToWishlist("id-to-keep");
|
|
33
|
+
vm.removeFromWishlist("id-to-remove");
|
|
34
|
+
expect(vm.items).toEqual(["id-to-keep"]);
|
|
35
|
+
});
|
|
21
36
|
});
|
|
22
37
|
|
|
23
38
|
describe("clearWishlist", () => {
|
|
24
|
-
it("should clear the wishlist", () => {
|
|
39
|
+
it("should clear the wishlist", async () => {
|
|
25
40
|
const { vm } = useSetup(useLocalWishlist);
|
|
26
|
-
vm.
|
|
41
|
+
await vm.clearWishlist();
|
|
42
|
+
await vm.addToWishlist("clear-test-id");
|
|
27
43
|
expect(vm.count).toBe(1);
|
|
28
|
-
vm.clearWishlist();
|
|
44
|
+
await vm.clearWishlist();
|
|
29
45
|
expect(vm.count).toBe(0);
|
|
30
46
|
});
|
|
31
47
|
});
|
|
@@ -45,10 +61,33 @@ describe("useLocalWishlist", () => {
|
|
|
45
61
|
});
|
|
46
62
|
it("getWishlistProducts with items localStorage", () => {
|
|
47
63
|
const { vm } = useSetup(useLocalWishlist);
|
|
48
|
-
|
|
64
|
+
vm.clearWishlist();
|
|
65
|
+
localStorage.setItem("sw-wishlist-items", JSON.stringify(["id-1"]));
|
|
49
66
|
vm.getWishlistProducts();
|
|
50
67
|
expect(vm.count).toBe(1);
|
|
68
|
+
expect(vm.items).toContain("id-1");
|
|
51
69
|
});
|
|
52
70
|
});
|
|
71
|
+
|
|
72
|
+
it("getWishlistProducts with missing localStorage key", () => {
|
|
73
|
+
const { vm } = useSetup(useLocalWishlist);
|
|
74
|
+
vm.clearWishlist();
|
|
75
|
+
localStorage.removeItem("sw-wishlist-items");
|
|
76
|
+
vm.getWishlistProducts();
|
|
77
|
+
expect(vm.count).toBe(0);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("getWishlistProducts returns nothing when localStorage is unavailable", () => {
|
|
81
|
+
const { vm } = useSetup(useLocalWishlist);
|
|
82
|
+
vm.clearWishlist();
|
|
83
|
+
const getItemSpy = vi
|
|
84
|
+
.spyOn(localStorage, "getItem")
|
|
85
|
+
.mockImplementation(() => {
|
|
86
|
+
throw new Error("localStorage not available");
|
|
87
|
+
});
|
|
88
|
+
vm.getWishlistProducts();
|
|
89
|
+
getItemSpy.mockRestore();
|
|
90
|
+
expect(vm.count).toBe(0);
|
|
91
|
+
});
|
|
53
92
|
});
|
|
54
93
|
});
|
|
@@ -43,10 +43,11 @@ export function useLocalWishlist(): UseLocalWishlistReturn {
|
|
|
43
43
|
JSON.stringify(_wishlistItems.value),
|
|
44
44
|
);
|
|
45
45
|
};
|
|
46
|
-
/* istanbul ignore next */
|
|
47
46
|
const getFromStorage = () => {
|
|
48
|
-
|
|
47
|
+
try {
|
|
49
48
|
return JSON.parse(localStorage.getItem("sw-wishlist-items") ?? "[]");
|
|
49
|
+
} catch {
|
|
50
|
+
return undefined;
|
|
50
51
|
}
|
|
51
52
|
};
|
|
52
53
|
|
|
@@ -3,46 +3,47 @@ import { ref } from "vue";
|
|
|
3
3
|
import { useSetup } from "../_test";
|
|
4
4
|
import { useNavigationContext } from "./useNavigationContext";
|
|
5
5
|
|
|
6
|
+
const mockSeoUrl = {
|
|
7
|
+
createdAt: "2020-08-06T06:26:52.576+00:00",
|
|
8
|
+
foreignKey: "7e117859f69b4ee08947e1ae4fce1f69",
|
|
9
|
+
id: "dd38c5ed443544e28818e967809c8914",
|
|
10
|
+
isCanonical: true,
|
|
11
|
+
isDeleted: false,
|
|
12
|
+
isModified: false,
|
|
13
|
+
languageId: "2fbb5fe2e29a4d70aa5854ce7ce3e20b",
|
|
14
|
+
pathInfo: "/detail/7e117859f69b4ee08947e1ae4fce1f69",
|
|
15
|
+
routeName: "frontend.detail.page",
|
|
16
|
+
updatedAt: "2022-08-03T08:07:04.512+00:00",
|
|
17
|
+
salesChannelId: "98432def39fc4624b33213a56b8c944d",
|
|
18
|
+
seoPathInfo: "Cigar-Special-40/SW10044",
|
|
19
|
+
} as const;
|
|
20
|
+
|
|
6
21
|
describe("useNavigationContext", () => {
|
|
7
22
|
it("notification flow", async () => {
|
|
8
|
-
const { vm } = useSetup(() =>
|
|
9
|
-
useNavigationContext(
|
|
10
|
-
ref({
|
|
11
|
-
createdAt: "2020-08-06T06:26:52.576+00:00",
|
|
12
|
-
foreignKey: "7e117859f69b4ee08947e1ae4fce1f69",
|
|
13
|
-
id: "dd38c5ed443544e28818e967809c8914",
|
|
14
|
-
isCanonical: true,
|
|
15
|
-
isDeleted: false,
|
|
16
|
-
isModified: false,
|
|
17
|
-
languageId: "2fbb5fe2e29a4d70aa5854ce7ce3e20b",
|
|
18
|
-
pathInfo: "/detail/7e117859f69b4ee08947e1ae4fce1f69",
|
|
19
|
-
routeName: "frontend.detail.page",
|
|
20
|
-
updatedAt: "2022-08-03T08:07:04.512+00:00",
|
|
21
|
-
salesChannelId: "98432def39fc4624b33213a56b8c944d",
|
|
22
|
-
seoPathInfo: "Cigar-Special-40/SW10044",
|
|
23
|
-
}),
|
|
24
|
-
),
|
|
25
|
-
);
|
|
23
|
+
const { vm } = useSetup(() => useNavigationContext(ref(mockSeoUrl)));
|
|
26
24
|
|
|
27
25
|
expect(vm.foreignKey).toBe("7e117859f69b4ee08947e1ae4fce1f69");
|
|
28
26
|
expect(vm.routeName).toBe("frontend.detail.page");
|
|
27
|
+
expect(vm.navigationContext).toEqual(mockSeoUrl);
|
|
29
28
|
});
|
|
30
29
|
|
|
31
30
|
it("should return empty string if no foreignKey", async () => {
|
|
32
31
|
const { vm } = useSetup(() =>
|
|
33
32
|
useNavigationContext(
|
|
34
33
|
ref({
|
|
35
|
-
|
|
34
|
+
...mockSeoUrl,
|
|
36
35
|
foreignKey: "",
|
|
37
|
-
id: "dd38c5ed443544e28818e967809c8914",
|
|
38
|
-
languageId: "2fbb5fe2e29a4d70aa5854ce7ce3e20b",
|
|
39
|
-
pathInfo: "/detail/7e117859f69b4ee08947e1ae4fce1f69",
|
|
40
|
-
routeName: "frontend.detail.page",
|
|
41
|
-
seoPathInfo: "Cigar-Special-40/SW10044",
|
|
42
36
|
}),
|
|
43
37
|
),
|
|
44
38
|
);
|
|
45
39
|
|
|
46
40
|
expect(vm.foreignKey).toBe("");
|
|
47
41
|
});
|
|
42
|
+
|
|
43
|
+
it("should return empty string when context is null", () => {
|
|
44
|
+
const { vm } = useSetup(() => useNavigationContext(ref(null)));
|
|
45
|
+
expect(vm.foreignKey).toBe("");
|
|
46
|
+
expect(vm.routeName).toBeUndefined();
|
|
47
|
+
expect(vm.navigationContext).toBeNull();
|
|
48
|
+
});
|
|
48
49
|
});
|
|
@@ -52,4 +52,20 @@ describe("useNewsletter", () => {
|
|
|
52
52
|
vm.newsletterStatus = "direct";
|
|
53
53
|
expect(vm.isNewsletterSubscriber).toBe(true);
|
|
54
54
|
});
|
|
55
|
+
|
|
56
|
+
it("confirmationNeeded when status is notSet", async () => {
|
|
57
|
+
const { vm, injections } = useSetup(useNewsletter);
|
|
58
|
+
injections.apiClient.invoke.mockResolvedValue({
|
|
59
|
+
data: { status: "notSet" },
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
await vm.getNewsletterStatus();
|
|
63
|
+
expect(vm.confirmationNeeded).toBe(true);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("returns SUBSRIBE_KEY and UNSUBSCRIBE_KEY", () => {
|
|
67
|
+
const { vm } = useSetup(useNewsletter);
|
|
68
|
+
expect(vm.SUBSCRIBE_KEY).toBe("subscribe");
|
|
69
|
+
expect(vm.UNSUBSCRIBE_KEY).toBe("unsubscribe");
|
|
70
|
+
});
|
|
55
71
|
});
|
|
@@ -37,6 +37,14 @@ export type UseNewsletterReturn = {
|
|
|
37
37
|
* Inform about newsletter confirmation
|
|
38
38
|
*/
|
|
39
39
|
confirmationNeeded: ComputedRef<boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* Subscribe key
|
|
42
|
+
*/
|
|
43
|
+
SUBSCRIBE_KEY: string;
|
|
44
|
+
/**
|
|
45
|
+
* Unsubscribe key
|
|
46
|
+
*/
|
|
47
|
+
UNSUBSCRIBE_KEY: string;
|
|
40
48
|
};
|
|
41
49
|
|
|
42
50
|
/**
|
|
@@ -45,6 +53,9 @@ export type UseNewsletterReturn = {
|
|
|
45
53
|
* @category Customer & Account
|
|
46
54
|
*/
|
|
47
55
|
export function useNewsletter(): UseNewsletterReturn {
|
|
56
|
+
const SUBSCRIBE_KEY = "subscribe";
|
|
57
|
+
const UNSUBSCRIBE_KEY = "unsubscribe";
|
|
58
|
+
|
|
48
59
|
const { apiClient } = useShopwareContext();
|
|
49
60
|
const { getStorefrontUrl } = useInternationalization();
|
|
50
61
|
const newsletterStatus =
|
|
@@ -105,5 +116,7 @@ export function useNewsletter(): UseNewsletterReturn {
|
|
|
105
116
|
getNewsletterStatus,
|
|
106
117
|
newsletterStatus,
|
|
107
118
|
confirmationNeeded,
|
|
119
|
+
SUBSCRIBE_KEY,
|
|
120
|
+
UNSUBSCRIBE_KEY,
|
|
108
121
|
};
|
|
109
122
|
}
|
|
@@ -6,12 +6,21 @@ import { useOrderDetails } from "./useOrderDetails";
|
|
|
6
6
|
describe("useOrderDetails", () => {
|
|
7
7
|
it("init details", async () => {
|
|
8
8
|
const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
|
|
9
|
+
|
|
10
|
+
expect(vm.documents).toStrictEqual([]);
|
|
11
|
+
|
|
9
12
|
injections.apiClient.invoke.mockResolvedValue({ data: Order });
|
|
10
13
|
|
|
11
14
|
await vm.loadOrderDetails();
|
|
15
|
+
expect(vm.hasDocuments).toBe(false);
|
|
16
|
+
expect(vm.documents).toStrictEqual([]);
|
|
12
17
|
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
13
18
|
expect.stringContaining("readOrder"),
|
|
14
|
-
expect.objectContaining({
|
|
19
|
+
expect.objectContaining({
|
|
20
|
+
body: expect.objectContaining({
|
|
21
|
+
associations: expect.anything(),
|
|
22
|
+
}),
|
|
23
|
+
}),
|
|
15
24
|
);
|
|
16
25
|
|
|
17
26
|
expect(vm.personalDetails).toEqual({
|
|
@@ -26,11 +35,25 @@ describe("useOrderDetails", () => {
|
|
|
26
35
|
id === Order.orders.elements?.[0]?.billingAddressId,
|
|
27
36
|
),
|
|
28
37
|
);
|
|
38
|
+
|
|
39
|
+
expect(vm.order).toBeDefined();
|
|
40
|
+
expect(vm.status).toBe(
|
|
41
|
+
Order.orders.elements?.[0]?.stateMachineState.translated.name,
|
|
42
|
+
);
|
|
43
|
+
expect(vm.statusTechnicalName).toBe(
|
|
44
|
+
Order.orders.elements?.[0]?.stateMachineState.technicalName,
|
|
45
|
+
);
|
|
46
|
+
expect(vm.shippingAddress).toBeUndefined();
|
|
47
|
+
expect(vm.total).toBe(Order.orders.elements?.[0]?.price?.totalPrice);
|
|
48
|
+
expect(vm.subtotal).toBe(Order.orders.elements?.[0]?.price?.positionPrice);
|
|
49
|
+
expect(vm.shippingCosts).toBe(Order.orders.elements?.[0]?.shippingTotal);
|
|
29
50
|
});
|
|
30
51
|
|
|
31
52
|
it("should handle setting the order payment", async () => {
|
|
32
53
|
const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
|
|
33
|
-
injections.apiClient.invoke.mockResolvedValue({
|
|
54
|
+
injections.apiClient.invoke.mockResolvedValue({
|
|
55
|
+
data: { redirectUrl: "https://payment.example.com" },
|
|
56
|
+
});
|
|
34
57
|
await vm.handlePayment();
|
|
35
58
|
|
|
36
59
|
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
@@ -43,6 +66,24 @@ describe("useOrderDetails", () => {
|
|
|
43
66
|
},
|
|
44
67
|
}),
|
|
45
68
|
);
|
|
69
|
+
expect(vm.paymentUrl).toBe("https://payment.example.com");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("should handle payment with success and error URLs", async () => {
|
|
73
|
+
const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
|
|
74
|
+
injections.apiClient.invoke.mockResolvedValue({ data: {} });
|
|
75
|
+
await vm.handlePayment("https://success.com", "https://error.com");
|
|
76
|
+
|
|
77
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
78
|
+
expect.stringContaining("handlePaymentMethod"),
|
|
79
|
+
expect.objectContaining({
|
|
80
|
+
body: {
|
|
81
|
+
orderId: "123-test",
|
|
82
|
+
finishUrl: "https://success.com",
|
|
83
|
+
errorUrl: "https://error.com",
|
|
84
|
+
},
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
46
87
|
});
|
|
47
88
|
|
|
48
89
|
it("should cancel the order", async () => {
|
|
@@ -112,7 +153,7 @@ describe("useOrderDetails", () => {
|
|
|
112
153
|
it("getPaymentMethods", async () => {
|
|
113
154
|
const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
|
|
114
155
|
injections.apiClient.invoke.mockResolvedValue({ data: {} });
|
|
115
|
-
await vm.getPaymentMethods();
|
|
156
|
+
const result = await vm.getPaymentMethods();
|
|
116
157
|
|
|
117
158
|
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
118
159
|
expect.stringContaining("readPaymentMethod"),
|
|
@@ -122,6 +163,18 @@ describe("useOrderDetails", () => {
|
|
|
122
163
|
},
|
|
123
164
|
}),
|
|
124
165
|
);
|
|
166
|
+
expect(result).toEqual([]);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("getPaymentMethods returns elements when available", async () => {
|
|
170
|
+
const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
|
|
171
|
+
const paymentMethods = [{ id: "1", name: "Invoice" }];
|
|
172
|
+
injections.apiClient.invoke.mockResolvedValue({
|
|
173
|
+
data: { elements: paymentMethods },
|
|
174
|
+
});
|
|
175
|
+
const result = await vm.getPaymentMethods();
|
|
176
|
+
|
|
177
|
+
expect(result).toEqual(paymentMethods);
|
|
125
178
|
});
|
|
126
179
|
|
|
127
180
|
it("paymentChangeable", async () => {
|
|
@@ -132,6 +185,42 @@ describe("useOrderDetails", () => {
|
|
|
132
185
|
expect(vm.paymentChangeable).toEqual(true);
|
|
133
186
|
});
|
|
134
187
|
|
|
188
|
+
it("loadOrderDetails with custom associations", async () => {
|
|
189
|
+
const customAssociations = { lineItems: { associations: { cover: {} } } };
|
|
190
|
+
const { vm, injections } = useSetup(() =>
|
|
191
|
+
useOrderDetails("123-test", customAssociations),
|
|
192
|
+
);
|
|
193
|
+
injections.apiClient.invoke.mockResolvedValue({ data: Order });
|
|
194
|
+
await vm.loadOrderDetails();
|
|
195
|
+
|
|
196
|
+
const call = injections.apiClient.invoke.mock.calls.at(0);
|
|
197
|
+
expect(call).toBeDefined();
|
|
198
|
+
if (call) {
|
|
199
|
+
const args = call[1] as { body: { associations: unknown } };
|
|
200
|
+
expect(call[0]).toContain("readOrder");
|
|
201
|
+
expect(args.body.associations).toMatchObject(customAssociations);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("hasDocuments and documents when order has documents", async () => {
|
|
206
|
+
const orderElement = Order.orders.elements[0];
|
|
207
|
+
const orderWithDocs = {
|
|
208
|
+
...orderElement,
|
|
209
|
+
documents: [{ id: "doc-1", deepLinkCode: "abc" }],
|
|
210
|
+
};
|
|
211
|
+
const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
|
|
212
|
+
injections.apiClient.invoke.mockResolvedValue({
|
|
213
|
+
data: {
|
|
214
|
+
orders: { elements: [orderWithDocs] },
|
|
215
|
+
paymentChangeable: { "123-test": true },
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
await vm.loadOrderDetails();
|
|
219
|
+
|
|
220
|
+
expect(vm.hasDocuments).toBe(true);
|
|
221
|
+
expect(vm.documents).toStrictEqual([{ id: "doc-1", deepLinkCode: "abc" }]);
|
|
222
|
+
});
|
|
223
|
+
|
|
135
224
|
it("should return current payment method", async () => {
|
|
136
225
|
const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
|
|
137
226
|
injections.apiClient.invoke.mockResolvedValue({
|