@bigbinary/neetoui 3.2.73 → 3.2.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/neetoui",
3
- "version": "3.2.73",
3
+ "version": "3.2.76",
4
4
  "main": "./index.js",
5
5
  "author": "BigBinary",
6
6
  "license": "MIT",
@@ -0,0 +1,111 @@
1
+ import React from "react";
2
+ import { fireEvent, render, screen } from "@testing-library/react";
3
+
4
+ import dayjs from "dayjs";
5
+ import DatePicker from "../lib/components/DatePicker";
6
+
7
+ const today = dayjs();
8
+ const tomorrow = dayjs().add(1, "day");
9
+
10
+ describe("DatePicker", () => {
11
+ it("should render without error", () => {
12
+ render(<DatePicker defaultValue={today} />);
13
+ expect(screen.getByRole("textbox")).toHaveValue(today.format("DD/MM/YYYY"));
14
+ });
15
+
16
+ it("should show label if label is provided", () => {
17
+ render(<DatePicker label="DatePicker Label" />);
18
+ expect(screen.getByText("DatePicker Label")).toBeInTheDocument();
19
+ });
20
+
21
+ it("should show error if error is provided", () => {
22
+ render(<DatePicker error="DatePicker Error" />);
23
+ expect(screen.getByText("DatePicker Error")).toBeInTheDocument();
24
+ });
25
+
26
+ it("should render time if showTime is true", async () => {
27
+ render(<DatePicker defaultValue={today} showTime open />);
28
+ expect(await screen.findAllByText("00")).toHaveLength(3);
29
+ });
30
+
31
+ it("should show only hours if format is HH", async () => {
32
+ render(<DatePicker defaultValue={today} timeFormat="HH" showTime open />);
33
+ expect(await screen.findAllByText("00")).toHaveLength(1);
34
+ });
35
+
36
+ it("should show only hours and minutes if format is MM", async () => {
37
+ render(
38
+ <DatePicker defaultValue={today} timeFormat="HH:mm" showTime open />
39
+ );
40
+ expect(await screen.findAllByText("00")).toHaveLength(2);
41
+ });
42
+
43
+ it("should return date in the given format", async () => {
44
+ render(
45
+ <DatePicker
46
+ defaultValue={dayjs("2022-05-24", "YYYY-MM-DD")}
47
+ format="DD/MM/YYYY"
48
+ />
49
+ );
50
+ expect(screen.getByRole("textbox")).toHaveValue("24/05/2022");
51
+ });
52
+
53
+ it("should return date time in the given format", async () => {
54
+ render(
55
+ <DatePicker
56
+ defaultValue={dayjs("2022-05-24", "YYYY-MM-DD")
57
+ .hour(12)
58
+ .minute(30)
59
+ .second(0)}
60
+ format="DD/MM/YYYY HH:mm"
61
+ showTime
62
+ />
63
+ );
64
+ expect(screen.getByRole("textbox")).toHaveValue("24/05/2022 12:30");
65
+ });
66
+
67
+ it("should trigger onChange on selecting a date", () => {
68
+ const onChange = jest.fn();
69
+ render(<DatePicker defaultValue={today} onChange={onChange} open />);
70
+ fireEvent.click(screen.getByText(tomorrow.get("D")));
71
+ expect(onChange).toHaveBeenCalled();
72
+ });
73
+
74
+ it("should trigger onOk method on clicking on ok button", () => {
75
+ const onOk = jest.fn();
76
+ render(<DatePicker open showTime defaultValue={today} onOk={onOk} />);
77
+ fireEvent.click(screen.getByText("Ok"));
78
+ expect(onOk).toHaveBeenCalled();
79
+ });
80
+
81
+ it("should show 12 hour format if timeFormat is in 12 hr format", () => {
82
+ render(
83
+ <DatePicker
84
+ defaultValue={dayjs("12/04/2022", "DD/MM/YYYY").hour(14).minute(30)}
85
+ dateFormat="DD/MM/YYYY"
86
+ showTime
87
+ timeFormat="h:mm A"
88
+ open
89
+ />
90
+ );
91
+ expect(screen.getByRole("textbox")).toHaveValue("12/04/2022 2:30 PM");
92
+ });
93
+
94
+ it("should be able to select date in a range", () => {
95
+ render(
96
+ <DatePicker
97
+ defaultValue={[
98
+ dayjs("12/04/2022", "DD/MM/YYYY"),
99
+ dayjs("14/04/2022", "DD/MM/YYYY"),
100
+ ]}
101
+ type="range"
102
+ open
103
+ />
104
+ );
105
+ fireEvent.click(screen.getAllByText("11")[0]);
106
+ fireEvent.click(screen.getAllByText("16")[1]);
107
+ const dateInputBox = screen.getAllByRole("textbox");
108
+ expect(dateInputBox[0]).toHaveValue("11/04/2022");
109
+ expect(dateInputBox[1]).toHaveValue("16/05/2022");
110
+ });
111
+ });
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import { Dropdown } from "../lib/components";
3
- import { fireEvent, render, screen } from "@testing-library/react";
3
+ import { render, screen } from "@testing-library/react";
4
4
  import userEvent from "@testing-library/user-event";
