Skip to content

Commit

Permalink
Merge branch 'feat/evm' into feat/user-balance-and-hide-values
Browse files Browse the repository at this point in the history
  • Loading branch information
patricio0312rev committed Feb 12, 2025
2 parents 946f1b3 + 3562fd3 commit 4f0068f
Show file tree
Hide file tree
Showing 80 changed files with 5,782 additions and 14,530 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ jobs:
COVERAGE_THRESHOLD_LINES: 99.57
COVERAGE_THRESHOLD_FUNCTIONS: 98.3
COVERAGE_THRESHOLD_STATEMENTS: 99.6
COVERAGE_THRESHOLD_BRANCHES: 99.2
COVERAGE_THRESHOLD_BRANCHES: 99.17
COVERAGE_INCLUDE_PATH: src/domains/message
with:
timeout_minutes: 10
Expand Down Expand Up @@ -612,7 +612,7 @@ jobs:
run: pnpm rebuild
- name: Test
env:
COVERAGE_THRESHOLD_BRANCHES: 99.6
COVERAGE_THRESHOLD_BRANCHES: 99.24
uses: nick-invision/retry@v2
with:
timeout_minutes: 10
Expand Down Expand Up @@ -855,9 +855,9 @@ jobs:
- name: Test
uses: nick-invision/retry@v2
env:
COVERAGE_THRESHOLD_LINES: 96.44
COVERAGE_THRESHOLD_FUNCTIONS: 97.51
COVERAGE_THRESHOLD_STATEMENTS: 96.5
COVERAGE_THRESHOLD_LINES: 96.13
COVERAGE_THRESHOLD_FUNCTIONS: 97.34
COVERAGE_THRESHOLD_STATEMENTS: 96.21
COVERAGE_THRESHOLD_BRANCHES: 92.27
COVERAGE_INCLUDE_PATH: src/domains/wallet
with:
Expand Down
70 changes: 70 additions & 0 deletions src/app/App.restore.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Bcrypt } from "@ardenthq/sdk-cryptography";
import { createHashHistory } from "history";
import React from "react";
import userEvent from "@testing-library/user-event";
import { App } from "./App";
import { toasts } from "@/app/services";
import { translations as profileTranslations } from "@/domains/profile/i18n";
import { env, render, screen, waitFor } from "@/utils/testing-library";

const history = createHashHistory();

const passwordInput = () => screen.getByTestId("SignIn__input--password");

describe("App", () => {
afterEach(() => {
vi.restoreAllMocks();
process.env.MOCK_SYNCHRONIZER = undefined;
});

beforeEach(() => {
vi.spyOn(toasts, "dismiss").mockImplementation(vi.fn());

// Mock synchronizer to avoid running any jobs in these tests.
process.env.MOCK_SYNCHRONIZER = "TRUE";

history.replace("/");
env.reset();
});

it("should redirect to root if profile restoration error occurs", async () => {
process.env.TEST_PROFILES_RESTORE_STATUS = "restored";
process.env.REACT_APP_IS_UNIT = "1";

render(<App />, { history, withProviders: false });

await expect(
screen.findByText(profileTranslations.PAGE_WELCOME.WITH_PROFILES.TITLE, undefined),
).resolves.toBeVisible();

expect(history.location.pathname).toBe("/");

await userEvent.click(screen.getAllByTestId("ProfileRow__Link")[1]);

await waitFor(() => {
expect(passwordInput()).toBeInTheDocument();
});

await userEvent.clear(passwordInput());
await userEvent.type(passwordInput(), "password");

await waitFor(() => {
expect(passwordInput()).toHaveValue("password");
});

const profile = env.profiles().findById("cba050f1-880f-45f0-9af9-cfe48f406052");

const verifyPasswordMock = vi.spyOn(Bcrypt, "verify").mockReturnValue(true);
const memoryPasswordMock = vi.spyOn(profile.password(), "get").mockImplementation(() => {
throw new Error("password not found");
});

await userEvent.click(screen.getByTestId("SignIn__submit-button"));

await waitFor(() => expect(memoryPasswordMock).toHaveBeenCalled(), { timeout: 4000 });
await waitFor(() => expect(history.location.pathname).toBe("/"));

memoryPasswordMock.mockRestore();
verifyPasswordMock.mockRestore();
});
});
85 changes: 22 additions & 63 deletions src/app/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/require-await */
import { Bcrypt } from "@ardenthq/sdk-cryptography";
import { Contracts, Environment } from "@ardenthq/sdk-profiles";
import { createHashHistory } from "history";
import React from "react";
Expand Down Expand Up @@ -73,46 +72,6 @@ describe("App", () => {
env.reset();
});

