highlight.spec.jsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import {mountWithTheme, screen} from 'sentry-test/reactTestingLibrary';
  2. import {HighlightComponent} from 'sentry/components/highlight';
  3. describe('Highlight', function () {
  4. it('highlights text', function () {
  5. const wrapper = mountWithTheme(
  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. mountWithTheme(
  15. <HighlightComponent text="invalid">billy@sentry.io</HighlightComponent>
  16. );
  17. expect(screen.getByText('billy@sentry.io')).toBeInTheDocument();
  18. });
  19. it('does not have highlighted text if `text` prop is empty', function () {
  20. mountWithTheme(<HighlightComponent text="">billy@sentry.io</HighlightComponent>);
  21. expect(screen.getByText('billy@sentry.io')).toBeInTheDocument();
  22. });
  23. it('does not have highlighted text if `disabled` prop is true', function () {
  24. mountWithTheme(<HighlightComponent text="">billy@sentry.io</HighlightComponent>);
  25. expect(screen.getByText('billy@sentry.io')).toBeInTheDocument();
  26. });
  27. });