File size: 1,513 Bytes
246d201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { describe, it, expect, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { ContextMenuListItem } from "#/components/features/context-menu/context-menu-list-item";

describe("ContextMenuListItem", () => {
  it("should render the component with the children", () => {
    const onClickMock = vi.fn();
    render(
      <ContextMenuListItem onClick={onClickMock}>Test</ContextMenuListItem>,
    );

    expect(screen.getByTestId("context-menu-list-item")).toBeInTheDocument();
    expect(screen.getByText("Test")).toBeInTheDocument();
  });

  it("should call the onClick callback when clicked", async () => {
    const user = userEvent.setup();
    const onClickMock = vi.fn();
    render(
      <ContextMenuListItem onClick={onClickMock}>Test</ContextMenuListItem>,
    );

    const element = screen.getByTestId("context-menu-list-item");
    await user.click(element);

    expect(onClickMock).toHaveBeenCalledOnce();
  });

  it("should not call the onClick callback when clicked and the button is disabled", async () => {
    const user = userEvent.setup();
    const onClickMock = vi.fn();
    render(
      <ContextMenuListItem onClick={onClickMock} isDisabled>

        Test

      </ContextMenuListItem>,
    );

    const element = screen.getByTestId("context-menu-list-item");
    await user.click(element);

    expect(onClickMock).not.toHaveBeenCalled();
  });
});