it("should redirect to root if profile restoration error occurs", async () => {
process.env.REACT_APP_IS_UNIT = "1";

render(<App />, { history, withProviders: false });

await expect(
screen.findByText(profileTranslations.PAGE_WELCOME.WITH_PROFILES.TITLE, undefined),
).resolves.toBeVisible();

expect(history.location.pathname).toBe("/");

await userEvent.click(screen.getAllByTestId("ProfileRow__Link")[1]);

await waitFor(() => {
expect(passwordInput()).toBeInTheDocument();
});

await userEvent.clear(passwordInput());
await userEvent.type(passwordInput(), "password");

await waitFor(() => {
expect(passwordInput()).toHaveValue("password");
});

const profile = env.profiles().findById("cba050f1-880f-45f0-9af9-cfe48f406052");

const verifyPasswordMock = vi.spyOn(Bcrypt, "verify").mockReturnValue(true);
const memoryPasswordMock = vi.spyOn(profile.password(), "get").mockImplementation(() => {
throw new Error("password not found");
});

await userEvent.click(screen.getByTestId("SignIn__submit-button"));

await waitFor(() => expect(memoryPasswordMock).toHaveBeenCalled(), { timeout: 4000 });
await waitFor(() => expect(history.location.pathname).toBe("/"));

memoryPasswordMock.mockRestore();
verifyPasswordMock.mockRestore();
});

