-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test code for DefaultView (#2160)
* 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
1 parent
db916e4
commit 197538f
Showing
2 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
]; |