highlight.spec.jsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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(
  13. wrapper
  14. .children()
  15. .at(0)
  16. .text()
  17. ).toBe('b');
  18. expect(wrapper.find('span').text()).toBe('ill');
  19. expect(
  20. wrapper
  21. .children()
  22. .at(2)
  23. .text()
  24. ).toBe('y@sentry.io');
  25. });
  26. it('does not have highlighted text if `text` prop is not found in main text', function() {
  27. // shallow because `mount` and React Fragments don't work when accessing children
  28. // it will only return first child
  29. const wrapper = shallow(
  30. <HighlightComponent text="invalid">billy@sentry.io</HighlightComponent>,
  31. TestStubs.routerContext()
  32. );
  33. expect(wrapper.text()).toBe('billy@sentry.io');
  34. });
  35. it('does not have highlighted text if `text` prop is empty', function() {
  36. // shallow because `mount` and React Fragments don't work when accessing children
  37. // it will only return first child
  38. const wrapper = shallow(
  39. <HighlightComponent text="">billy@sentry.io</HighlightComponent>,
  40. TestStubs.routerContext()
  41. );
  42. expect(wrapper.text()).toBe('billy@sentry.io');
  43. });
  44. it('does not have highlighted text if `disabled` prop is true', function() {
  45. // shallow because `mount` and React Fragments don't work when accessing children
  46. // it will only return first child
  47. const wrapper = shallow(
  48. <HighlightComponent text="">billy@sentry.io</HighlightComponent>,
  49. TestStubs.routerContext()
  50. );
  51. expect(wrapper.text()).toBe('billy@sentry.io');
  52. });
  53. });