highlight.spec.jsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import {shallow} from 'sentry-test/enzyme';
  2. import {HighlightComponent} from 'app/components/highlight';
  3. describe('Highlight', function () {
  4. it('highlights text', function () {
  5. // shallow because `mount` and React Fragments don't work when accessing children
  6. // it will only return first child
  7. const wrapper = shallow(
  8. <HighlightComponent text="ILL">billy@sentry.io</HighlightComponent>,
  9. TestStubs.routerContext()
  10. );
  11. expect(wrapper.children().at(0).text()).toBe('b');
  12. expect(wrapper.find('span').text()).toBe('ill');
  13. expect(wrapper.children().at(2).text()).toBe('y@sentry.io');
  14. });
  15. it('does not have highlighted text if `text` prop is not found in main text', function () {
  16. // shallow because `mount` and React Fragments don't work when accessing children
  17. // it will only return first child
  18. const wrapper = shallow(
  19. <HighlightComponent text="invalid">billy@sentry.io</HighlightComponent>,
  20. TestStubs.routerContext()
  21. );
  22. expect(wrapper.text()).toBe('billy@sentry.io');
  23. });
  24. it('does not have highlighted text if `text` prop is empty', function () {
  25. // shallow because `mount` and React Fragments don't work when accessing children
  26. // it will only return first child
  27. const wrapper = shallow(
  28. <HighlightComponent text="">billy@sentry.io</HighlightComponent>,
  29. TestStubs.routerContext()
  30. );
  31. expect(wrapper.text()).toBe('billy@sentry.io');
  32. });
  33. it('does not have highlighted text if `disabled` prop is true', function () {
  34. // shallow because `mount` and React Fragments don't work when accessing children
  35. // it will only return first child
  36. const wrapper = shallow(
  37. <HighlightComponent text="">billy@sentry.io</HighlightComponent>,
  38. TestStubs.routerContext()
  39. );
  40. expect(wrapper.text()).toBe('billy@sentry.io');
  41. });
  42. });