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

add more tests for increased coverage #230

Merged
merged 2 commits into from
Aug 29, 2018
Merged
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
40 changes: 39 additions & 1 deletion test/unit/test.step.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ chai.use(chaiAsPromised);
const { assert } = chai;
import Shepherd from '../../src/js/shepherd.js';
import { Step } from '../../src/js/step.js';
import { Tour } from '../../src/js/tour.js';
// since importing non UMD, needs assignment
window.Shepherd = Shepherd;

Expand All @@ -31,10 +32,21 @@ describe('Step', () => {
});

const showTestStep = instance.addStep('test2', {
buttons: [],
id: 'test2',
text: 'Another Step'
});

// Add more steps for total _setUpButtons coverage
instance.addStep('test3', {
buttons: {
text: 'Next',
action: instance.next
},
id: 'test3',
text: 'Another Step part deux'
});

const beforeShowPromise = new Promise((resolve) => {
return setTimeout(1000, resolve('beforeShowPromise worked!'));
});
Expand Down Expand Up @@ -168,20 +180,23 @@ describe('Step', () => {

describe('bindButtonEvents()', () => {
const link = document.createElement('a');
const step = new Step();
const step = new Step(new Tour(), {});
it('adds button events', () => {
const event = new Event('test');
const hover = new Event('mouseover');
let eventTriggered = false;

step.bindButtonEvents({
events: {
'mouseover': '1',
test: () => eventTriggered = true
},
text: 'Next',
action: () => {}
}, link);

link.dispatchEvent(event);
link.dispatchEvent(hover);
assert.isOk(eventTriggered, 'custom button event was bound/triggered');
});

Expand Down Expand Up @@ -297,6 +312,17 @@ describe('Step', () => {
});
});

describe('getAttachTo()', function(){
it('fails if element does not exist', function(){
const step = new Step({}, {
attachTo: { element: '.scroll-test', on: 'center' }
});

const { element } = step.getAttachTo();
assert.notOk(element);
});
});

describe('render()', () => {
it('calls destroy if element is already set', () => {
const step = new Step();
Expand All @@ -306,6 +332,18 @@ describe('Step', () => {
step.render();
assert.isOk(destroyCalled, 'render method called destroy with element set');
});

it('calls bindAdvance() if advanceOn passed', () => {
const step = new Step({
next: () => true
}, {
advanceOn: '.click-test test'
});
const bindFunction = spy(step, 'bindAdvance');
step.render();

assert.ok(bindFunction.called);
});
});

describe('scrollTo()', () => {
Expand Down