guideAnchor.spec.jsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import GuideActions from 'sentry/actions/guideActions';
  3. import GuideAnchorWrapper, {GuideAnchor} from 'sentry/components/assistant/guideAnchor';
  4. import ConfigStore from 'sentry/stores/configStore';
  5. import theme from 'sentry/utils/theme';
  6. describe('GuideAnchor', function () {
  7. let wrapper, wrapper2;
  8. const serverGuide = [
  9. {
  10. guide: 'issue',
  11. seen: false,
  12. },
  13. ];
  14. beforeEach(function () {
  15. ConfigStore.config = {
  16. user: {
  17. isSuperuser: false,
  18. dateJoined: new Date(2020, 0, 1),
  19. },
  20. };
  21. wrapper = mountWithTheme(<GuideAnchor target="issue_title" />);
  22. wrapper2 = mountWithTheme(<GuideAnchor target="exception" />);
  23. });
  24. afterEach(function () {
  25. wrapper.unmount();
  26. wrapper2.unmount();
  27. });
  28. it('renders, advances, and finishes', async function () {
  29. GuideActions.fetchSucceeded(serverGuide);
  30. await tick();
  31. wrapper.update();
  32. expect(wrapper.find('Hovercard').exists()).toBe(true);
  33. expect(wrapper.find('GuideTitle').text()).toBe("Let's Get This Over With");
  34. expect(wrapper.find('Hovercard').prop('tipColor')).toBe(theme.purple300);
  35. // Clicking on next should deactivate the current card and activate the next one.
  36. wrapper.find('StyledButton[aria-label="Next"]').simulate('click');
  37. await tick();
  38. wrapper.update();
  39. wrapper2.update();
  40. expect(wrapper.state('active')).toBeFalsy();
  41. expect(wrapper2.state('active')).toBeTruthy();
  42. expect(wrapper2.find('Hovercard').exists()).toBe(true);
  43. expect(wrapper2.find('GuideTitle').text()).toBe('Narrow Down Suspects');
  44. // Clicking on the button in the last step should finish the guide.
  45. const finishMock = MockApiClient.addMockResponse({
  46. method: 'PUT',
  47. url: '/assistant/',
  48. });
  49. wrapper2.find('Button').last().simulate('click');
  50. expect(finishMock).toHaveBeenCalledWith(
  51. '/assistant/',
  52. expect.objectContaining({
  53. method: 'PUT',
  54. data: {
  55. guide: 'issue',
  56. status: 'viewed',
  57. },
  58. })
  59. );
  60. });
  61. it('dismisses', async function () {
  62. GuideActions.fetchSucceeded(serverGuide);
  63. await tick();
  64. wrapper.update();
  65. const dismissMock = MockApiClient.addMockResponse({
  66. method: 'PUT',
  67. url: '/assistant/',
  68. });
  69. wrapper.find('StyledButton[aria-label="Dismiss"]').simulate('click');
  70. expect(dismissMock).toHaveBeenCalledWith(
  71. '/assistant/',
  72. expect.objectContaining({
  73. method: 'PUT',
  74. data: {
  75. guide: 'issue',
  76. status: 'dismissed',
  77. },
  78. })
  79. );
  80. await tick();
  81. expect(wrapper.state('active')).toBeFalsy();
  82. });
  83. it('renders no container when inactive', function () {
  84. wrapper = mountWithTheme(
  85. <GuideAnchor target="target 1">
  86. <span>A child</span>
  87. </GuideAnchor>
  88. );
  89. const component = wrapper.instance();
  90. wrapper.update();
  91. expect(component.state).toMatchObject({active: false});
  92. expect(wrapper.find('Hovercard').exists()).toBe(false);
  93. });
  94. it('renders children when disabled', async function () {
  95. const wrapper3 = mountWithTheme(
  96. <GuideAnchorWrapper disabled target="exception">
  97. <div data-test-id="child-div" />
  98. </GuideAnchorWrapper>
  99. );
  100. GuideActions.fetchSucceeded(serverGuide);
  101. await tick();
  102. wrapper3.update();
  103. expect(wrapper3.find('Hovercard').exists()).toBe(false);
  104. expect(wrapper3.find('[data-test-id="child-div"]').exists()).toBe(true);
  105. });
  106. });