-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.test.tsx
More file actions
49 lines (47 loc) · 1.81 KB
/
input.test.tsx
File metadata and controls
49 lines (47 loc) · 1.81 KB
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
import React from "react";
import { render, fireEvent, queryByText } from "@testing-library/react";
import Input, { InputProps } from "./input";
const defaultProps: InputProps = {
onChange: jest.fn(),
placeholder: "test-input",
};
describe("test Input component", () => {
it("should render the correct default Input", () => {
const wrapper = render(<Input {...defaultProps} />);
const testNode = wrapper.getByPlaceholderText(
"test-input"
) as HTMLInputElement;
expect(testNode).toBeInTheDocument();
expect(testNode).toHaveClass("viking-input-inner");
fireEvent.change(testNode, { target: { value: "23" } });
expect(defaultProps.onChange).toHaveBeenCalled();
expect(testNode.value).toEqual("23");
});
it("should render the disabled Input on disabled property", () => {
const wrapper = render(<Input disabled placeholder="test-input" />);
const testNode = wrapper.getByPlaceholderText(
"test-input"
) as HTMLInputElement;
expect(testNode.disabled).toBeTruthy();
});
it("should render different input sizes on size property", () => {
const wrapper = render(<Input placeholder="sizes" size="lg" />);
const testCntainer = wrapper.container.querySelector(
".viking-input-wrapper"
);
expect(testCntainer).toHaveClass("input-size-lg");
});
it("should render prepand abd append element on prepend/append property", () => {
const wrapper = render(
<Input placeholder="pend" prepend="https://" append=".com" />
);
const testContainer = wrapper.container.querySelector(
".viking-input-wrapper"
);
expect(testContainer).toHaveClass(
"input-group input-group-append input-group-prepend"
);
expect(wrapper.queryByText("https://")).toBeInTheDocument();
expect(wrapper.queryByText(".com")).toBeInTheDocument();
});
});