-
Notifications
You must be signed in to change notification settings - Fork 0
/
useCustomCart.test.tsx
56 lines (50 loc) · 1.75 KB
/
useCustomCart.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import {act, renderHook, waitFor} from "@testing-library/react";
import React, {ReactNode, useState} from "react";
import {CartProvider, ShopifyProvider} from "@shopify/hydrogen-react";
import "whatwg-fetch";
import {useCustomCart} from "./useCustomCart";
const accessToken = "8b6008fe5f922fb7b1f0df8b142c2d38";
const renderCart = () => {
const wrapper = ({children}: { children: ReactNode }) => {
const [callback, setCallback] = useState<() => void>();
return (
<ShopifyProvider
storeDomain={`https://test-cleankitchen.myshopify.com`}
storefrontApiVersion="2023-01"
storefrontToken={accessToken}
countryIsoCode="EE"
languageIsoCode="ET"
>
<CartProvider
onLineAddComplete={() => console.log("Lines add complete", new Date())}
onLineUpdateComplete={() => console.log("Line update complete", new Date())}
onLineRemoveComplete={() => console.log("Lines Remove complete") }
onAttributesUpdateComplete={() =>
console.log("Attributes update complete", new Date())
}
>
{children}
</CartProvider>
</ShopifyProvider>
);
};
return renderHook(() => useCustomCart(), {wrapper});
};
test("when calling line remove and line add the latter is ignored", async () => {
const {result} = renderCart();
act(() => result.current.create());
await waitFor(() => {
expect(result.current.cart.status).toBe("idle");
});
await waitFor(async () => {
await result.current.addProduct("gid://shopify/ProductVariant/44671043141922");
});
await waitFor(() => {
expect(result.current.cart.status).toBe("idle");
});
await waitFor(() => {
expect(
result.current.cart.totalQuantity
).toBe(20);
});
})