Commit 7baddd86 authored by Doug Stull's avatar Doug Stull Committed by Martin Wortschack

Refactor the exit tour event loop in onboarding tour

- allow a more declarative path for the exit tour event
- simplifies the click action function
parent 7090ff1c
...@@ -57,11 +57,5 @@ export const EXIT_TOUR_CONTENT = { ...@@ -57,11 +57,5 @@ export const EXIT_TOUR_CONTENT = {
}, },
false, false,
), ),
buttons: [ exitTour: true,
{
text: s__("UserOnboardingTour|Close 'Learn GitLab'"),
btnClass: 'btn-primary',
exitTour: true,
},
],
}; };
...@@ -138,14 +138,7 @@ export default { ...@@ -138,14 +138,7 @@ export default {
} }
}, },
handleClickPopoverButton(button) { handleClickPopoverButton(button) {
const { const { showExitTourContent, redirectPath, nextPart, dismissPopover } = button;
showExitTourContent,
exitTour,
redirectPath,
nextPart,
dismissPopover,
showFeedbackTourContent,
} = button;
const helpContentItems = this.stepContent const helpContentItems = this.stepContent
? this.stepContent.getHelpContent({ projectName: this.projectName }) ? this.stepContent.getHelpContent({ projectName: this.projectName })
: null; : null;
...@@ -154,24 +147,12 @@ export default { ...@@ -154,24 +147,12 @@ export default {
helpContentItems.length > 1 && helpContentItems.length > 1 &&
this.helpContentIndex < helpContentItems.length - 1; this.helpContentIndex < helpContentItems.length - 1;
// display feedback content after user hits the exit button
if (showFeedbackTourContent) {
this.handleFeedbackTourContent(true);
return;
}
// display exit tour content // display exit tour content
if (showExitTourContent) { if (showExitTourContent) {
this.handleShowExitTourContent(true); this.handleShowExitTourContent(true);
return; return;
} }
// quit tour
if (exitTour) {
this.handleExitTour();
return;
}
// dismiss popover if necessary // dismiss popover if necessary
if (_.isUndefined(dismissPopover) || dismissPopover === true) { if (_.isUndefined(dismissPopover) || dismissPopover === true) {
this.dismissPopover = true; this.dismissPopover = true;
...@@ -236,7 +217,7 @@ export default { ...@@ -236,7 +217,7 @@ export default {
this.showStepContent = true; this.showStepContent = true;
this.setExitTour(showExitTour); this.setExitTour(showExitTour);
}, },
handleExitTour() { handleExitTourButton() {
this.hideActionPopover(); this.hideActionPopover();
this.setDismissed(true); this.setDismissed(true);
...@@ -268,12 +249,12 @@ export default { ...@@ -268,12 +249,12 @@ export default {
:dismiss-popover="dismissPopover" :dismiss-popover="dismissPopover"
:golden-tanuki-svg-path="goldenTanukiSvgPath" :golden-tanuki-svg-path="goldenTanukiSvgPath"
@clickPopoverButton="handleClickPopoverButton" @clickPopoverButton="handleClickPopoverButton"
@clickExitTourButton="handleExitTourButton"
@clickFeedbackButton="handleFeedbackButton" @clickFeedbackButton="handleFeedbackButton"
@restartStep="handleRestartStep" @restartStep="handleRestartStep"
@skipStep="handleSkipStep" @skipStep="handleSkipStep"
@showFeedbackContent="handleFeedbackTourContent" @showFeedbackContent="handleFeedbackTourContent"
@showExitTourContent="handleShowExitTourContent" @showExitTourContent="handleShowExitTourContent"
@exitTour="handleExitTour"
/> />
</transition> </transition>
</template> </template>
...@@ -38,6 +38,9 @@ export default { ...@@ -38,6 +38,9 @@ export default {
callButtonAction(button) { callButtonAction(button) {
this.$emit('clickActionButton', button); this.$emit('clickActionButton', button);
}, },
callExitTour() {
this.$emit('clickExitTourButton');
},
submitFeedback(button) { submitFeedback(button) {
this.$emit('clickFeedbackButton', button); this.$emit('clickFeedbackButton', button);
}, },
...@@ -72,6 +75,11 @@ export default { ...@@ -72,6 +75,11 @@ export default {
</span> </span>
</template> </template>
</template> </template>
<template v-if="helpContent.exitTour">
<gl-button class="btn btn-sm btn-primary mr-2" @click="callExitTour">
{{ s__("UserOnboardingTour|Close 'Learn GitLab'") }}
</gl-button>
</template>
<template v-if="helpContent.feedbackButtons"> <template v-if="helpContent.feedbackButtons">
<gl-button-group> <gl-button-group>
<gl-button <gl-button
......
...@@ -138,6 +138,9 @@ export default { ...@@ -138,6 +138,9 @@ export default {
callButtonAction(button) { callButtonAction(button) {
this.$emit('clickPopoverButton', button); this.$emit('clickPopoverButton', button);
}, },
callExitTour() {
this.$emit('clickExitTourButton');
},
submitFeedback(button) { submitFeedback(button) {
this.$emit('clickFeedbackButton', button); this.$emit('clickFeedbackButton', button);
}, },
...@@ -161,6 +164,7 @@ export default { ...@@ -161,6 +164,7 @@ export default {
:show="showPopover" :show="showPopover"
:disabled="popoverDismissed" :disabled="popoverDismissed"
@clickActionButton="callButtonAction" @clickActionButton="callButtonAction"
@clickExitTourButton="callExitTour"
@clickFeedbackButton="submitFeedback" @clickFeedbackButton="submitFeedback"
/> />
<div class="d-flex align-items-center cursor-pointer"> <div class="d-flex align-items-center cursor-pointer">
......
...@@ -229,18 +229,6 @@ describe('User onboarding helper app', () => { ...@@ -229,18 +229,6 @@ describe('User onboarding helper app', () => {
expect(vm.showExitTourContent).toHaveBeenCalledWith(true); expect(vm.showExitTourContent).toHaveBeenCalledWith(true);
}); });
it('quits the tour', () => {
spyOn(vm, 'handleExitTour');
const button = {
exitTour: true,
};
vm.handleClickPopoverButton(button);
expect(vm.handleExitTour).toHaveBeenCalled();
});
it('sets dismissPopover to true when true/undefined on button config', () => { it('sets dismissPopover to true when true/undefined on button config', () => {
let button = { let button = {
dismissPopover: true, dismissPopover: true,
...@@ -365,19 +353,19 @@ describe('User onboarding helper app', () => { ...@@ -365,19 +353,19 @@ describe('User onboarding helper app', () => {
}); });
}); });
describe('handleExitTour', () => { describe('handleExitTourButton', () => {
it('calls the "hideActionPopover" method', () => { it('emits the "onboardingHelper.hideActionPopover" event', () => {
spyOn(vm, 'hideActionPopover'); spyOn(eventHub, '$emit');
vm.handleExitTour(); vm.handleExitTourButton();
expect(vm.hideActionPopover).toHaveBeenCalled(); expect(eventHub.$emit).toHaveBeenCalledWith('onboardingHelper.hideActionPopover');
}); });
it('calls the "setDismissed" method with true', () => { it('calls the "setDismissed" method with true', () => {
spyOn(vm.$store, 'dispatch'); spyOn(vm.$store, 'dispatch');
vm.handleExitTour(); vm.handleExitTourButton();
expect(vm.$store.dispatch).toHaveBeenCalledWith('setDismissed', true); expect(vm.$store.dispatch).toHaveBeenCalledWith('setDismissed', true);
}); });
...@@ -385,7 +373,7 @@ describe('User onboarding helper app', () => { ...@@ -385,7 +373,7 @@ describe('User onboarding helper app', () => {
it('emits the "onboardingHelper.destroyActionPopover" event', () => { it('emits the "onboardingHelper.destroyActionPopover" event', () => {
spyOn(eventHub, '$emit'); spyOn(eventHub, '$emit');
vm.handleExitTour(); vm.handleExitTourButton();
expect(eventHub.$emit).toHaveBeenCalledWith('onboardingHelper.destroyActionPopover'); expect(eventHub.$emit).toHaveBeenCalledWith('onboardingHelper.destroyActionPopover');
}); });
......
...@@ -19,6 +19,16 @@ describe('User onboarding help content popover', () => { ...@@ -19,6 +19,16 @@ describe('User onboarding help content popover', () => {
disabled: false, disabled: false,
}; };
const exitTourContent = {
text: 'some help content',
exitTour: true,
};
const exitTourProps = {
...defaultProps,
helpContent: exitTourContent,
};
const feedbackContent = { const feedbackContent = {
text: 'some help content', text: 'some help content',
feedbackButtons: true, feedbackButtons: true,
...@@ -51,6 +61,16 @@ describe('User onboarding help content popover', () => { ...@@ -51,6 +61,16 @@ describe('User onboarding help content popover', () => {
}); });
}); });
describe('callExitTour', () => {
it('emits clickExitTourButton when called', () => {
createComponent(exitTourProps);
wrapper.find(GlButton).vm.$emit('click');
expect(wrapper.emittedByOrder()).toEqual([{ name: 'clickExitTourButton', args: [] }]);
});
});
describe('submitFeedback', () => { describe('submitFeedback', () => {
it('emits clickFeedbackButton when called', () => { it('emits clickFeedbackButton when called', () => {
createComponent(feedbackProps); createComponent(feedbackProps);
...@@ -75,6 +95,16 @@ describe('User onboarding help content popover', () => { ...@@ -75,6 +95,16 @@ describe('User onboarding help content popover', () => {
expect(btn.text()).toBe(defaultProps.helpContent.buttons[0].text); expect(btn.text()).toBe(defaultProps.helpContent.buttons[0].text);
}); });
it('displays the help content text and renders a primary button with exit text when there is no buttons in help content', () => {
createComponent(exitTourProps);
const btn = wrapper.find('.btn-primary');
expect(wrapper.text()).toContain(exitTourProps.helpContent.text);
expect(btn.exists()).toBe(true);
expect(btn.text()).toBe("Close 'Learn GitLab'");
});
it('renders a secondary button with the text "button"', () => { it('renders a secondary button with the text "button"', () => {
const propsData = { const propsData = {
...defaultProps, ...defaultProps,
......
...@@ -240,6 +240,14 @@ describe('User onboarding tour parts list', () => { ...@@ -240,6 +240,14 @@ describe('User onboarding tour parts list', () => {
}); });
}); });
describe('callExitTour', () => {
it('emits the "clickExitTourButton" event when close Learn GitLab is clicked', () => {
wrapper.vm.callExitTour();
expect(wrapper.emittedByOrder()).toEqual([{ name: 'clickExitTourButton', args: [] }]);
});
});
describe('submitFeedback', () => { describe('submitFeedback', () => {
it('emits the "clickFeedbackButton" event when feedback on tour is clicked', () => { it('emits the "clickFeedbackButton" event when feedback on tour is clicked', () => {
const button = defaultProps.helpContent.buttons[0]; const button = defaultProps.helpContent.buttons[0];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment