Skip to content

Commit

Permalink
test: add test code for DefaultView (#2160)
Browse files Browse the repository at this point in the history
* test: add test code for DefaultView

* test: add test code for DefaultView

* feat: modify the name of the test case

* fix: default view test

---------

Co-authored-by: im-adithya <imadithyavardhan@gmail.com>
  • Loading branch information
qqqzhch and im-adithya authored Jun 19, 2023
1 parent db916e4 commit 197538f
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
90 changes: 90 additions & 0 deletions src/app/screens/Home/DefaultView/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { render, screen } from "@testing-library/react";
import { I18nextProvider } from "react-i18next";
import { MemoryRouter } from "react-router-dom";
import { settingsFixture as mockSettings } from "~/../tests/fixtures/settings";
import i18n from "~/../tests/unit/helpers/i18n";
import { BatteryFixture } from "~/fixtures/battery";

import { AccountsProvider } from "../../../context/AccountsContext";
import DefaultView from "./index";

jest.mock("~/common/lib/api", () => ({
getPayments: () => {
return {
payments: [],
};
},
getBlocklist: () => {
return {};
},
getInvoices: () => {
return { invoices: [] };
},
}));

const mockGetFiatValue = jest
.fn()
.mockImplementation(() => Promise.resolve("$0.00"));

jest.mock("~/app/context/AccountContext", () => ({
useAccount: () => ({
account: { id: "1", name: "LND account" },
loading: false,
unlock: jest.fn(),
lock: jest.fn(),
setAccountId: jest.fn(),
fetchAccountInfo: jest.fn(),
balancesDecorated: {
fiatBalance: "",
accountBalance: "",
},
}),
}));

jest.mock("~/app/context/SettingsContext", () => ({
useSettings: () => ({
settings: mockSettings,
isLoading: false,
updateSetting: jest.fn(),
getFormattedNumber: jest.fn(),
getFormattedSats: jest.fn(() => "21 sats"),
getFormattedFiat: mockGetFiatValue,
}),
}));

describe("DefaultView", () => {
test("render DefaultView", async () => {
render(
<AccountsProvider>
<I18nextProvider i18n={i18n}>
<MemoryRouter>
<DefaultView currentUrl={new URL("https://github.com/")} />
</MemoryRouter>
</I18nextProvider>
</AccountsProvider>
);
expect(await screen.findByText("Send")).toBeInTheDocument();
expect(await screen.findByText("Receive")).toBeInTheDocument();
});
test("render DefaultView with battery", async () => {
const battery = BatteryFixture[0];
render(
<AccountsProvider>
<I18nextProvider i18n={i18n}>
<MemoryRouter>
<DefaultView
currentUrl={new URL("https://github.com/")}
lnDataFromCurrentTab={[battery]}
/>
</MemoryRouter>
</I18nextProvider>
</AccountsProvider>
);

expect(
await screen.findByText("⚡️ Send Satoshis ⚡️")
).toBeInTheDocument();
expect(await screen.findByText(battery.name)).toBeInTheDocument();
expect(await screen.findByText(battery.description)).toBeInTheDocument();
});
});
25 changes: 25 additions & 0 deletions src/fixtures/battery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { Battery } from "~/types";

export const BatteryFixture: Battery[] = [
{
method: "lnurl",
address: "tester@getalby.com",
customKey: "",
customValue: "",
suggested: "",
name: "test.fund",
icon: "https://geyser.fund/logo-brand.svg",
location: "https://github.com/hi",
domain: "https://github.com",
host: "github.com",
pathname: "/hi",
description: "metaData tester description",
metaData: {
icon: "https://github.githubassets.com/pinned-octocat.svg",
provider: "github",
title: "metaData tester",
url: "https://github.com/im-adithya",
},
external: true,
},
];

0 comments on commit 197538f

Please sign in to comment.