5
5
 
6
6
  const options = ["option 1", "option 2"].map(option => <li key={option}>{option}</li>)
@@ -0,0 +1,166 @@
1
+ import React from "react";
2
+ import { EmailInput } from "../lib/components";
3
+ import { render, screen } from "@testing-library/react";
4
+ import userEvent from "@testing-library/user-event";
5
+
6
+ describe("EmailInput", () => {
7
+ it("should render without error", () => {
8
+ render(<EmailInput />);
9
+ expect(screen.getByText("Email(s)")).toBeInTheDocument();
10
+ });
11
+
12
+ it("should display helpText", () => {
13
+ render(<EmailInput helpText="Help text" />);
14
+ expect(screen.getByText("Help text")).toBeInTheDocument();
15
+ });
16
+
17
+ it("should display error message", () => {
18
+ render(<EmailInput error="Error message" />);
19
+ expect(screen.getByText("Error message")).toBeInTheDocument();
20
+ });
21
+
22
+ it("should render correct number of emails", () => {
23
+ render(
24
+ <EmailInput
25
+ value={[
26
+ { label: "test@example.com", value: "test@example.com", valid: true },
27
+ ]}
28
+ counter={{ label: "email" }}
29
+ />
30
+ );
31
+ expect(screen.getByText("1 email")).toBeInTheDocument();
32
+ });
33
+
34
+ it("should render default counter text when no label is provided", () => {
35
+ const { rerender } = render(
36
+ <EmailInput
37
+ value={[
38
+ { label: "test@example.com", value: "test@example.com", valid: true },
39
+ ]}
40
+ counter={{}}
41
+ />
42
+ );
43
+ expect(screen.getByText("1 email")).toBeInTheDocument();
44
+ rerender(<EmailInput
45
+ value={[
46
+ { label: "test@example.com", value: "test@example.com", valid: true },
47
+ { label: "test2@example.com", value: "test2@example.com", valid: true },
48
+ ]}
49
+ counter={{}}
50
+ />);
51
+ expect(screen.getByText("2 emails")).toBeInTheDocument();
52
+ });
53
+
54
+ it("should call onBlur when focus from the input field changes", () => {
55
+ const onBlur = jest.fn();
56
+ render(<EmailInput onBlur={onBlur} />);
57
+ const emailInput = screen.getByRole("combobox");
58
+ userEvent.click(emailInput);
59
+ userEvent.click(document.body);
60
+ expect(onBlur).toHaveBeenCalledTimes(1);
61
+ });
62
+
63
+ it("should call onChange when input loses focus after entering email", () => {
64
+ const onChange = jest.fn();
65
+ render(<EmailInput onChange={onChange} />);
66
+ const emailInput = screen.getByRole("combobox");
67
+ userEvent.paste(emailInput, "test@email.com test2@email.com");
68
+ userEvent.click(document.body);
69
+ expect(onChange).toHaveBeenCalledTimes(1);
70
+ expect(onChange).toHaveBeenCalledWith([
71
+ { label: "test@email.com", valid: true, value: "test@email.com" },
72
+ { label: "test2@email.com", valid: true, value: "test2@email.com" },
73
+ ]);
74
+ });
75
+
76
+ it("should call onInputChange when email input value changes", () => {
77
+ const onInputChange = jest.fn();
78
+ render(<EmailInput onInputChange={onInputChange} />);
79
+ const emailInput = screen.getByRole("combobox");
80
+ userEvent.type(emailInput, "test");
81
+ expect(onInputChange).toHaveBeenCalledTimes(4);
82
+ });
83
+
84
+ it("should call onChange when Enter key is pressed", () => {
85
+ const onChange = jest.fn();
86
+ render(<EmailInput onChange={onChange} />);
87
+ const emailInput = screen.getByRole("combobox");
88
+ userEvent.type(emailInput, "email@domain.com{enter}");
89
+ expect(onChange).toHaveBeenCalledTimes(1);
90
+ expect(onChange).toHaveBeenCalledWith([
91
+ { label: "email@domain.com", valid: true, value: "email@domain.com" },
92
+ ]);
93
+ });
94
+
95
+ it("should call onChange when Space key is pressed", () => {
96
+ const onChange = jest.fn();
97
+ render(<EmailInput onChange={onChange} />);
98
+ const emailInput = screen.getByRole("combobox");
99
+ userEvent.type(emailInput, "email@domain.com{space}");
100
+ expect(onChange).toHaveBeenCalledTimes(1);
101
+ expect(onChange).toHaveBeenCalledWith([
102
+ { label: "email@domain.com", valid: true, value: "email@domain.com" },
103
+ ]);
104
+ });
105
+
106
+ it("should call onChange when Tab key is pressed", () => {
107
+ const onChange = jest.fn();
108
+ render(<EmailInput onChange={onChange} />);
109
+ const emailInput = screen.getByRole("combobox");
110
+ userEvent.type(emailInput, "email@domain.com");
111
+ userEvent.tab();
112
+ expect(onChange).toHaveBeenCalledTimes(1);
113
+ expect(onChange).toHaveBeenCalledWith([
114
+ { label: "email@domain.com", valid: true, value: "email@domain.com" },
115
+ ]);
116
+ });
117
+
118
+ it("should call onChange when comma key is pressed", () => {
119
+ const onChange = jest.fn();
120
+ render(<EmailInput onChange={onChange} />);
121
+ const emailInput = screen.getByRole("combobox");
122
+ userEvent.type(emailInput, "email@domain.com,");
123
+ expect(onChange).toHaveBeenCalledTimes(1);
124
+ expect(onChange).toHaveBeenCalledWith([
125
+ { label: "email@domain.com", valid: true, value: "email@domain.com" },
126
+ ]);
127
+ });
128
+
129
+ it("should remove all invalid emails on clicking filterInvalidEmails label", () => {
130
+ const onChange = jest.fn();
131
+ render(
132
+ <EmailInput
133
+ onChange={onChange}
134
+ value={[
135
+ { label: "test@example.com", value: "test@example.com", valid: true },
136
+ { label: "invalidEmail", value: "invalidEmail" },
137
+ ]}
138
+ filterInvalidEmails={{
139
+ label: "Filter invalid emails",
140
+ }}
141
+ error="Invalid email"
142
+ />
143
+ );
144
+ userEvent.click(screen.getByText("Filter invalid emails"));
145
+ expect(onChange).toHaveBeenCalledTimes(1);
146
+ expect(onChange).toHaveBeenCalledWith([
147
+ { label: "test@example.com", value: "test@example.com", valid: true },
148
+ ]);
149
+ });
150
+
151
+ it("should display filterInvalidEmails label if no label is provided", () => {
152
+ const onChange = jest.fn();
153
+ render(
154
+ <EmailInput
155
+ onChange={onChange}
156
+ value={[
157
+ { label: "test@example.com", value: "test@example.com", valid: true },
158
+ { label: "invalidEmail", value: "invalidEmail" },
159
+ ]}
160
+ filterInvalidEmails={{}}
161
+ error="Invalid email"
162
+ />
163
+ );
164
+ expect(screen.getByText("Click here to remove invalid emails.")).toBeInTheDocument();
165
+ });
166
+ });
@@ -0,0 +1,61 @@
1
+ import React from "react";
2
+ import { render } from "@testing-library/react";
3
+ import Label from "../lib/components/Label";
4
+ import userEvent from "@testing-library/user-event";
5
+
6
+ describe("Label", () => {
7
+ it("should render without error", () => {
8
+ const { getByText } = render(<Label>Content</Label>);
9
+ expect(getByText("Content")).toBeInTheDocument();
10
+ });
11
+
12
+ it("should show * when required prop is provided", () => {
13
+ const { getByText } = render(
14
+ <Label required>
15
+ <p>Content</p>
16
+ </Label>
17
+ );
18
+ expect(getByText("Content")).toBeInTheDocument();
19
+ expect(getByText("*")).toBeInTheDocument();
20
+ });
21
+
22
+ it("should show info icon by default when helpIconProps is provided", () => {
23
+ const { getByTestId } = render(
24
+ <Label helpIconProps={{ "data-testid": "icon" }}>
25
+ <p>Content</p>
26
+ </Label>
27
+ );
28
+ expect(getByTestId("icon")).toBeInTheDocument();
29
+ });
30
+
31
+ it("should show tooltip when provided in helpIconProps", () => {
32
+ const { getByText, getByTestId } = render(
33
+ <Label
34
+ helpIconProps={{
35
+ tooltipProps: { content: "Tooltip" },
36
+ "data-testid": "icon"
37
+ }}
38
+ >
39
+ <p>Content</p>
40
+ </Label>
41
+ );
42
+ userEvent.hover(getByTestId("icon"));
43
+ expect(getByText("Tooltip")).toBeInTheDocument();
44
+ });
45
+
46
+ it("should trigger onClick when provided in helpIconProps", () => {
47
+ const onClick = jest.fn();
48
+ const { getByTestId } = render(
49
+ <Label
50
+ helpIconProps={{
51
+ onClick,
52
+ "data-testid": "icon"
53
+ }}
54
+ >
55
+ <p>Content</p>
56
+ </Label>
57
+ );
58
+ userEvent.click(getByTestId("icon"));
59
+ expect(onClick).toHaveBeenCalledTimes(1);
60
+ });
61
+ });
@@ -0,0 +1,125 @@
1
+ import React from "react";
2
+ import { Pagination } from "../lib/components";
3
+ import { render } from "@testing-library/react";
4
+ import userEvent from "@testing-library/user-event";
5
+
6
+ const currentPage = 3
7
+ const count = 1000
8
+ const pageSize = 100
9
+
10
+ describe("Pagination", () => {
11
+ it("should render current page number without error", () => {
12
+ const { getByText } = render(
13
+ <Pagination
14
+ count={count}
15
+ pageNo={currentPage}
16
+ pageSize={pageSize}
17
+ />
18
+ );
19
+ expect(getByText(currentPage)).toBeInTheDocument();
20
+ });
21
+
22
+ it("should invoke navigate callback when the left navigate button is clicked.", () => {
23
+ const navigate = jest.fn()
24
+ const { getByTestId } = render(
25
+ <Pagination
26
+ count={count}
27
+ pageNo={currentPage}
28
+ pageSize={pageSize}
29
+ navigate={navigate}
30
+ />
31
+ );
32
+ userEvent.click(getByTestId("left-navigate-button"));
33
+ expect(navigate).toHaveBeenCalledTimes(1);
34
+ expect(navigate).toHaveBeenCalledWith(currentPage - 1);
35
+ });
36
+
37
+ it("should invoke navigate callback when the right navigate button is clicked.", () => {
38
+ const navigate = jest.fn()
39
+ const { getByTestId } = render(
40
+ <Pagination
41
+ count={count}
42
+ pageNo={currentPage}
43
+ pageSize={pageSize}
44
+ navigate={navigate}
45
+ />
46
+ );
47
+ userEvent.click(getByTestId("right-navigate-button"));
48
+ expect(navigate).toHaveBeenCalledTimes(1);
49
+ expect(navigate).toHaveBeenCalledWith(currentPage + 1);
50
+ });
51
+
52
+ it("should invoke navigate callback when any page number is clicked.", () => {
53
+ const navigate = jest.fn()
54
+ const { getByText } = render(
55
+ <Pagination
56
+ count={count}
57
+ pageNo={currentPage}
58
+ pageSize={pageSize}
59
+ navigate={navigate}
60
+ />
61
+ );
62
+ userEvent.click(getByText("4"));
63
+ expect(navigate).toHaveBeenCalledTimes(1);
64
+ expect(navigate).toHaveBeenCalledWith(4);
65
+ });
66
+
67
+ it("should not render anything when currentPage is 0", () => {
68
+ const { container } = render(
69
+ <Pagination
70
+ count={count}
71
+ pageNo={0}
72
+ pageSize={pageSize}
73
+ />
74
+ )
75
+ expect(container.firstChild).toBeNull();
76
+ });
77
+
78
+ it("should render only left dots when there are more than 1 page between the extremes of left sibling and the page limit", () => {
79
+ const { getByTestId } = render(
80
+ <Pagination
81
+ count={count}
82
+ pageNo={7}
83
+ pageSize={pageSize}
84
+ />
85
+ )
86
+ const dots = getByTestId("dots")
87
+ expect(dots).toBeInTheDocument()
88
+ });
89
+
90
+ it("should render only right dots when there are more than 1 page between the extremes of right sibling and the page limit", () => {
91
+ const { getByTestId } = render(
92
+ <Pagination
93
+ count={count}
94
+ pageNo={3}
95
+ pageSize={pageSize}
96
+ />
97
+ )
98
+ const dots = getByTestId("dots")
99
+ expect(dots).toBeInTheDocument()
100
+ });
101
+
102
+ it("should render both left and right dots when there are more than 1 page between the extremes of both siblings and the page limit", () => {
103
+ const { getAllByTestId } = render(
104
+ <Pagination
105
+ count={count}
106
+ pageNo={5}
107
+ pageSize={pageSize}
108
+ />
109
+ )
110
+ const dots = getAllByTestId("dots")
111
+ expect(dots.length).toBe(2)
112
+ });
113
+
114
+ it("should not render any dots if the number of pages is less than the page numbers we want to show ", () => {
115
+ const { queryByTestId } = render(
116
+ <Pagination
117
+ count={500}
118
+ pageNo={currentPage}
119
+ pageSize={pageSize}
120
+ />
121
+ )
122
+ const dots = queryByTestId("dots")
123
+ expect(dots).toBeNull()
124
+ });
125
+ });
@@ -0,0 +1,83 @@
1
+ import React, { useState } from "react";
2
+ import { Radio } from "../lib/components";
3
+ import { render } from "@testing-library/react";
4
+ import userEvent from "@testing-library/user-event";
5
+
6
+ const ControlledRadio = () => {
7
+ const [value, setValue] = useState("");
8
+
9
+ return (
10
+ <Radio
11
+ label="Radio"
12
+ onChange={(e) => setValue(e.target.value)}
13
+ value={value}
14
+ >
15
+ <Radio.Item label="option1" name="options" value="option1" />
16
+ <Radio.Item label="option2" name="options" value="option2" />
17
+ </Radio>
18
+ );
19
+ };
20
+
21
+ describe("Radio", () => {
22
+ it("should render without error", () => {
23
+ const { getByText } = render(
24
+ <Radio label="Radio">
25
+ <Radio.Item label="option1" name="options" value="option1" />
26
+ </Radio>
27
+ );
28
+ expect(getByText("Radio")).toBeInTheDocument();
29
+ });
30
+
31
+ it("should call onChange when radio value is changed", () => {
32
+ const onChange = jest.fn((event) => {
33
+ expect(event.target.value).toBe("option1");
34
+ });
35
+ const { getByText } = render(
36
+ <Radio label="Radio" onChange={onChange}>
37
+ <Radio.Item label="option1" name="options" value="option1" />
38
+ </Radio>
39
+ );
40
+ userEvent.click(getByText("option1"));
41
+ expect(onChange).toHaveBeenCalledTimes(1);
42
+ });
43
+
44
+ it("should display error message", () => {
45
+ const { getByText } = render(
46
+ <Radio label="Radio" error="Error message">
47
+ <Radio.Item label="option1" name="options" value="option1" />
48
+ </Radio>
49
+ );
50
+ expect(getByText("Error message")).toBeInTheDocument();
51
+ });
52
+
53
+ it("should be unchecked by default", () => {
54
+ const { getByRole } = render(
55
+ <Radio label="Radio">
56
+ <Radio.Item label="option1" name="options" value="option1" />
57
+ </Radio>
58
+ );
59
+ expect(getByRole("radio")).not.toBeChecked();
60
+ });
61
+
62
+ it("should show controlled behaviour", () => {
63
+ const { getAllByRole } = render(<ControlledRadio />);
64
+ const radio = getAllByRole("radio");
65
+ userEvent.click(radio[0]);
66
+ expect(radio[0]).toBeChecked();
67
+ expect(radio[1]).not.toBeChecked();
68
+ userEvent.click(radio[1]);
69
+ expect(radio[0]).not.toBeChecked();
70
+ expect(radio[1]).toBeChecked();
71
+ });
72
+
73
+ it("should be checked on clicking the radio item", () => {
74
+ const { getByRole } = render(
75
+ <Radio label="Radio">
76
+ <Radio.Item label="option1" name="options" value="option1" />
77
+ </Radio>
78
+ );
79
+ const radio = getByRole("radio");
80
+ userEvent.click(radio);
81
+ expect(radio).toBeChecked();
82
+ });
83
+ });
@@ -0,0 +1,61 @@
1
+ import React from "react";
2
+ import { Switch } from "../lib/components";
3
+ import { render } from "@testing-library/react";
4
+ import userEvent from "@testing-library/user-event";
5
+
6
+ describe("Switch", () => {
7
+ it("should render without error", () => {
8
+ const { getByRole } = render(<Switch />);
9
+ const switchButton = getByRole("checkbox");
10
+ expect(switchButton).toBeInTheDocument();
11
+ });
12
+
13
+ it("should be unchecked by default", () => {
14
+ const { getByRole } = render(<Switch />);
15
+ const switchButton = getByRole("checkbox");
16
+ expect(switchButton).not.toBeChecked();
17
+ });
18
+
19
+ it("should be checked on clicking the checkbox", () => {
20
+ const { getByRole } = render(<Switch />);
21
+ const switchButton = getByRole("checkbox");
22
+ userEvent.click(switchButton);
23
+ expect(switchButton).toBeChecked();
24
+ });
25
+
26
+ it("should render label", () => {
27
+ const { getByText } = render(<Switch label="Switch" />);
28
+ const label = getByText("Switch");
29
+ expect(label).toBeInTheDocument();
30
+ });
31
+
32
+ it("should render asterisk when required is set to true", () => {
33
+ const { getByText } = render(<Switch required label="Switch" />);
34
+ const asterisk = getByText("*");
35
+ expect(asterisk).toBeInTheDocument();
36
+ });
37
+
38
+ it("should display error message", () => {
39
+ const { getByText } = render(<Switch error="Error message" />);
40
+ const errorMessage = getByText("Error message");
41
+ expect(errorMessage).toBeInTheDocument();
42
+ });
43
+
44
+ it("should be disabled if disabled is true", () => {
45
+ const { getByRole } = render(<Switch disabled />);
46
+ const switchButton = getByRole("checkbox");
47
+ expect(switchButton).toBeDisabled();
48
+ });
49
+
50
+ it("should render check icon icon when checked is true", () => {
51
+ const { getByTestId } = render(<Switch checked />);
52
+ const checkIcon = getByTestId("check-icon");
53
+ expect(checkIcon).toBeInTheDocument();
54
+ });
55
+
56
+ it("should render close icon icon when checked is false", () => {
57
+ const { getByTestId } = render(<Switch checked={false} />);
58
+ const closeIcon = getByTestId("close-icon");
59
+ expect(closeIcon).toBeInTheDocument();
60
+ });
61
+ });
@@ -0,0 +1,60 @@
1
+ import React from "react";
2
+ import { render, screen } from "@testing-library/react";
3
+ import userEvent from "@testing-library/user-event";
4
+ import { Tab } from "../lib/components";
5
+ import { BrowserRouter } from "react-router-dom";
6
+
7
+ describe("Tab", () => {
8
+ it("should render without error", () => {
9
+ render(
10
+ <Tab>
11
+ <Tab.Item>Tab 1</Tab.Item>
12
+ <Tab.Item>Tab 2</Tab.Item>
13
+ </Tab>
14
+ );
15
+ expect(screen.getByText("Tab 1")).toBeInTheDocument();
16
+ expect(screen.getByText("Tab 2")).toBeInTheDocument();
17
+ });
18
+
19
+ it("should render a link when activeClassName is provided", () => {
20
+ render(<BrowserRouter>
21
+ <Tab>
22
+ <Tab.Item activeClassName="active" to="/route">Tab 1</Tab.Item>
23
+ <Tab.Item>Tab 2</Tab.Item>
24
+ </Tab>
25
+ </BrowserRouter>);
26
+ expect(screen.getByRole("link")).toBeInTheDocument();
27
+ expect(screen.getByRole("link")).toHaveAttribute("href", "/route");
28
+ });
29
+
30
+ it("should render icon when provided", () => {
31
+ render(<Tab>
32
+ <Tab.Item icon={() => <svg data-testid="svg-icon" />}>Tab 1</Tab.Item>
33
+ </Tab>);
34
+ expect(screen.getByTestId("svg-icon")).toBeInTheDocument();
35
+ });
36
+
37
+ it("should render icon when icon className is provided", () => {
38
+ render(<Tab>
39
+ <Tab.Item icon="icon">Tab 1</Tab.Item>
40
+ </Tab>);
41
+ expect(screen.getByTestId("tab-icon")).toBeInTheDocument();
42
+ });
43
+
44
+ it("should call onClick when clicked on Tab", () => {
45
+ const onClick = jest.fn();
46
+ render(<Tab>
47
+ <Tab.Item icon="icon" onClick={onClick}>Tab 1</Tab.Item>
48
+ </Tab>);
49
+ userEvent.click(screen.getByText("Tab 1"));
50
+ expect(onClick).toHaveBeenCalled();
51
+ });
52
+
53
+ it("should make the tab active when active prop is true", () => {
54
+ render(<Tab>
55
+ <Tab.Item active>Tab 1</Tab.Item>
56
+ <Tab.Item>Tab 2</Tab.Item>
57
+ </Tab>);
58
+ expect(screen.getByText("Tab 1")).toHaveClass("active");
59
+ });
60
+ });