Website for showcasing all features of Tesseract Web.
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

196 lines
4.4 KiB

  1. import * as React from 'react';
  2. import {
  3. render,
  4. screen
  5. } from '@testing-library/react';
  6. import '@testing-library/jest-dom';
  7. import userEvent from '@testing-library/user-event';
  8. import * as TextControlBase from '@tesseract-design/web-base-textcontrol';
  9. import {
  10. MultilineTextInput
  11. } from '.';
  12. jest.mock('@tesseract-design/web-base-textcontrol');
  13. describe('MultilineTextInput', () => {
  14. it('should render a textbox', () => {
  15. render(<MultilineTextInput />);
  16. const textbox: HTMLTextAreaElement = screen.getByRole('textbox');
  17. expect(textbox).toBeInTheDocument();
  18. });
  19. it('should render a border', () => {
  20. render(
  21. <MultilineTextInput
  22. border
  23. />
  24. );
  25. const border = screen.getByTestId('border');
  26. expect(border).toBeInTheDocument();
  27. });
  28. it('should render a label', () => {
  29. render(
  30. <MultilineTextInput
  31. label="foo"
  32. />
  33. );
  34. const textbox = screen.getByLabelText('foo');
  35. expect(textbox).toBeInTheDocument();
  36. const label = screen.getByTestId('label');
  37. expect(label).toHaveTextContent('foo');
  38. });
  39. it('should render a hidden label', () => {
  40. render(
  41. <MultilineTextInput
  42. label="foo"
  43. hiddenLabel
  44. />
  45. );
  46. const textbox = screen.getByLabelText('foo');
  47. expect(textbox).toBeInTheDocument();
  48. const label = screen.queryByTestId('label');
  49. expect(label).toBeNull();
  50. });
  51. it('should render a hint', () => {
  52. render(
  53. <MultilineTextInput
  54. hint="foo"
  55. />
  56. );
  57. const hint = screen.getByTestId('hint');
  58. expect(hint).toBeInTheDocument();
  59. });
  60. it('should render an indicator', () => {
  61. render(
  62. <MultilineTextInput
  63. indicator={
  64. <div data-testid="indicator" />
  65. }
  66. />
  67. );
  68. const indicator = screen.getByTestId('indicator');
  69. expect(indicator).toBeInTheDocument();
  70. });
  71. describe.each([
  72. TextControlBase.TextControlSize.SMALL,
  73. TextControlBase.TextControlSize.MEDIUM,
  74. TextControlBase.TextControlSize.LARGE,
  75. ])('on %s size', (size) => {
  76. it('should render input styles', () => {
  77. render(
  78. <MultilineTextInput
  79. size={size}
  80. />
  81. );
  82. expect(TextControlBase.Input).toBeCalledWith(expect.objectContaining({
  83. size,
  84. }));
  85. });
  86. it('should render hint styles', () => {
  87. render(
  88. <MultilineTextInput
  89. size={size}
  90. hint="hint"
  91. />
  92. );
  93. expect(TextControlBase.HintWrapper).toBeCalledWith(expect.objectContaining({
  94. size,
  95. }));
  96. });
  97. it('should render indicator styles', () => {
  98. render(
  99. <MultilineTextInput
  100. size={size}
  101. indicator={
  102. <div data-testid="indicator" />
  103. }
  104. />
  105. );
  106. expect(TextControlBase.IndicatorWrapper).toBeCalledWith(expect.objectContaining({
  107. size,
  108. }));
  109. });
  110. });
  111. it('should render a block textbox', () => {
  112. render(
  113. <MultilineTextInput
  114. block
  115. />
  116. );
  117. expect(TextControlBase.Root).toBeCalledWith(expect.objectContaining({
  118. block: true,
  119. }));
  120. });
  121. describe.each([
  122. TextControlBase.TextControlStyle.DEFAULT,
  123. TextControlBase.TextControlStyle.ALTERNATE,
  124. ])('on %s style', (style) => {
  125. it('should render input styles', () => {
  126. render(
  127. <MultilineTextInput
  128. style={style}
  129. />
  130. );
  131. expect(TextControlBase.Input).toBeCalledWith(expect.objectContaining({
  132. style,
  133. }));
  134. });
  135. it('should render hint styles', () => {
  136. render(
  137. <MultilineTextInput
  138. style={style}
  139. hint="hint"
  140. />
  141. );
  142. expect(TextControlBase.HintWrapper).toBeCalledWith(expect.objectContaining({
  143. style,
  144. }));
  145. });
  146. it('should render indicator styles', () => {
  147. render(
  148. <MultilineTextInput
  149. style={style}
  150. indicator={
  151. <div
  152. data-testid="indicator"
  153. />
  154. }
  155. />
  156. );
  157. expect(TextControlBase.IndicatorWrapper).toBeCalledWith(expect.objectContaining({
  158. style,
  159. }));
  160. });
  161. });
  162. it('should handle change events', () => {
  163. const onChange = jest.fn();
  164. render(
  165. <MultilineTextInput
  166. onChange={onChange}
  167. />
  168. );
  169. const textbox: HTMLTextAreaElement = screen.getByRole('textbox');
  170. userEvent.type(textbox, 'foobar');
  171. expect(onChange).toBeCalled();
  172. });
  173. });