guideStore.spec.jsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. it('should move through the steps in the guide', function () {
  31. GuideStore.onFetchSucceeded(data);
  32. // Should pick the first non-seen guide in alphabetic order.
  33. expect(GuideStore.state.currentStep).toEqual(0);
  34. expect(GuideStore.state.currentGuide.guide).toEqual('issue');
  35. // Should prune steps that don't have anchors.
  36. expect(GuideStore.state.currentGuide.steps).toHaveLength(3);
  37. GuideStore.onNextStep();
  38. expect(GuideStore.state.currentStep).toEqual(1);
  39. GuideStore.onNextStep();
  40. expect(GuideStore.state.currentStep).toEqual(2);
  41. GuideStore.onCloseGuide();
  42. expect(GuideStore.state.currentGuide).toEqual(null);
  43. });
  44. it('should force show a guide with #assistant', function () {
  45. data = [
  46. {
  47. guide: 'issue',
  48. seen: true,
  49. },
  50. {guide: 'issue_stream', seen: false},
  51. ];
  52. GuideStore.onFetchSucceeded(data);
  53. window.location.hash = '#assistant';
  54. GuideStore.onURLChange();
  55. expect(GuideStore.state.currentGuide.guide).toEqual('issue');
  56. GuideStore.onCloseGuide();
  57. expect(GuideStore.state.currentGuide.guide).toEqual('issue_stream');
  58. window.location.hash = '';
  59. });
  60. it('should record analytics events when guide is cued', function () {
  61. const spy = jest.spyOn(GuideStore, 'recordCue');
  62. GuideStore.onFetchSucceeded(data);
  63. expect(spy).toHaveBeenCalledWith('issue');
  64. expect(trackAnalyticsEvent).toHaveBeenCalledWith({
  65. guide: 'issue',
  66. eventKey: 'assistant.guide_cued',
  67. eventName: 'Assistant Guide Cued',
  68. organization_id: null,
  69. user_id: parseInt(user.id, 10),
  70. });
  71. expect(spy).toHaveBeenCalledTimes(1);
  72. GuideStore.updateCurrentGuide();
  73. expect(spy).toHaveBeenCalledTimes(1);
  74. GuideStore.onNextStep();
  75. expect(spy).toHaveBeenCalledTimes(1);
  76. spy.mockRestore();
  77. });
  78. it('only shows guides with server data and content', function () {
  79. data = [
  80. {
  81. guide: 'issue',
  82. seen: true,
  83. },
  84. {
  85. guide: 'has_no_content',
  86. seen: false,
  87. },
  88. ];
  89. GuideStore.onFetchSucceeded(data);
  90. expect(GuideStore.state.guides.length).toBe(1);
  91. expect(GuideStore.state.guides[0].guide).toBe(data[0].guide);
  92. });
  93. });