guideStore.spec.jsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import ConfigStore from 'sentry/stores/configStore';
  2. import GuideStore from 'sentry/stores/guideStore';
  3. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  4. jest.mock('sentry/utils/analytics/trackAdvancedAnalyticsEvent');
  5. describe('GuideStore', function () {
  6. let data;
  7. const user = {
  8. id: '5',
  9. isSuperuser: false,
  10. dateJoined: new Date(2020, 0, 1),
  11. };
  12. beforeEach(function () {
  13. trackAdvancedAnalyticsEvent.mockClear();
  14. ConfigStore.config = {
  15. user,
  16. };
  17. GuideStore.init();
  18. data = [
  19. {
  20. guide: 'issue',
  21. seen: false,
  22. },
  23. {guide: 'issue_stream', seen: true},
  24. ];
  25. GuideStore.registerAnchor('issue_number');
  26. GuideStore.registerAnchor('exception');
  27. GuideStore.registerAnchor('breadcrumbs');
  28. GuideStore.registerAnchor('issue_stream');
  29. });
  30. afterEach(() => {
  31. GuideStore.teardown();
  32. });
  33. it('should move through the steps in the guide', function () {
  34. GuideStore.fetchSucceeded(data);
  35. // Should pick the first non-seen guide in alphabetic order.
  36. expect(GuideStore.state.currentStep).toEqual(0);
  37. expect(GuideStore.state.currentGuide.guide).toEqual('issue');
  38. // Should prune steps that don't have anchors.
  39. expect(GuideStore.state.currentGuide.steps).toHaveLength(3);
  40. GuideStore.nextStep();
  41. expect(GuideStore.state.currentStep).toEqual(1);
  42. GuideStore.nextStep();
  43. expect(GuideStore.state.currentStep).toEqual(2);
  44. GuideStore.closeGuide();
  45. expect(GuideStore.state.currentGuide).toEqual(null);
  46. });
  47. it('should expect anchors to appear in expectedTargets', function () {
  48. data = [{guide: 'new_page_filters', seen: false}];
  49. GuideStore.registerAnchor('new_page_filter_button');
  50. GuideStore.fetchSucceeded(data);
  51. expect(GuideStore.state.currentStep).toEqual(0);
  52. expect(GuideStore.state.currentGuide.guide).toEqual('new_page_filters');
  53. GuideStore.registerAnchor('new_page_filter_button');
  54. // Will not prune steps that don't have anchors
  55. expect(GuideStore.state.currentGuide.steps).toHaveLength(2);
  56. });
  57. it('should force show a guide with #assistant', function () {
  58. data = [
  59. {
  60. guide: 'issue',
  61. seen: true,
  62. },
  63. {guide: 'issue_stream', seen: false},
  64. ];
  65. GuideStore.fetchSucceeded(data);
  66. window.location.hash = '#assistant';
  67. GuideStore.onURLChange();
  68. expect(GuideStore.state.currentGuide.guide).toEqual('issue');
  69. GuideStore.closeGuide();
  70. expect(GuideStore.state.currentGuide.guide).toEqual('issue_stream');
  71. window.location.hash = '';
  72. });
  73. it('should force hide', function () {
  74. expect(GuideStore.state.forceHide).toEqual(false);
  75. GuideStore.setForceHide(true);
  76. expect(GuideStore.state.forceHide).toEqual(true);
  77. GuideStore.setForceHide(false);
  78. expect(GuideStore.state.forceHide).toEqual(false);
  79. });
  80. it('should record analytics events when guide is cued', function () {
  81. const spy = jest.spyOn(GuideStore, 'recordCue');
  82. GuideStore.fetchSucceeded(data);
  83. expect(spy).toHaveBeenCalledWith('issue');
  84. expect(trackAdvancedAnalyticsEvent).toHaveBeenCalledWith('assistant.guide_cued', {
  85. guide: 'issue',
  86. organization: null,
  87. });
  88. expect(spy).toHaveBeenCalledTimes(1);
  89. GuideStore.updateCurrentGuide();
  90. expect(spy).toHaveBeenCalledTimes(1);
  91. GuideStore.nextStep();
  92. expect(spy).toHaveBeenCalledTimes(1);
  93. spy.mockRestore();
  94. });
  95. it('only shows guides with server data and content', function () {
  96. data = [
  97. {
  98. guide: 'issue',
  99. seen: true,
  100. },
  101. {
  102. guide: 'has_no_content',
  103. seen: false,
  104. },
  105. ];
  106. GuideStore.fetchSucceeded(data);
  107. expect(GuideStore.state.guides.length).toBe(1);
  108. expect(GuideStore.state.guides[0].guide).toBe(data[0].guide);
  109. });
  110. });