This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
/
AddLiquidity.test.tsx
177 lines (153 loc) · 4.66 KB
/
AddLiquidity.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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import type { Fuel, FuelWalletLocked } from "@fuel-wallet/sdk";
import {
screen,
renderWithRouter,
waitFor,
fireEvent,
} from "@swayswap/test-utils";
import { mockUseUserPosition } from "../hooks/__mocks__/useUserPosition";
import * as poolQueries from "../utils/queries";
import { App } from "~/App";
import { ZERO } from "~/systems/Core";
import {
createWallet,
mockUseFuel,
mockUseWallet,
} from "~/systems/Core/hooks/__mocks__/useWallet";
import { faucet } from "~/systems/Faucet/hooks/__mocks__/useFaucet";
import { mint } from "~/systems/Mint/hooks/__mocks__/useMint";
import { setAgreement } from "~/systems/Welcome";
let wallet: FuelWalletLocked;
let fuel: Fuel;
beforeAll(async () => {
setAgreement(true);
({ wallet, fuel } = await createWallet());
mockUseFuel(fuel);
mockUseWallet(wallet);
});
afterAll(() => {
setAgreement(false);
});
describe("Add Liquidity", () => {
beforeEach(() => {
mockUseUserPosition();
});
afterEach(() => {
jest.clearAllMocks();
});
it("should see a 'new pool' message", async () => {
renderWithRouter(<App />, { route: "/pool/add-liquidity" });
jest.spyOn(poolQueries, "fetchPoolInfo").mockImplementation(async () => ({
token_reserve1: ZERO,
token_reserve2: ZERO,
lp_token_supply: ZERO,
}));
const newPoolMessage = await screen.findByText(/new pool/, undefined, {
timeout: 20000,
});
expect(newPoolMessage).toBeInTheDocument();
});
it("should enter amount button be disabled by default", async () => {
renderWithRouter(<App />, { route: "/pool/add-liquidity" });
await waitFor(async () => {
const submitBtn = await screen.findByText(/Enter sEther amount/);
expect(submitBtn).toBeInTheDocument();
expect(submitBtn).toBeDisabled();
});
});
it("should submit button ask to inform DAI", async () => {
renderWithRouter(<App />, {
route: "/pool/add-liquidity",
});
const coinFromInput = screen.getByLabelText(/Coin from input/);
fireEvent.change(coinFromInput, {
target: {
value: "10",
},
});
await waitFor(
() => {
const submitBtn = screen.getByText(/Enter DAI amount/);
expect(submitBtn).toBeInTheDocument();
expect(submitBtn).toBeDisabled();
},
{ timeout: 10000 }
);
});
it("should be able to set coin to input values if no liquidity added", async () => {
renderWithRouter(<App />, {
route: "/pool/add-liquidity",
});
const coinFromInput = await screen.findByLabelText(/Coin from input/);
fireEvent.change(coinFromInput, {
target: {
value: "10",
},
});
expect(coinFromInput).toHaveValue("10");
const coinToInput = await screen.findByLabelText(/Coin to input/);
fireEvent.change(coinToInput, {
target: {
value: "1000",
},
});
expect(coinToInput).toHaveValue("1000");
});
describe("Create/Add liquidity", () => {
it("Should be able to create liquidity", async () => {
await faucet(wallet);
await mint(wallet);
const { user } = renderWithRouter(<App />, {
route: "/pool/add-liquidity",
});
const coinFromInput = await screen.findByLabelText(/Coin from input/);
fireEvent.change(coinFromInput, {
target: {
value: "0.1",
},
});
const coinToInput = await screen.findByLabelText(/Coin to input/);
fireEvent.change(coinToInput, {
target: {
value: "500",
},
});
const submitBtn = await screen.findByText(/Create liquidity/, undefined, {
timeout: 10000,
});
expect(submitBtn).toBeInTheDocument();
await user.click(submitBtn);
});
it("Should be able to add liquidity", async () => {
const { user } = renderWithRouter(<App />, {
route: "/pool/add-liquidity",
});
const coinFromInput = await screen.findByLabelText(/Coin from input/);
fireEvent.change(coinFromInput, {
target: {
value: "0.1",
},
});
waitFor(async () => {
const submitBtn = await screen.findByText(/Add liquidity/);
expect(submitBtn).toBeInTheDocument();
await user.click(submitBtn);
});
});
});
it("should show '0.' if typed only '.' in the input", async () => {
jest.unmock("../hooks/useUserPositions.ts");
renderWithRouter(<App />, {
route: "/pool/add-liquidity",
});
const coinFromInput = screen.getByLabelText(/Coin from input/);
fireEvent.change(coinFromInput, {
target: {
value: ".",
},
});
await waitFor(() => {
expect(screen.getByLabelText(/Coin from input/)).toHaveValue("0.");
});
});
});