Skip to content

Commit

Permalink
feat: mock useDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-hosseini-deriv committed May 10, 2024
1 parent d5493fe commit 87a98d7
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/components/AppLayout/Notifications/__test__/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import React from "react";
import { render, fireEvent } from "@testing-library/react";
import { render } from "@testing-library/react";
import { Notifications } from "..";

import userEvent from "@testing-library/user-event";
// Mocking the useDevice hook
jest.mock("../../../../hooks", () => ({
useDevice: jest.fn().mockReturnValue({ isMobile: false }),
}));
describe("Notifications Component", () => {
it("renders multiple notifications with their respective properties", () => {
it("renders multiple notifications with their respective properties", async () => {
const mockAction1 = jest.fn();
const mockAction2 = jest.fn();
const notifications = [
Expand All @@ -24,7 +28,15 @@ describe("Notifications Component", () => {
];

const { getByText, getAllByRole } = render(
<Notifications notifications={notifications} />,
<Notifications
notifications={notifications}
clearNotificationsCallback={() => {}}
isNotificationsVisible={true}
componentConfig={{
clearButtonText: "Clear all",
modalTitle: "Notifications",
}}
/>,
);

// Check if the title, message, and button for each notification are in the document
Expand All @@ -36,9 +48,9 @@ describe("Notifications Component", () => {

// Check if buttons are clickable and actions are called
const buttons = getAllByRole("button");
fireEvent.click(buttons[0]);
await userEvent.click(buttons[0]);
expect(mockAction1).toHaveBeenCalled();
fireEvent.click(buttons[1]);
await userEvent.click(buttons[1]);
expect(mockAction2).toHaveBeenCalled();
});
});

0 comments on commit 87a98d7

Please sign in to comment.