arrayValue.spec.jsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import ArrayValue from 'sentry/utils/discover/arrayValue';
  3. describe('Discover > ArrayValue', function () {
  4. it('renders an expand link', function () {
  5. render(<ArrayValue value={['one', 'two', 'three']} />);
  6. // Should have a button
  7. const button = screen.getByRole('button');
  8. expect(button).toHaveTextContent('[+2 more]');
  9. // Should show last value.
  10. expect(screen.getByText('three')).toBeInTheDocument();
  11. });
  12. it('renders all elements when expanded', function () {
  13. render(<ArrayValue value={['one', 'two', 'three', '', null]} />);
  14. // Should have a button
  15. let button = screen.getByRole('button');
  16. userEvent.click(button);
  17. // Button text should update.
  18. button = screen.getByRole('button');
  19. expect(button).toHaveTextContent('[collapse]');
  20. // Should show all values.
  21. expect(screen.getByText('one')).toBeInTheDocument();
  22. expect(screen.getByText('two')).toBeInTheDocument();
  23. expect(screen.getByText('three')).toBeInTheDocument();
  24. expect(screen.getByText('(no value)')).toBeInTheDocument();
  25. expect(screen.getByText('(empty string)')).toBeInTheDocument();
  26. });
  27. it('hides toggle on 1 element', function () {
  28. render(<ArrayValue value={['one']} />);
  29. expect(screen.queryByRole('button')).not.toBeInTheDocument();
  30. expect(screen.getByText('one')).toBeInTheDocument();
  31. });
  32. it('hides toggle on 0 elements', function () {
  33. render(<ArrayValue value={[]} />);
  34. expect(screen.queryByRole('button')).not.toBeInTheDocument();
  35. });
  36. });