@bigbinary/neetoui 3.2.73 → 3.2.74

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.74",
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
+ });
@@ -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,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
+ });