highlight.spec.jsx 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import {HighlightComponent} from 'sentry/components/highlight';
  3. describe('Highlight', function () {
  4. it('highlights text', function () {
  5. const wrapper = render(
  6. <HighlightComponent text="ILL">billy@sentry.io</HighlightComponent>
  7. );
  8. expect(wrapper.container.childNodes).toHaveLength(3);
  9. expect(wrapper.container.childNodes[0]).toHaveTextContent('b');
  10. expect(wrapper.container.childNodes[1]).toHaveTextContent('ill');
  11. expect(wrapper.container.childNodes[2]).toHaveTextContent('y@sentry.io');
  12. });
  13. it('does not have highlighted text if `text` prop is not found in main text', function () {
  14. render(<HighlightComponent text="invalid">billy@sentry.io</HighlightComponent>);
  15. expect(screen.getByText('billy@sentry.io')).toBeInTheDocument();
  16. });
  17. it('does not have highlighted text if `text` prop is empty', function () {
  18. render(<HighlightComponent text="">billy@sentry.io</HighlightComponent>);
  19. expect(screen.getByText('billy@sentry.io')).toBeInTheDocument();
  20. });
  21. it('does not have highlighted text if `disabled` prop is true', function () {
  22. render(<HighlightComponent text="">billy@sentry.io</HighlightComponent>);
  23. expect(screen.getByText('billy@sentry.io')).toBeInTheDocument();
  24. });
  25. });