guideAnchor.spec.jsx 3.6 KB

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