inputGroup.spec.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {Button} from 'sentry/components/button';
  3. import {InputGroup} from 'sentry/components/inputGroup';
  4. describe('InputGroup', function () {
  5. it('renders input', function () {
  6. render(
  7. <InputGroup>
  8. <InputGroup.Input value="Search" onChange={() => {}} />
  9. </InputGroup>
  10. );
  11. expect(screen.getByRole('textbox')).toBeInTheDocument();
  12. expect(screen.getByRole('textbox')).toHaveDisplayValue('Search');
  13. });
  14. it('renders disabled input', function () {
  15. render(
  16. <InputGroup>
  17. <InputGroup.Input disabled />
  18. </InputGroup>
  19. );
  20. expect(screen.getByRole('textbox')).toBeDisabled();
  21. });
  22. it('renders leading elements', async function () {
  23. render(
  24. <InputGroup>
  25. <InputGroup.LeadingItems>
  26. <Button>Leading Button</Button>
  27. </InputGroup.LeadingItems>
  28. <InputGroup.Input />
  29. </InputGroup>
  30. );
  31. // Leading button is rendered
  32. expect(screen.getByTestId('input-leading-items')).toBeInTheDocument();
  33. expect(screen.getByRole('button', {name: 'Leading Button'})).toBeInTheDocument();
  34. // Focus moves first to leading button and then to input
  35. await userEvent.tab();
  36. expect(screen.getByRole('button', {name: 'Leading Button'})).toHaveFocus();
  37. await userEvent.tab();
  38. expect(screen.getByRole('textbox')).toHaveFocus();
  39. });
  40. it('renders trailing elements', async function () {
  41. render(
  42. <InputGroup>
  43. <InputGroup.Input />
  44. <InputGroup.TrailingItems>
  45. <Button>Trailing Button</Button>
  46. </InputGroup.TrailingItems>
  47. </InputGroup>
  48. );
  49. // Trailing button is rendered
  50. expect(screen.getByTestId('input-trailing-items')).toBeInTheDocument();
  51. expect(screen.getByRole('button', {name: 'Trailing Button'})).toBeInTheDocument();
  52. // Focus moves first to input and then to trailing button
  53. await userEvent.tab();
  54. expect(screen.getByRole('textbox')).toHaveFocus();
  55. await userEvent.tab();
  56. expect(screen.getByRole('button', {name: 'Trailing Button'})).toHaveFocus();
  57. });
  58. });