Skip to content

Commit

Permalink
Update ErrorPage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asiia-trilitech committed Dec 3, 2024
1 parent eb80dba commit 0f09050
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions apps/desktop/src/components/ErrorPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ describe("ErrorPage", () => {
it("renders the error message and buttons", () => {
render(<ErrorPage />);

expect(screen.getByText("Oops! Something went wrong!")).toBeInTheDocument();
expect(screen.getByText("Oops! Something went wrong!")).toBeVisible();
expect(
screen.getByText("Please refresh the app or use one of the following options:")
).toBeInTheDocument();
).toBeVisible();
// Refresh link
expect(screen.getByRole("heading", { name: /Refresh/i })).toBeInTheDocument();
expect(screen.getByRole("heading", { name: "Refresh" })).toBeVisible();
// Action buttons
expect(screen.getByRole("button", { name: /Report Error/i })).toBeInTheDocument();
expect(screen.getByRole("button", { name: /Save Backup/i })).toBeInTheDocument();
expect(screen.getByRole("button", { name: /Off-board Wallet/i })).toBeInTheDocument();
const actionButtons = screen.getAllByRole("button");
expect(actionButtons.map(button => button.textContent)).toEqual(["Save Backup", "Report Error", "Off-board Wallet"]);
actionButtons.forEach(button => expect(button).toBeVisible());
});

it("calls saveBackup function when 'Save Backup' button is clicked", async () => {
const user = userEvent.setup();
render(<ErrorPage />);

const saveBackupButton = screen.getByRole("button", { name: /Save Backup/i });
const saveBackupButton = screen.getByRole("button", { name: "Save Backup" });
await act(() => user.click(saveBackupButton));

expect(mockSaveBackup).toHaveBeenCalledTimes(1);
Expand All @@ -49,7 +49,7 @@ describe("ErrorPage", () => {
const user = userEvent.setup();
render(<ErrorPage />);

const offboardButton = screen.getByRole("button", { name: /Off-board Wallet/i });
const offboardButton = screen.getByRole("button", { name: "Off-board Wallet" });
await act(() => user.click(offboardButton));

expect(mockOnOpenOffboarding).toHaveBeenCalledTimes(1);
Expand All @@ -58,7 +58,7 @@ describe("ErrorPage", () => {
it("renders the feedback email link correctly", () => {
render(<ErrorPage />);

const emailLink = screen.getByRole("link", { name: /Report Error/i });
const emailLink = screen.getByRole("link", { name: "Report Error" });
expect(emailLink).toHaveAttribute(
"href",
expect.stringContaining("mailto:[email protected]")
Expand All @@ -72,7 +72,7 @@ describe("ErrorPage", () => {

render(<ErrorPage />);

const refreshLink = screen.getByRole("heading", { name: /Refresh/i });
const refreshLink = screen.getByRole("heading", { name: "Refresh" });
await act(() => user.click(refreshLink));

expect(window.location.href).toBe("/");
Expand Down
18 changes: 9 additions & 9 deletions apps/web/src/components/ErrorPage/ErrorPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ describe("ErrorPage", () => {
it("renders the error message and buttons", () => {
render(<ErrorPage />);

expect(screen.getByText("Oops! Something went wrong!")).toBeInTheDocument();
expect(screen.getByText("Oops! Something went wrong!")).toBeVisible();
expect(
screen.getByText("Please refresh the page or use one of the following options:")
).toBeInTheDocument();
// Action buttons
expect(screen.getByRole("button", { name: /Report Error/i })).toBeInTheDocument();
expect(screen.getByRole("button", { name: /Save Backup/i })).toBeInTheDocument();
expect(screen.getByRole("button", { name: /Off-board Wallet/i })).toBeInTheDocument();
).toBeVisible();

const actionButtons = screen.getAllByRole("button");
expect(actionButtons.map(button => button.textContent)).toEqual(["Save Backup", "Report Error", "Logout"]);
actionButtons.forEach(button => expect(button).toBeVisible());
});

it("calls saveBackup function when 'Save Backup' button is clicked", async () => {
const { openWith } = dynamicModalContextMock;
const user = userEvent.setup();
render(<ErrorPage />);

const saveBackupButton = screen.getByRole("button", { name: /Save Backup/i });
const saveBackupButton = screen.getByRole("button", { name: "Save Backup" });
await act(() => user.click(saveBackupButton));

expect(openWith).toHaveBeenCalledWith(<SetupPassword mode="save_backup" />);
Expand All @@ -34,7 +34,7 @@ describe("ErrorPage", () => {
const user = userEvent.setup();
render(<ErrorPage />);

const offboardButton = screen.getByRole("button", { name: /Off-board Wallet/i });
const offboardButton = screen.getByRole("button", { name: "Logout" });
await act(() => user.click(offboardButton));

expect(openWith).toHaveBeenCalledWith(<LogoutModal />);
Expand All @@ -43,7 +43,7 @@ describe("ErrorPage", () => {
it("renders the feedback email link correctly", () => {
render(<ErrorPage />);

const emailLink = screen.getByRole("link", { name: /Report Error/i });
const emailLink = screen.getByRole("link", { name: "Report Error" });
expect(emailLink).toHaveAttribute(
"href",
expect.stringContaining("mailto:[email protected]")
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ErrorPage/ErrorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const ErrorPage = () => {
size="lg"
variant="alert"
>
Off-board Wallet
Logout
</Button>
</VStack>
</VStack>
Expand Down

0 comments on commit 0f09050

Please sign in to comment.