forked from SmartDropLabs/smartdrop-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoostModal.test.tsx
More file actions
128 lines (117 loc) · 3.49 KB
/
Copy pathBoostModal.test.tsx
File metadata and controls
128 lines (117 loc) · 3.49 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { render, screen } from "@testing-library/react";
import { ChakraProvider } from "@chakra-ui/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { useStellarWallet } from "@/context/StellarWalletContext";
import { useFarmStore } from "@/store/farmStore";
import BoostModal from "./BoostModal";
vi.mock("@/context/StellarWalletContext", () => ({
useStellarWallet: vi.fn(),
}));
vi.mock("@/hooks/useSorobanQuery", async (importOriginal) => {
const actual = await importOriginal<typeof import("@/hooks/useSorobanQuery")>();
return { ...actual, useSetBoost: vi.fn() };
});
const useStellarWalletMock = vi.mocked(useStellarWallet);
const { useSetBoost } = await import("@/hooks/useSorobanQuery");
const useSetBoostMock = vi.mocked(useSetBoost);
const defaultWallet = {
publicKey: "GA3CD2PYXOQCXW7ZVQW3MOA3JFZCE4F4IG2FD66I55TQASPCNKYYEFRN",
walletApi: {},
networkName: "TESTNET",
isNetworkMismatch: false,
isConnected: true,
connect: vi.fn(),
disconnect: vi.fn(),
};
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
function renderModal() {
return render(
<QueryClientProvider client={queryClient}>
<ChakraProvider>
<BoostModal />
</ChakraProvider>
</QueryClientProvider>,
);
}
beforeEach(() => {
useStellarWalletMock.mockReturnValue(defaultWallet);
useSetBoostMock.mockReturnValue({
mutate: vi.fn(),
isPending: false,
reset: vi.fn(),
} as ReturnType<typeof useSetBoost> extends infer R ? R : never);
useFarmStore.setState({
selectedPosition: null,
activeModal: "none",
pendingTxHash: null,
});
});
describe("BoostModal", () => {
it("does not render when modal is not open", () => {
renderModal();
expect(screen.queryByText("Set Boost")).toBeNull();
});
it("renders when boost modal is opened", () => {
useFarmStore.setState({
selectedPosition: {
id: "pool-1",
name: "XLM",
img: "",
earned: "10",
stake: "50",
dailyRate: "0.5",
totalStakedLiquidity: "$1,000",
symbol: "XLM",
lockedAmount: 50,
lockedAt: Date.now() - 86400000,
lockPeriodSeconds: 86400,
},
activeModal: "boost",
});
renderModal();
expect(screen.getByText("Set Boost - XLM")).toBeTruthy();
});
it("shows current boost allocation", () => {
useFarmStore.setState({
selectedPosition: {
id: "pool-1",
name: "XLM",
img: "",
earned: "10",
stake: "50",
dailyRate: "0.5",
totalStakedLiquidity: "$1,000",
symbol: "XLM",
lockedAmount: 50,
lockedAt: Date.now() - 86400000,
lockPeriodSeconds: 86400,
boostAllocation: 25,
},
activeModal: "boost",
});
renderModal();
expect(screen.getByText("Current boost")).toBeTruthy();
expect(screen.getAllByText("25%").length).toBeGreaterThanOrEqual(1);
});
it("shows warning when user has no stake", () => {
useFarmStore.setState({
selectedPosition: {
id: "pool-1",
name: "XLM",
img: "",
earned: "0",
stake: "0",
dailyRate: "0",
totalStakedLiquidity: "$1,000",
symbol: "XLM",
lockedAmount: 0,
lockedAt: 0,
lockPeriodSeconds: 86400,
},
activeModal: "boost",
});
renderModal();
expect(screen.getByText(/You need to deposit/)).toBeTruthy();
});
});