123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- import {logExperiment, trackAnalyticsEvent} from 'app/utils/analytics';
- import ConfigStore from 'app/stores/configStore';
- import GuideStore from 'app/stores/guideStore';
- jest.mock('app/utils/analytics');
- describe('GuideStore', function() {
- let data;
- const user = {
- id: '5',
- isSuperuser: false,
- dateJoined: new Date(2020, 0, 1),
- };
- beforeEach(function() {
- trackAnalyticsEvent.mockClear();
- logExperiment.mockClear();
- ConfigStore.config = {
- user,
- };
- GuideStore.init();
- data = [
- {
- guide: 'issue',
- seen: false,
- },
- {guide: 'issue_stream', seen: true},
- ];
- GuideStore.onRegisterAnchor('issue_title');
- GuideStore.onRegisterAnchor('exception');
- GuideStore.onRegisterAnchor('breadcrumbs');
- GuideStore.onRegisterAnchor('issue_stream');
- });
- it('should move through the steps in the guide', function() {
- GuideStore.onFetchSucceeded(data);
- // Should pick the first non-seen guide in alphabetic order.
- expect(GuideStore.state.currentStep).toEqual(0);
- expect(GuideStore.state.currentGuide.guide).toEqual('issue');
- // Should prune steps that don't have anchors.
- expect(GuideStore.state.currentGuide.steps).toHaveLength(3);
- GuideStore.onNextStep();
- expect(GuideStore.state.currentStep).toEqual(1);
- GuideStore.onNextStep();
- expect(GuideStore.state.currentStep).toEqual(2);
- GuideStore.onCloseGuide();
- expect(GuideStore.state.currentGuide).toEqual(null);
- });
- it('should force show a guide with #assistant', function() {
- data = [
- {
- guide: 'issue',
- seen: true,
- },
- {guide: 'issue_stream', seen: false},
- ];
- GuideStore.onFetchSucceeded(data);
- window.location.hash = '#assistant';
- GuideStore.onURLChange();
- expect(GuideStore.state.currentGuide.guide).toEqual('issue');
- GuideStore.onCloseGuide();
- expect(GuideStore.state.currentGuide.guide).toEqual('issue_stream');
- window.location.hash = '';
- });
- it('should record analytics events when guide is cued', function() {
- const spy = jest.spyOn(GuideStore, 'recordCue');
- GuideStore.onFetchSucceeded(data);
- expect(spy).toHaveBeenCalledWith('issue');
- expect(trackAnalyticsEvent).toHaveBeenCalledWith({
- guide: 'issue',
- eventKey: 'assistant.guide_cued',
- eventName: 'Assistant Guide Cued',
- organization_id: null,
- user_id: parseInt(user.id, 10),
- });
- expect(spy).toHaveBeenCalledTimes(1);
- GuideStore.updateCurrentGuide();
- expect(spy).toHaveBeenCalledTimes(1);
- GuideStore.onNextStep();
- expect(spy).toHaveBeenCalledTimes(1);
- spy.mockRestore();
- expect(logExperiment).toHaveBeenCalledWith({
- key: 'AssistantGuideExperiment',
- unitName: 'user_id',
- unitId: parseInt(user.id, 10),
- param: 'variant',
- });
- });
- it('only shows guides with server data and content', function() {
- data = [
- {
- guide: 'issue',
- seen: true,
- },
- {
- guide: 'has_no_content',
- seen: false,
- },
- ];
- GuideStore.onFetchSucceeded(data);
- expect(GuideStore.state.guides.length).toBe(1);
- expect(GuideStore.state.guides[0].guide).toBe(data[0].guide);
- });
- describe('discover sidebar guide', function() {
- beforeEach(function() {
- data = [
- {
- guide: 'discover_sidebar',
- seen: false,
- },
- ];
- GuideStore.onRegisterAnchor('discover_sidebar');
- });
- it('does not render without user', function() {
- ConfigStore.config = {};
- GuideStore.onFetchSucceeded(data);
- expect(GuideStore.state.currentGuide).toBe(null);
- });
- it('shows discover sidebar guide to superusers', function() {
- ConfigStore.config = {
- user: {
- isSuperuser: true,
- },
- };
- GuideStore.onFetchSucceeded(data);
- expect(GuideStore.state.currentGuide.guide).toBe('discover_sidebar');
- });
- it('shows discover sidebar guide to previously existing users', function() {
- ConfigStore.config = {
- user: {
- isSuperuser: false,
- dateJoined: new Date(2020, 0, 1),
- },
- };
- GuideStore.onFetchSucceeded(data);
- expect(GuideStore.state.currentGuide.guide).toBe('discover_sidebar');
- });
- it('does not show discover sidebar guide to new users', function() {
- ConfigStore.config = {
- user: {
- isSuperuser: false,
- dateJoined: new Date(2020, 1, 22),
- },
- };
- GuideStore.onFetchSucceeded(data);
- expect(GuideStore.state.currentGuide).toBe(null);
- });
- it('hides discover sidebar guide once seen', function() {
- data[0].seen = true;
- // previous user
- ConfigStore.config = {
- user: {
- isSuperuser: false,
- dateJoined: new Date(2020, 0, 1),
- },
- };
- GuideStore.onFetchSucceeded(data);
- expect(GuideStore.state.currentGuide).toBe(null);
- });
- it('does not force show the discover sidebar guide once seen', function() {
- data[0].seen = true;
- // previous user
- ConfigStore.config = {
- user: {
- isSuperuser: false,
- dateJoined: new Date(2020, 0, 1),
- },
- };
- GuideStore.onFetchSucceeded(data);
- window.location.hash = '#assistant';
- GuideStore.onURLChange();
- expect(GuideStore.state.currentGuide).toBe(null);
- });
- });
- });
|