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

Remove cleanupShepherdElements #247

Merged
merged 2 commits into from
Sep 18, 2018
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
4 changes: 1 addition & 3 deletions addon/services/tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {
getElementForStep,
removeElement,
setPositionForHighlightElement,
toggleShepherdModalClass,
cleanupShepherdElements
toggleShepherdModalClass
} from '../utils';

export default Service.extend(Evented, {
Expand All @@ -28,7 +27,6 @@ export default Service.extend(Evented, {
steps: [],

willDestroy() {
cleanupShepherdElements();
this.cleanup();
},

Expand Down
13 changes: 1 addition & 12 deletions addon/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,11 @@ function toggleShepherdModalClass(currentElement) {
currentElement.classList.add('shepherd-modal');
}

function cleanupShepherdElements() {
document.body.classList.remove('shepherd-active');
document.querySelectorAll('[class^=shepherd]').forEach((el) => {
el.parentNode.removeChild(el);
});
document.querySelectorAll('[id^=shepherd]').forEach((el) => {
el.parentNode.removeChild(el);
});
}

export {
elementIsHidden,
getElementForStep,
getElementPosition,
removeElement,
setPositionForHighlightElement,
toggleShepherdModalClass,
cleanupShepherdElements
toggleShepherdModalClass
};
35 changes: 23 additions & 12 deletions tests/acceptance/ember-shepherd-test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { module, test } from 'qunit';
import { visit, click, find } from '@ember/test-helpers';
import { later } from '@ember/runloop';
import { setupApplicationTest } from 'ember-qunit';
import { builtInButtons } from '../data';


module('Acceptance | Tour functionality tests', function(hooks) {
let tour;

Expand Down Expand Up @@ -116,11 +116,13 @@ module('Acceptance | Tour functionality tests', function(hooks) {

await click('.toggleHelpModal');

assert.ok(document.querySelector('.highlight'), 'currentElement highlighted');
assert.ok(tour.get('tourObject').currentStep.target.classList.contains('highlight'),
'currentElement has highlightClass applied');

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

assert.notOk(document.querySelector('.highlight'), 'highlightClass removed on cancel');
assert.notOk(tour.get('tourObject').currentStep.target.classList.contains('highlight'),
'highlightClass removed on cancel');
});

test('Highlight applied when `tour.modal == false`', async function(assert) {
Expand All @@ -145,11 +147,13 @@ module('Acceptance | Tour functionality tests', function(hooks) {

await click('.toggleHelpNonmodal');

assert.ok(document.querySelector('.highlight'), 'currentElement highlighted');
assert.ok(tour.get('tourObject').currentStep.target.classList.contains('highlight'),
'currentElement has highlightClass applied');

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

assert.notOk(document.querySelector('.highlight'), 'highlightClass removed on cancel');
assert.notOk(tour.get('tourObject').currentStep.target.classList.contains('highlight'),
'highlightClass removed on cancel');
});

test('Defaults applied', async function(assert) {
Expand Down Expand Up @@ -351,6 +355,9 @@ module('Acceptance | Tour functionality tests', function(hooks) {

test('scrollTo works with a custom scrollToHandler', async function(assert) {
assert.expect(2);

const done = assert.async();

// Override default behavior
const steps = [{
id: 'intro',
Expand All @@ -362,7 +369,11 @@ module('Acceptance | Tour functionality tests', function(hooks) {
],
scrollTo: true,
scrollToHandler() {
return document.querySelector('#ember-testing-container').scrollTop = 120;
document.querySelector('#ember-testing-container').scrollTop = 120;
return later(() => {
assert.equal(document.querySelector('#ember-testing-container').scrollTop, 120, 'Scrolled correctly');
done();
}, 50);
}
}
}];
Expand All @@ -377,8 +388,6 @@ module('Acceptance | Tour functionality tests', function(hooks) {

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

assert.ok(document.querySelector('#ember-testing-container').scrollTop === 120, 'Scrolled correctly');
});

test('scrollTo works without a custom scrollToHandler', async function(assert) {
Expand All @@ -399,12 +408,14 @@ module('Acceptance | Tour functionality tests', function(hooks) {
assert.ok(document.querySelector('#ember-testing-container').scrollTop > 0, 'Scrolled correctly');
});

test('Shows by id works', async function(assert) {
test('Show by id works', async function(assert) {
assert.expect(1);

await visit('/');

tour.show('usage');

assert.equal(document.querySelector('.shepherd-element .shepherd-text').textContent,
assert.equal(tour.get('tourObject').currentStep.el.querySelector('.shepherd-text').textContent,
'To use the tour service, simply inject it into your application and use it like this example.',
'Usage step shown');
});
Expand Down