Skip to content

Commit ecbc311

Browse files
author
Arnold
committed
feature: add tests for multiple highlights
1 parent d813dea commit ecbc311

File tree

4 files changed

+88
-11
lines changed

4 files changed

+88
-11
lines changed

test/cypress/integration/test.acceptance.cy.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,41 @@ describe('Shepherd Acceptance Tests', () => {
361361
'#dummyTarget is the target'
362362
);
363363
});
364-
});
364+
});
365+
366+
it.only('correctly selects multiple elements', () => {
367+
cy.document().then((document) => {
368+
const steps = () => {
369+
return [
370+
{
371+
text: 'Multiple selection works too!',
372+
attachTo: {
373+
element: '.hero-multiple div',
374+
on: 'bottom',
375+
multiple: true
376+
},
377+
id: 'multipleStep'
378+
}
379+
];
380+
};
381+
382+
const tour = setupTour(Shepherd, {
383+
cancelIcon: {
384+
enabled: false
385+
}
386+
}, steps);
387+
388+
tour.start();
389+
390+
cy.get('[data-shepherd-step-id="multipleStep"] .shepherd-text')
391+
.contains('Multiple selection works too!').should('be.visible');
392+
assert.deepEqual(
393+
[...document.querySelectorAll('.hero-multiple div')],
394+
tour.getCurrentStep().target,
395+
'#multiple-targets are in the target'
396+
);
397+
});
398+
});
365399
});
366400

367401
describe('buttons', () => {

test/dummy/css/welcome.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ body {
6767
text-align: center;
6868
}
6969

70+
.hero-multiple {
71+
display: flex;
72+
justify-content: space-between;
73+
}
74+
75+
.hero-multiple div {
76+
display: block;
77+
width: 30%;
78+
height: 100px;
79+
text-align: center;
80+
}
81+
7082
.demo-heading {
7183
color: #00213B;
7284
}

test/dummy/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ <h1>Shepherd</h1>
3333
<h2>Guide your users through a tour of your app.</h2>
3434
</div>
3535

36+
<div class="hero-multiple">
37+
<div>Block 1</div>
38+
<div>Block 2</div>
39+
<div>Block 3</div>
40+
</div>
3641
<div class="hero-including" data-test-hero-including>
3742
<h3>Including</h3>
3843

test/unit/utils/general.spec.js

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { spy } from 'sinon';
22
import { Step } from '../../../src/js/step.js';
33
import { getPopperOptions, parseAttachTo, shouldCenterStep } from '../../../src/js/utils/general.js';
44

5-
describe('General Utils', function() {
5+
describe('General Utils', function () {
66
let optionsElement;
77

88
beforeEach(() => {
@@ -15,8 +15,8 @@ describe('General Utils', function() {
1515
document.body.removeChild(optionsElement);
1616
});
1717

18-
describe('parseAttachTo()', function() {
19-
it('fails if element does not exist', function() {
18+
describe('parseAttachTo()', function () {
19+
it('fails if element does not exist', function () {
2020
const step = new Step({}, {
2121
attachTo: { element: '.element-does-not-exist', on: 'center' }
2222
});
@@ -25,7 +25,7 @@ describe('General Utils', function() {
2525
expect(element).toBeFalsy();
2626
});
2727

28-
it('accepts callback function as element', function() {
28+
it('accepts callback function as element', function () {
2929
const callback = spy();
3030

3131
const step = new Step({}, {
@@ -36,7 +36,7 @@ describe('General Utils', function() {
3636
expect(callback.called).toBe(true);
3737
});
3838

39-
it('correctly resolves elements when given function that returns a selector', function() {
39+
it('correctly resolves elements when given function that returns a selector', function () {
4040
const step = new Step({}, {
4141
attachTo: { element: () => 'body', on: 'center' }
4242
});
@@ -45,7 +45,7 @@ describe('General Utils', function() {
4545
expect(element[0]).toBe(document.body);
4646
});
4747

48-
it('binds element callback to step', function() {
48+
it('binds element callback to step', function () {
4949
const step = new Step({}, {
5050
attachTo: {
5151
element() {
@@ -57,10 +57,36 @@ describe('General Utils', function() {
5757

5858
parseAttachTo(step);
5959
});
60+
61+
it('returns all selected elements if multiple flag enabled', function () {
62+
const elements = [];
63+
const addNode = () => {
64+
const el = document.createElement('div');
65+
el.className = 'multiple-item';
66+
document.body.appendChild(el);
67+
return el;
68+
};
69+
70+
elements.push(addNode());
71+
elements.push(addNode());
72+
73+
const step = new Step({}, {
74+
attachTo: {
75+
element: '.multiple-item',
76+
on: 'center',
77+
multiple: true
78+
}
79+
});
80+
81+
const { element } = parseAttachTo(step);
82+
elements.forEach((el, index) => {
83+
expect(element[index]).toBe(el);
84+
})
85+
});
6086
});
6187

62-
describe('getPopperOptions', function() {
63-
it('modifiers can be overridden', function() {
88+
describe('getPopperOptions', function () {
89+
it('modifiers can be overridden', function () {
6490
const step = new Step({}, {
6591
attachTo: { element: '.options-test', on: 'right' },
6692
popperOptions: {
@@ -79,7 +105,7 @@ describe('General Utils', function() {
79105
expect(popperOptions.modifiers[1].options.altAxis).toBe(false);
80106
});
81107

82-
it('positioning strategy is explicitly set', function() {
108+
it('positioning strategy is explicitly set', function () {
83109
const step = new Step({}, {
84110
attachTo: { element: '.options-test', on: 'center' },
85111
options: {
@@ -138,7 +164,7 @@ describe('General Utils', function() {
138164
})
139165

140166
it('Returns true when element property is null', () => {
141-
const elementAttachTo = { element: null}; // FAILS
167+
const elementAttachTo = { element: null }; // FAILS
142168

143169
expect(shouldCenterStep(elementAttachTo)).toBe(true)
144170
})

0 commit comments

Comments
 (0)