Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5,047 changes: 1,951 additions & 3,096 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,23 @@ describe("MobileAddressRow", () => {
await userEvent.click(screen.getByTestId("dropdown__option--0"));
expect(onSelectOption).toHaveBeenCalled();
});

it("should render error message", () => {
render(
<MobileAddressRow
profile={profile}
wallet={wallet}
onDelete={vi.fn()}
usesManageMode={true}
toggleAddress={vi.fn()}
isSelected={false}
onSelectOption={vi.fn()}
isSingleView={true}
isError={true}
errorMessage="Test error message"
/>,
);

expect(screen.getByText("Test error message")).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { env, getMainsailProfileId, mockNanoSTransport, render, screen, waitFor } from "@/utils/testing-library";
import { expect, it, describe, beforeAll, vi, beforeEach } from "vitest";
import { Contracts } from "@/app/lib/profiles";
import { LedgerConnectionStep } from "./LedgerConnection";
import { useLedgerContext } from "@/app/contexts/Ledger";

const defaultLedgerContext = {
abortConnectionRetry: vi.fn(),
connect: vi.fn(),
error: "",
isConnected: false,
};

vi.mock("@/app/contexts/Ledger", () => ({
useLedgerContext: vi.fn(() => defaultLedgerContext),
}));

beforeEach(() => {
vi.mocked(useLedgerContext).mockReturnValue({ ...defaultLedgerContext });
});

const mockNetwork = {
coin: () => "Mainsail",
id: () => "mainsail",
isLive: () => true,
isTest: () => false,
ticker: () => "ARK",
toObject: () => ({ id: "mainsail", name: "Mainsail" }),
};

describe("LedgerConnection", () => {
let profile: Contracts.IProfile;
const route = `/profiles/${getMainsailProfileId()}/dashboard`;

beforeAll(async () => {
mockNanoSTransport();

profile = env.profiles().findById(getMainsailProfileId());
await env.profiles().restore(profile);
});

it("should render connection step", async () => {
const onConnect = vi.fn();

await render(<LedgerConnectionStep profile={profile} network={mockNetwork as any} onConnect={onConnect} />, {
route,
});

expect(screen.getByTestId("LedgerConnectionStep")).toBeInTheDocument();
});

it("should render cancelling state", async () => {
const onConnect = vi.fn();

await render(
<LedgerConnectionStep
profile={profile}
network={mockNetwork as any}
isCancelling={true}
onConnect={onConnect}
/>,
{ route },
);

await waitFor(() => {
expect(screen.queryByTestId("LedgerConnectionStep")).not.toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,39 @@ describe("LedgerMigrationOverview", () => {
expect(screen.getByTestId("UpdateWalletName__input")).toBeInTheDocument();
});
});

it("should close modal on cancel", async () => {
render(<LedgerMigrationOverview profile={profile} transfer={transaction} />);

await userEvent.click(screen.getByTestId("LedgerMigration__Review-edit"));

await waitFor(() => {
expect(screen.getByTestId("UpdateWalletName__input")).toBeInTheDocument();
});

await userEvent.click(screen.getByTestId("UpdateWalletName__cancel"));

await waitFor(() => {
expect(screen.queryByTestId("UpdateWalletName__input")).not.toBeInTheDocument();
});
});

it("should close modal on save", async () => {
render(<LedgerMigrationOverview profile={profile} transfer={transaction} />);

await userEvent.click(screen.getByTestId("LedgerMigration__Review-edit"));

await waitFor(() => {
expect(screen.getByTestId("UpdateWalletName__input")).toBeInTheDocument();
});

await userEvent.clear(screen.getByTestId("UpdateWalletName__input"));
await userEvent.type(screen.getByTestId("UpdateWalletName__input"), "Test Wallet");

await userEvent.click(screen.getByTestId("UpdateWalletName__submit"));

await waitFor(() => {
expect(screen.queryByTestId("UpdateWalletName__input")).not.toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { env, getMainsailProfileId, mockNanoSTransport, render, screen, waitFor } from "@/utils/testing-library";
import { expect, it, describe, beforeEach, afterAll, vi } from "vitest";
import { Contracts } from "@/app/lib/profiles";
import { MigrationLedgerScanStep } from "./LedgerMigrationScanStep";
import { Networks } from "@/app/lib/mainsail";

vi.mock("@/app/contexts/Ledger", () => ({
useLedgerScanner: vi.fn().mockReturnValue({
abortScanner: vi.fn(),
canRetry: true,
error: null,
isScanning: false,
isSelected: vi.fn().mockReturnValue(false),
loadedWallets: [
{
address: "0x125b484e51Ad990b5b3140931f3BD8eAee85Db23",
balance: "0",
path: "m/44'/1'/0'/0/0",
},
{
address: "0xcd15953dD076e56Dc6a5bc46Da23308Ff3158EE6",
balance: "100",
path: "m/44'/1'/0'/0/1",
},
{
address: "0xB64b3619cEF2642E36B6093da95BA2D14Fa9b52f",
balance: undefined as unknown as string,
path: "m/44'/1'/0'/0/2",
},
],
scan: vi.fn(),
selectedWallets: [
{
address: "0x125b484e51Ad990b5b3140931f3BD8eAee85Db23",
balance: "0",
path: "m/44'/1'/0'/0/0",
},
{
address: "0xcd15953dD076e56Dc6a5bc46Da23308Ff3158EE6",
balance: "100",
path: "m/44'/1'/0'/0/1",
},
{
address: "0xB64b3619cEF2642E36B6093da95BA2D14Fa9b52f",
balance: undefined as unknown as string,
path: "m/44'/1'/0'/0/2",
},
],
wallets: [
{
address: "0xcd15953dD076e56Dc6a5bc46Da23308Ff3158EE6",
balance: "100",
path: "m/44'/1'/0'/0/1",
},
],
}),
}));

describe("MigrationLedgerScanStep", () => {
let profile: Contracts.IProfile;
let network: Networks.Network;
let migrator: any;

beforeEach(async () => {
mockNanoSTransport();
profile = env.profiles().findById(getMainsailProfileId());
await env.profiles().restore(profile);
network = profile.wallets().first().network();

migrator = {
createTransactions: vi.fn().mockResolvedValue(undefined),
flushTransactions: vi.fn(),
};
});

afterAll(() => {
vi.restoreAllMocks();
});

it("should filter addresses with balance greater than zero", async () => {
const createTransactionsSpy = vi.spyOn(migrator, "createTransactions");

render(
<MigrationLedgerScanStep
migrator={migrator as any}
profile={profile}
network={network}
onContinue={vi.fn()}
/>,
);

await waitFor(() => {
expect(screen.getByTestId("LedgerScanStep")).toBeInTheDocument();
});

await waitFor(() => {
expect(createTransactionsSpy).toHaveBeenCalled();
});
});
});
Loading
Loading