Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jackstar12 committed Jan 9, 2025
1 parent a57f849 commit efba188
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 144 deletions.
4 changes: 2 additions & 2 deletions src/pages/RefundExternal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ enum RefundError {
InvalidData,
}

const RefundBtcLike = () => {
export const RefundBtcLike = () => {
const { t } = useGlobalContext();

const [refundInvalid, setRefundInvalid] = createSignal<
Expand Down Expand Up @@ -126,7 +126,7 @@ const RefundBtcLike = () => {
);
};

const RefundRsk = () => {
export const RefundRsk = () => {
const { t } = useGlobalContext();
const { signer, getEtherSwap } = useWeb3Signer();

Expand Down
142 changes: 0 additions & 142 deletions tests/pages/Refund.spec.tsx

This file was deleted.

99 changes: 99 additions & 0 deletions tests/pages/RefundExternal.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { render, screen } from "@solidjs/testing-library";
import { userEvent } from "@testing-library/user-event";

import i18n from "../../src/i18n/i18n";
import { TestComponent, contextWrapper, globalSignals } from "../helper";
import RefundExternal, { RefundBtcLike } from "../../src/pages/RefundExternal";

/* eslint-disable require-await,@typescript-eslint/require-await,@typescript-eslint/no-explicit-any */

jest.mock("../../src/utils/boltzClient", () => {
const originalModule = jest.requireActual("../../src/utils/boltzClient");

return {
__esModule: true,
...originalModule,
getLockupTransaction: jest.fn(() => {
return { timeoutBlockHeight: 10, timeoutEta: 10 };
}),
} as unknown;
});

describe("RefundExternal", () => {
test("should render WASM error", async () => {
render(
() => (
<>
<TestComponent />
<RefundExternal />
</>
),
{
wrapper: contextWrapper,
},
);
globalSignals.setWasmSupported(false);
expect(
await screen.findAllByText(i18n.en.error_wasm),
).not.toBeUndefined();
});

describe("BtcLike", () => {
test("should show refund button when file was uploaded", async () => {
const user = userEvent.setup();
render(
() => (
<>
<TestComponent />
<RefundBtcLike />
</>
),
{
wrapper: contextWrapper,
},
);
const uploadInput = await screen.findByTestId("refundUpload");
const swapFile = new File(["{}"], "swap.json", {
type: "application/json",
});
(swapFile as any).text = async () =>
JSON.stringify({
asset: "BTC",
id: "",
privateKey: "",
});
await user.upload(uploadInput, swapFile);

expect(await screen.findAllByText(i18n.en.refund)).not.toBeUndefined();
});

test("should show invalid refund button when invalid file was uploaded", async () => {
const user = userEvent.setup();
render(
() => (
<>
<TestComponent />
<RefundBtcLike />
</>
),
{
wrapper: contextWrapper,
},
);
const uploadInput = await screen.findByTestId("refundUpload");
const swapFile = new File(["{}"], "swap.json", {
type: "application/json",
});
(swapFile as any).text = async () =>
JSON.stringify({
asset: "BTC",
});
await user.upload(uploadInput, swapFile);

expect(
await screen.findAllByText(i18n.en.invalid_refund_file),
).not.toBeUndefined();
});
})

});

0 comments on commit efba188

Please sign in to comment.