guideStore.spec.jsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 data = {
  7. issue: {
  8. cue: 'Click here for a tour of the issue page',
  9. id: 1,
  10. page: 'issue',
  11. required_targets: ['target 1'],
  12. steps: [
  13. {message: 'Message 1', target: 'target 1', title: '1. Title 1'},
  14. {message: 'Message 2', target: 'target 2', title: '2. Title 2'},
  15. {message: 'Message 3', target: 'target 3', title: '3. Title 3'},
  16. ],
  17. },
  18. };
  19. let anchor1 = <GuideAnchor target="target 1" type="text" />;
  20. let anchor2 = <GuideAnchor target="target 2" type="text" />;
  21. beforeEach(function() {
  22. GuideStore.init();
  23. sandbox = sinon.sandbox.create();
  24. });
  25. afterEach(function() {
  26. sandbox.restore();
  27. });
  28. it('should add guides to store', function() {
  29. GuideStore.onFetchSucceeded(data);
  30. expect(GuideStore.state.guides).toEqual(data);
  31. expect(GuideStore.state.currentStep).toEqual(0);
  32. });
  33. it('should register anchors', function() {
  34. GuideStore.onRegisterAnchor(anchor1);
  35. GuideStore.onRegisterAnchor(anchor2);
  36. expect(GuideStore.state.anchors).toEqual(new Set([anchor1, anchor2]));
  37. });
  38. it('should move through the steps in the guide', function() {
  39. GuideStore.onRegisterAnchor(anchor1);
  40. GuideStore.onRegisterAnchor(anchor2);
  41. GuideStore.onFetchSucceeded(data);
  42. // GuideStore should prune steps that don't have anchors.
  43. expect(GuideStore.state.currentGuide.steps).toHaveLength(2);
  44. GuideStore.onNextStep();
  45. expect(GuideStore.state.currentStep).toEqual(1);
  46. GuideStore.onNextStep();
  47. expect(GuideStore.state.currentStep).toEqual(2);
  48. GuideStore.onCloseGuideOrSupport();
  49. expect(GuideStore.state.guidesSeen).toEqual(new Set([1]));
  50. });
  51. });