guideStore.spec.jsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import ConfigStore from 'sentry/stores/configStore';
  2. import GuideStore from 'sentry/stores/guideStore';
  3. import {trackAnalyticsEvent} from 'sentry/utils/analytics';
  4. jest.mock('sentry/utils/analytics');
  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. trackAnalyticsEvent.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.onRegisterAnchor('issue_title');
  26. GuideStore.onRegisterAnchor('exception');
  27. GuideStore.onRegisterAnchor('breadcrumbs');
  28. GuideStore.onRegisterAnchor('issue_stream');
  29. });
  30. afterEach(() => {
  31. GuideStore.teardown();
  32. });
  33. it('should move through the steps in the guide', function () {
  34. GuideStore.onFetchSucceeded(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.onNextStep();
  41. expect(GuideStore.state.currentStep).toEqual(1);
  42. GuideStore.onNextStep();
  43. expect(GuideStore.state.currentStep).toEqual(2);
  44. GuideStore.onCloseGuide();
  45. expect(GuideStore.state.currentGuide).toEqual(null);
  46. });
  47. it('should force show a guide with #assistant', function () {
  48. data = [
  49. {
  50. guide: 'issue',
  51. seen: true,
  52. },
  53. {guide: 'issue_stream', seen: false},
  54. ];
  55. GuideStore.onFetchSucceeded(data);
  56. window.location.hash = '#assistant';
  57. GuideStore.onURLChange();
  58. expect(GuideStore.state.currentGuide.guide).toEqual('issue');
  59. GuideStore.onCloseGuide();
  60. expect(GuideStore.state.currentGuide.guide).toEqual('issue_stream');
  61. window.location.hash = '';
  62. });
  63. it('should force hide', function () {
  64. expect(GuideStore.state.forceHide).toEqual(false);
  65. GuideStore.onSetForceHide(true);
  66. expect(GuideStore.state.forceHide).toEqual(true);
  67. GuideStore.onSetForceHide(false);
  68. expect(GuideStore.state.forceHide).toEqual(false);
  69. });
  70. it('should record analytics events when guide is cued', function () {
  71. const spy = jest.spyOn(GuideStore, 'recordCue');
  72. GuideStore.onFetchSucceeded(data);
  73. expect(spy).toHaveBeenCalledWith('issue');
  74. expect(trackAnalyticsEvent).toHaveBeenCalledWith({
  75. guide: 'issue',
  76. eventKey: 'assistant.guide_cued',
  77. eventName: 'Assistant Guide Cued',
  78. organization_id: null,
  79. user_id: parseInt(user.id, 10),
  80. });
  81. expect(spy).toHaveBeenCalledTimes(1);
  82. GuideStore.updateCurrentGuide();
  83. expect(spy).toHaveBeenCalledTimes(1);
  84. GuideStore.onNextStep();
  85. expect(spy).toHaveBeenCalledTimes(1);
  86. spy.mockRestore();
  87. });
  88. it('only shows guides with server data and content', function () {
  89. data = [
  90. {
  91. guide: 'issue',
  92. seen: true,
  93. },
  94. {
  95. guide: 'has_no_content',
  96. seen: false,
  97. },
  98. ];
  99. GuideStore.onFetchSucceeded(data);
  100. expect(GuideStore.state.guides.length).toBe(1);
  101. expect(GuideStore.state.guides[0].guide).toBe(data[0].guide);
  102. });
  103. });