File size: 1,429 Bytes
b59aa07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
56
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it, vi } from "vitest";
import { BrandButton } from "#/components/features/settings/brand-button";

describe("BrandButton", () => {
  const onClickMock = vi.fn();

  it("should set a test id", () => {
    render(
      <BrandButton testId="brand-button" type="button" variant="primary">
        Test Button
      </BrandButton>,
    );

    expect(screen.getByTestId("brand-button")).toBeInTheDocument();
  });

  it("should call onClick when clicked", async () => {
    const user = userEvent.setup();
    render(
      <BrandButton type="button" variant="primary" onClick={onClickMock}>
        Test Button
      </BrandButton>,
    );

    await user.click(screen.getByText("Test Button"));
  });

  it("should be disabled if isDisabled is true", () => {
    render(
      <BrandButton type="button" variant="primary" isDisabled>
        Test Button
      </BrandButton>,
    );

    expect(screen.getByText("Test Button")).toBeDisabled();
  });

  it("should pass a start content", () => {
    render(
      <BrandButton
        type="button"
        variant="primary"
        startContent={
          <div data-testid="custom-start-content">Start Content</div>
        }
      >
        Test Button
      </BrandButton>,
    );

    screen.getByTestId("custom-start-content");
  });
});