|
@@ -1,8 +1,9 @@
|
|
/* eslint-disable no-undef */
|
|
/* eslint-disable no-undef */
|
|
import React from 'react';
|
|
import React from 'react';
|
|
-import { render, cleanup, fireEvent } from '@testing-library/react';
|
|
|
|
|
|
+import { cleanup } from '@testing-library/react';
|
|
import '@testing-library/jest-dom';
|
|
import '@testing-library/jest-dom';
|
|
|
|
|
|
|
|
+import testWrapper from '../helpers/testWrapper';
|
|
import InputBox from '../components/InputBox';
|
|
import InputBox from '../components/InputBox';
|
|
import TextareaBox from '../components/TextareaBox';
|
|
import TextareaBox from '../components/TextareaBox';
|
|
|
|
|
|
@@ -10,31 +11,49 @@ describe('Input Box component', () => {
|
|
afterEach(cleanup);
|
|
afterEach(cleanup);
|
|
|
|
|
|
test('input element', () => {
|
|
test('input element', () => {
|
|
- const { container } = render(<InputBox />);
|
|
|
|
|
|
+ const handleChange = (value: string) => {
|
|
|
|
+ console.log(value);
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const { container } = testWrapper(
|
|
|
|
+ <InputBox value="test" onChange={handleChange} />,
|
|
|
|
+ );
|
|
const inputNode = container.querySelector('input') as HTMLElement;
|
|
const inputNode = container.querySelector('input') as HTMLElement;
|
|
expect(inputNode.tagName).toBe('INPUT');
|
|
expect(inputNode.tagName).toBe('INPUT');
|
|
});
|
|
});
|
|
|
|
|
|
test('textarea element', () => {
|
|
test('textarea element', () => {
|
|
- const { container } = render(<TextareaBox />);
|
|
|
|
|
|
+ const handleChange = (value: string) => {
|
|
|
|
+ console.log(value);
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const { container } = testWrapper(
|
|
|
|
+ <TextareaBox value="test" onChange={handleChange} />,
|
|
|
|
+ );
|
|
const textAreaNode = container.querySelector('TextArea') as HTMLElement;
|
|
const textAreaNode = container.querySelector('TextArea') as HTMLElement;
|
|
expect(textAreaNode.tagName).toBe('TEXTAREA');
|
|
expect(textAreaNode.tagName).toBe('TEXTAREA');
|
|
});
|
|
});
|
|
|
|
|
|
- test('onChange event', () => {
|
|
|
|
- const { container } = render(<InputBox />);
|
|
|
|
|
|
+ test('test value', () => {
|
|
|
|
+ const handleChange = (value: string) => {
|
|
|
|
+ console.log(value);
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const { container } = testWrapper(
|
|
|
|
+ <InputBox value="test default value" onChange={handleChange} />,
|
|
|
|
+ );
|
|
const inputNode = container.querySelector('input') as HTMLInputElement;
|
|
const inputNode = container.querySelector('input') as HTMLInputElement;
|
|
- fireEvent.change(inputNode, { target: { value: 'text' } });
|
|
|
|
|
|
|
|
- expect(inputNode.value).toBe('text');
|
|
|
|
|
|
+ // fireEvent.change(inputNode, { target: { value: 'text' } });
|
|
|
|
+
|
|
|
|
+ expect(inputNode.value).toBe('test default value');
|
|
});
|
|
});
|
|
|
|
|
|
test('check disabled input', () => {
|
|
test('check disabled input', () => {
|
|
const handleChange = jest.fn();
|
|
const handleChange = jest.fn();
|
|
- const { getByTestId } = render(
|
|
|
|
- <InputBox disabled onChange={handleChange} />,
|
|
|
|
|
|
+ const { getByTestId } = testWrapper(
|
|
|
|
+ <InputBox disabled value="" onChange={handleChange} />,
|
|
);
|
|
);
|
|
- fireEvent.change(getByTestId('input'), { target: { value: 'text' } });
|
|
|
|
|
|
|
|
expect(handleChange).toBeCalledTimes(0);
|
|
expect(handleChange).toBeCalledTimes(0);
|
|
expect(getByTestId('input')).toBeDisabled();
|
|
expect(getByTestId('input')).toBeDisabled();
|