Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use rootElement, if defined, rather than document.body #295

Merged
merged 4 commits into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions addon/services/tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { get, set } from '@ember/object';
import { isEmpty, isPresent } from '@ember/utils';
import Service from '@ember/service';
import Evented from '@ember/object/evented';
import { getOwner } from '@ember/application';
import { bind, later } from '@ember/runloop';
import { normalizeAttachTo } from '../utils/attachTo';
import { makeButton } from '../utils/buttons';
Expand Down Expand Up @@ -132,6 +133,18 @@ export default Service.extend(Evented, {
const tourName = get(this, 'tourName');
const useModalOverlay = get(this, 'modal');

// Ensure `tippyOptions` exists on `defaultStepOptions`
defaultStepOptions.tippyOptions = defaultStepOptions.tippyOptions || {};

let { rootElement } = getOwner(this);
if (typeof rootElement === 'string') {
rootElement = document.querySelector(rootElement);
}

if (rootElement && !defaultStepOptions.tippyOptions.appendTo) {
defaultStepOptions.tippyOptions.appendTo = rootElement;
}

const tourObject = new Shepherd.Tour({
confirmCancel,
confirmCancelMessage,
Expand Down
12 changes: 6 additions & 6 deletions tests/acceptance/ember-shepherd-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module('Acceptance | Tour functionality tests', function(hooks) {

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

await click(document.querySelector('.shepherd-content a.shepherd-cancel-link'));
await click('.shepherd-content a.shepherd-cancel-link');

assert.notOk(document.body.classList.contains('shepherd-active'), 'Body does not have class of shepherd-active, when shepherd becomes inactive');
});
Expand Down Expand Up @@ -249,7 +249,7 @@ module('Acceptance | Tour functionality tests', function(hooks) {
assert.ok(document.querySelector('.button-two'), 'tour button two is visible');
assert.ok(document.querySelector('.button-three'), 'tour button three is visible');

await click(document.querySelector('.button-two'));
await click('.button-two');

assert.ok(buttonActionCalled, 'button action triggered');
});
Expand All @@ -269,9 +269,9 @@ module('Acceptance | Tour functionality tests', function(hooks) {

await tour.start();

await click(document.querySelector('.shepherd-content .next-button'));
await click('.shepherd-content .next-button');

await click(document.querySelector('.shepherd-content .next-button'));
await click('.shepherd-content .next-button');

assert.ok(document.querySelector('#ember-testing-container').scrollTop > 0, 'Scrolled down correctly');
});
Expand Down Expand Up @@ -308,7 +308,7 @@ module('Acceptance | Tour functionality tests', function(hooks) {
assert.equal(document.querySelector('#ember-testing-container').scrollTop, 0, 'Scroll is initially 0');

await tour.start();
await click(document.querySelector('.shepherd-content .next-button'));
await click('.shepherd-content .next-button');
});

test('scrollTo works without a custom scrollToHandler', async function(assert) {
Expand All @@ -325,7 +325,7 @@ module('Acceptance | Tour functionality tests', function(hooks) {

await tour.start();

await click(document.querySelector('.shepherd-content .next-button'));
await click('.shepherd-content .next-button');

assert.ok(document.querySelector('#ember-testing-container').scrollTop > 0, 'Scrolled correctly');
});
Expand Down
8 changes: 8 additions & 0 deletions tests/dummy/app/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ export default Route.extend({
tour.set('modal', true);
tour.set('confirmCancel', false);

// Disable animations in the test environment, to ensure timing is correct
if (config.environment === 'test') {
tour.set('defaultStepOptions.tippyOptions', {
delay: 0,
duration: 0
});
}

tour.addSteps(defaultSteps);

tour.on('cancel', () => {
Expand Down