highlight.spec.jsx 1.8 KB

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