it("should render page skeleton", async () => {
const toastSuccessMock = vi.spyOn(toasts, "success").mockImplementation(vi.fn());
process.env.REACT_APP_IS_UNIT = "1";
Expand Down Expand Up @@ -257,15 +216,25 @@ describe("App", () => {
},
);

it("should enter profile", async () => {
it("should enter profile and fail to restore", async () => {
process.env.REACT_APP_IS_UNIT = "1";
process.env.TEST_PROFILES_RESTORE_STATUS = undefined;

render(<App />, { history, withProviders: false });

await expect(
screen.findByText(profileTranslations.PAGE_WELCOME.WITH_PROFILES.TITLE, undefined),
screen.findByText(profileTranslations.PAGE_WELCOME.WITH_PROFILES.TITLE, undefined, { timeout: 2000 }),
).resolves.toBeVisible();

const profile = env.profiles().findById("cba050f1-880f-45f0-9af9-cfe48f406052");

vi.spyOn(profile, "usesPassword").mockReturnValue(true);
vi.spyOn(profile.password(), "get").mockImplementation(() => {
throw new Error("Failed to restore");
});

await env.profiles().restore(passwordProtectedProfile, getDefaultPassword());

expect(history.location.pathname).toBe("/");

await userEvent.click(screen.getAllByTestId("ProfileRow__Link")[1]);
Expand All @@ -282,33 +251,27 @@ describe("App", () => {

const toastSpy = vi.spyOn(toasts, "dismiss").mockResolvedValue(undefined);

vi.spyOn(passwordProtectedProfile.password(), "get").mockImplementation(() => {
throw new Error("restore error");
});

await userEvent.click(screen.getByTestId("SignIn__submit-button"));

const profileDashboardUrl = `/profiles/${passwordProtectedProfile.id()}/dashboard`;
await waitFor(() => expect(history.location.pathname).toBe(profileDashboardUrl), { timeout: 4000 });
await waitFor(() => expect(history.location.pathname).toBe("/"), { timeout: 4000 });

toastSpy.mockRestore();
vi.restoreAllMocks();
});

it("should enter profile and fail to restore", async () => {
it("should enter profile", async () => {
process.env.REACT_APP_IS_UNIT = "1";
process.env.TEST_PROFILES_RESTORE_STATUS = undefined;

render(<App />, { history, withProviders: false });

await expect(
screen.findByText(profileTranslations.PAGE_WELCOME.WITH_PROFILES.TITLE, undefined, { timeout: 2000 }),
screen.findByText(profileTranslations.PAGE_WELCOME.WITH_PROFILES.TITLE, undefined),
).resolves.toBeVisible();

const profile = env.profiles().findById("cba050f1-880f-45f0-9af9-cfe48f406052");

vi.spyOn(profile, "usesPassword").mockReturnValue(true);
vi.spyOn(profile.password(), "get").mockImplementation(() => {
throw new Error("Failed to restore");
});

await env.profiles().restore(passwordProtectedProfile, getDefaultPassword());

expect(history.location.pathname).toBe("/");

await userEvent.click(screen.getAllByTestId("ProfileRow__Link")[1]);
Expand All @@ -325,15 +288,11 @@ describe("App", () => {

const toastSpy = vi.spyOn(toasts, "dismiss").mockResolvedValue(undefined);

vi.spyOn(passwordProtectedProfile.password(), "get").mockImplementation(() => {
throw new Error("restore error");
});

await userEvent.click(screen.getByTestId("SignIn__submit-button"));

await waitFor(() => expect(history.location.pathname).toBe("/"), { timeout: 4000 });
const profileDashboardUrl = `/profiles/${passwordProtectedProfile.id()}/dashboard`;
await waitFor(() => expect(history.location.pathname).toBe(profileDashboardUrl), { timeout: 4000 });

toastSpy.mockRestore();
vi.restoreAllMocks();
});
});
4 changes: 4 additions & 0 deletions src/app/assets/svg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ import List from "./list.svg?react";
import LoaderLogo from "./loader-logo.svg?react";
import Lock from "./lock.svg?react";
import MagnifyingGlass from "./magnifying-glass.svg?react";
import Mainnet from "./mainnet.svg?react";
import Testnet from "./testnet.svg?react";
import MagnifyingGlassAlt from "./magnifying-glass-alt.svg?react";
import MagnifyingGlassId from "./magnifying-glass-id.svg?react";
import Menu from "./menu.svg?react";
Expand Down Expand Up @@ -178,6 +180,7 @@ export const SvgCollection: Record<string, FC<SVGProps<SVGSVGElement>>> = {
MagnifyingGlass,
MagnifyingGlassAlt,
MagnifyingGlassId,
Mainnet,
Menu,
MenuOpen,
MoneyCoinSwap,
Expand All @@ -202,6 +205,7 @@ export const SvgCollection: Record<string, FC<SVGProps<SVGSVGElement>>> = {
StatusError,
StatusOk,
StatusStandby,
Testnet,
Trash,
UnderlineMoon,
UnderlineSun,
Expand Down
5 changes: 5 additions & 0 deletions src/app/assets/svg/mainnet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/app/assets/svg/testnet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/app/components/Dropdown/Dropdown.contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface DropdownProperties extends JSX.IntrinsicAttributes {
as?: React.ElementType;
children?: React.ReactElement;
top?: React.ReactNode;
bottom?: React.ReactNode;
onSelect?: OnSelectProperties;
variant?: DropdownVariantType;
options?: DropdownOption[] | DropdownOptionGroup[];
Expand Down
2 changes: 2 additions & 0 deletions src/app/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const Wrapper = ({ variant, ...props }: { variant: DropdownVariantType }
export const Dropdown: FC<DropdownProperties> = ({
children,
top,
bottom,
wrapperClass,
variant,
options,
Expand Down Expand Up @@ -132,6 +133,7 @@ export const Dropdown: FC<DropdownProperties> = ({
{top}
{options?.length && renderOptions({ onSelect: onSelectOption, options })}
{clonedElement && <div>{clonedElement}</div>}
{bottom}
</Wrapper>
</div>
</FloatingPortal>
Expand Down
Loading

0 comments on commit 4f0068f

Please sign in to comment.