Skip to content

Commit

Permalink
Fix turning off modal overlay in successive tour starts (#277)
Browse files Browse the repository at this point in the history
* Fix turning off modal overlay in successive tour starts

Currently, the `showOrHideModal` function is being called for each step
on the `'hide' and 'destroy' events. This has the effect of calling it before
showing a tour again after closing it.

Moving the hide call up to the service itself fixes this.

* Update environment.js
  • Loading branch information
BrianSipple authored and RobbieTheWagner committed Nov 28, 2018
1 parent 774028f commit 7132157
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
6 changes: 4 additions & 2 deletions addon/services/tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default Service.extend(Evented, {
* @public
*/
cancel() {
this._showOrHideModal('hide');
get(this, 'tourObject').cancel();
},

Expand All @@ -64,6 +65,7 @@ export default Service.extend(Evented, {
* @public
*/
complete() {
this._showOrHideModal('hide');
get(this, 'tourObject').complete();
},

Expand All @@ -72,6 +74,7 @@ export default Service.extend(Evented, {
* @public
*/
hide() {
this._showOrHideModal('hide');
get(this, 'tourObject').hide();
},

Expand Down Expand Up @@ -162,7 +165,6 @@ export default Service.extend(Evented, {
tourObject.on('cancel', bind(this, 'onTourFinish', 'cancel'));

set(this, 'tourObject', tourObject);
this._initModalOverlay();
},

/**
Expand Down Expand Up @@ -278,7 +280,6 @@ export default Service.extend(Evented, {
['hide', 'destroy'].forEach(event => {
currentStep.on(event, () => {
unhighlightStepTarget(currentStep);
this._showOrHideModal('hide');
});
});

Expand Down Expand Up @@ -320,6 +321,7 @@ export default Service.extend(Evented, {
this._modalOverlayElem = createModalOverlay();
this._modalOverlayOpening = getModalMaskOpening(this._modalOverlayElem);

// don't show yet -- each step will control that
this._showOrHideModal('hide');

document.body.appendChild(this._modalOverlayElem);
Expand Down
15 changes: 6 additions & 9 deletions tests/acceptance/ember-shepherd-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,12 @@ module('Acceptance | Tour functionality tests', function(hooks) {
test('Displaying the modal during tours when modal mode is enabled', async function(assert) {
await visit('/');

const modalOverlay = document.querySelector(`#${modalElementIds.modalOverlay}`);

assert.ok(modalOverlay, 'modal overlay is present in the DOM');
assert.equal(getComputedStyle(modalOverlay).display, 'none', 'modal overlay is present but not displayed before the tour starts');
assert.notOk(document.body.classList.contains(modalClassNames.isVisible), `Body has no class of "${modalClassNames.isVisible}" when shepherd is not active`);
assert.equal(document.querySelector(`#${modalElementIds.modalOverlay}`), null, 'modal overlay is not present in the DOM before any tour is started');

await click('.toggleHelpModal');

const modalOverlay = document.querySelector(`#${modalElementIds.modalOverlay}`);

assert.equal(getComputedStyle(modalOverlay).display, 'block', 'modal overlay is present and displayed after the tour starts');

assert.ok(document.body.classList.contains('shepherd-active'), 'Body gets class of shepherd-active, when shepherd becomes active');
Expand All @@ -149,13 +147,12 @@ module('Acceptance | Tour functionality tests', function(hooks) {
test('Hiding the modal during tours when modal mode is not enabled', async function(assert) {
await visit('/');

const modalOverlay = document.querySelector(`#${modalElementIds.modalOverlay}`);

assert.ok(modalOverlay, 'modal overlay is present in the DOM');
assert.equal(getComputedStyle(modalOverlay).display, 'none', 'modal overlay is present but not displayed before the tour starts');
assert.equal(document.querySelector(`#${modalElementIds.modalOverlay}`), null, 'modal overlay is not present in the DOM before any tour is started');

await click('.toggleHelpNonmodal');

const modalOverlay = document.querySelector(`#${modalElementIds.modalOverlay}`);

assert.equal(getComputedStyle(modalOverlay).display, 'none', 'modal overlay is present but not displayed after the tour starts');

assert.ok(document.body.classList.contains('shepherd-active'), 'Body gets class of shepherd-active, when shepherd becomes active');
Expand Down

0 comments on commit 7132157

Please sign in to comment.