guideStore.spec.tsx 3.3 KB

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