guideStore.spec.jsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import React from 'react';
  2. import GuideStore from 'app/stores/guideStore';
  3. import GuideAnchor from 'app/components/assistant/guideAnchor';
  4. describe('GuideStore', function() {
  5. let sandbox;
  6. let anchor1 = <GuideAnchor target="target 1" type="text" />;
  7. let anchor2 = <GuideAnchor target="target 2" type="text" />;
  8. let data;
  9. beforeEach(function() {
  10. GuideStore.init();
  11. sandbox = sinon.sandbox.create();
  12. data = {
  13. issue: {
  14. cue: 'Click here for a tour of the issue page',
  15. id: 1,
  16. page: 'issue',
  17. required_targets: ['target 1'],
  18. steps: [
  19. {message: 'Message 1', target: 'target 1', title: '1. Title 1'},
  20. {message: 'Message 2', target: 'target 2', title: '2. Title 2'},
  21. {message: 'Message 3', target: 'target 3', title: '3. Title 3'},
  22. ],
  23. seen: false,
  24. },
  25. };
  26. });
  27. afterEach(function() {
  28. sandbox.restore();
  29. });
  30. it('should add guides to store', function() {
  31. GuideStore.onFetchSucceeded(data);
  32. expect(GuideStore.state.guides).toEqual(data);
  33. expect(GuideStore.state.currentStep).toEqual(0);
  34. });
  35. it('should register anchors', function() {
  36. GuideStore.onRegisterAnchor(anchor1);
  37. GuideStore.onRegisterAnchor(anchor2);
  38. expect(GuideStore.state.anchors).toEqual(new Set([anchor1, anchor2]));
  39. });
  40. it('should move through the steps in the guide', function() {
  41. GuideStore.onRegisterAnchor(anchor1);
  42. GuideStore.onRegisterAnchor(anchor2);
  43. GuideStore.onFetchSucceeded(data);
  44. // GuideStore should prune steps that don't have anchors.
  45. expect(GuideStore.state.currentGuide.steps).toHaveLength(2);
  46. expect(GuideStore.state.currentGuide.seen).toEqual(false);
  47. GuideStore.onNextStep();
  48. expect(GuideStore.state.currentStep).toEqual(1);
  49. GuideStore.onNextStep();
  50. expect(GuideStore.state.currentStep).toEqual(2);
  51. GuideStore.onCloseGuideOrSupport();
  52. expect(
  53. Object.keys(GuideStore.state.guides).filter(
  54. key => GuideStore.state.guides[key].seen == true
  55. )
  56. ).toEqual(['issue']);
  57. });
  58. it('should not show seen guides', function() {
  59. data.issue.seen = true;
  60. GuideStore.onRegisterAnchor(anchor1);
  61. GuideStore.onRegisterAnchor(anchor2);
  62. GuideStore.onFetchSucceeded(data);
  63. expect(GuideStore.state.currentGuide).toEqual(null);
  64. });
  65. it('should force show a guide', function() {
  66. data.issue.seen = true;
  67. GuideStore.onRegisterAnchor(anchor1);
  68. GuideStore.onRegisterAnchor(anchor2);
  69. GuideStore.state.forceShow = true;
  70. GuideStore.onFetchSucceeded(data);
  71. expect(GuideStore.state.currentGuide).not.toEqual(null);
  72. });
  73. });