diff --git a/src/plugins/promo-presets.test.ts b/src/plugins/promo-presets.test.ts index 182fb46..1cd6c1a 100644 --- a/src/plugins/promo-presets.test.ts +++ b/src/plugins/promo-presets.test.ts @@ -176,3 +176,33 @@ describe('promo preset', function () { }); }); }); + +it('open wizard -> close promo hint', async function () { + const options = getOptionsWithPromo(); + options.plugins = [new PromoPresetsPlugin()]; + const controller = new Controller(options); + + await controller.stepElementReached({ + stepSlug: 'showCoolFeature', + element: getAnchorElement(), + }); + + await controller.setWizardState('visible'); + + expect(controller.hintStore.state.open).toBe(false); +}); + +it('open wizard -> NOT close common hint', async function () { + const options = getOptionsWithPromo(); + options.plugins = [new PromoPresetsPlugin()]; + const controller = new Controller(options); + + await controller.stepElementReached({ + stepSlug: 'openBoard', + element: getAnchorElement(), + }); + + await controller.setWizardState('visible'); + + expect(controller.hintStore.state.open).toBe(true); +}); diff --git a/src/plugins/promo-presets.ts b/src/plugins/promo-presets.ts index 1e5f9e7..d88a796 100644 --- a/src/plugins/promo-presets.ts +++ b/src/plugins/promo-presets.ts @@ -27,6 +27,8 @@ export class PromoPresetsPlugin implements OnboardingPlugin { onboarding.events.subscribe('beforeShowHint', this.onHintShow); onboarding.events.subscribe('beforeSuggestPreset', this.onSuggestPreset); + + onboarding.events.subscribe('wizardStateChanged', this.onWizardStateChanged); }; onHintShow = ({stepData}: EventsMap['beforeShowHint']) => { @@ -34,11 +36,9 @@ export class PromoPresetsPlugin implements OnboardingPlugin { return true; } - const preset = this.onboardingInstance.options.config.presets[stepData.preset]; - const {wizardState} = this.onboardingInstance.state.base; - const isPromoPreset = preset?.type !== 'internal' && preset?.visibility === 'alwaysHidden'; + const isPromoPreset = this.checkIsPromoPreset(stepData.preset); const isGuideVisible = wizardState === 'visible' || wizardState === 'collapsed'; @@ -66,13 +66,36 @@ export class PromoPresetsPlugin implements OnboardingPlugin { return; } - const preset = this.onboardingInstance.options.config.presets[presetSlug]; - - const isPromoPreset = preset?.type !== 'internal' && preset?.visibility === 'alwaysHidden'; - - if (isPromoPreset) { + if (this.checkIsPromoPreset(presetSlug)) { this.onboardingInstance.state.base.enabled = true; this.onboardingInstance.emitStateChange(); } }; + + onWizardStateChanged = async ({wizardState}: EventsMap['wizardStateChanged']) => { + if (!this.onboardingInstance) { + return; + } + + if (wizardState === 'visible') { + const isHintOpen = this.onboardingInstance.hintStore.state.open; + const isPromoPreset = this.checkIsPromoPreset( + this.onboardingInstance.hintStore.state.hint?.preset, + ); + + if (isHintOpen && isPromoPreset) { + this.onboardingInstance.closeHint(); + } + } + }; + + private checkIsPromoPreset = (presetSlug: string) => { + if (!this.onboardingInstance) { + return false; + } + + const preset = this.onboardingInstance.options.config.presets[presetSlug]; + + return preset?.type !== 'internal' && preset?.visibility === 'alwaysHidden'; + }; } diff --git a/src/plugins/wizard-plugin.test.ts b/src/plugins/wizard-plugin.test.ts index dc95977..d7f6cb6 100644 --- a/src/plugins/wizard-plugin.test.ts +++ b/src/plugins/wizard-plugin.test.ts @@ -51,21 +51,6 @@ describe('open wizard', function () { expect(options.getProgressState).toHaveBeenCalled(); }); - - it('become visible -> close hint', async function () { - const options = getOptions({wizardState: 'hidden'}); - options.plugins = [new WizardPlugin()]; - const controller = new Controller(options); - - await controller.stepElementReached({ - stepSlug: 'createSprint', - element: getAnchorElement(), - }); - - await controller.setWizardState('visible'); - - expect(controller.hintStore.state.open).toBe(false); - }); }); describe('close wizard', function () { diff --git a/src/plugins/wizard-plugin.ts b/src/plugins/wizard-plugin.ts index d339645..7c4b3be 100644 --- a/src/plugins/wizard-plugin.ts +++ b/src/plugins/wizard-plugin.ts @@ -31,10 +31,6 @@ export class WizardPlugin implements OnboardingPlugin { return; } - if (wizardState === 'visible') { - await this.onboardingInstance.closeHint(); - } - if (wizardState === 'visible' || wizardState === 'collapsed') { await this.onboardingInstance.ensureRunning(); }