inputBox.test.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* eslint-disable no-undef */
  2. import React from 'react';
  3. import { cleanup } from '@testing-library/react';
  4. import '@testing-library/jest-dom';
  5. import testWrapper from '../helpers/testWrapper';
  6. import InputBox from '../components/InputBox';
  7. import TextareaBox from '../components/TextareaBox';
  8. describe('Input Box component', () => {
  9. afterEach(cleanup);
  10. test('input element', () => {
  11. const handleChange = (value: string) => {
  12. console.log(value);
  13. };
  14. const { container } = testWrapper(
  15. <InputBox value="test" onChange={handleChange} />,
  16. );
  17. const inputNode = container.querySelector('input') as HTMLElement;
  18. expect(inputNode.tagName).toBe('INPUT');
  19. });
  20. test('textarea element', () => {
  21. const handleChange = (value: string) => {
  22. console.log(value);
  23. };
  24. const { container } = testWrapper(
  25. <TextareaBox value="test" onChange={handleChange} />,
  26. );
  27. const textAreaNode = container.querySelector('TextArea') as HTMLElement;
  28. expect(textAreaNode.tagName).toBe('TEXTAREA');
  29. });
  30. test('test value', () => {
  31. const handleChange = (value: string) => {
  32. console.log(value);
  33. };
  34. const { container } = testWrapper(
  35. <InputBox value="test default value" onChange={handleChange} />,
  36. );
  37. const inputNode = container.querySelector('input') as HTMLInputElement;
  38. // fireEvent.change(inputNode, { target: { value: 'text' } });
  39. expect(inputNode.value).toBe('test default value');
  40. });
  41. test('check disabled input', () => {
  42. const handleChange = jest.fn();
  43. const { getByTestId } = testWrapper(
  44. <InputBox disabled value="" onChange={handleChange} />,
  45. );
  46. expect(handleChange).toBeCalledTimes(0);
  47. expect(getByTestId('input')).toBeDisabled();
  48. });
  49. });