Skip to content

Commit

Permalink
Use data attributes for test selectors (#299)
Browse files Browse the repository at this point in the history
Resolves #273
  • Loading branch information
RobbieTheWagner authored Dec 6, 2018
1 parent 1740291 commit 95f9afa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions test/cypress/integration/element-targeting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Attaching tooltips to target elements in the DOM on each step', () =>
it('Adds the "shepherd-target" and "shepherd-enabled" classes upon showing a step', () => {
tour.start();

cy.get('.hero-welcome')
cy.get('[data-test-hero-welcome]')
.should('have.class', 'shepherd-target')
.and('have.class', 'shepherd-enabled');
});
Expand All @@ -40,7 +40,7 @@ describe('Attaching tooltips to target elements in the DOM on each step', () =>
tour.start();
tour.next();

cy.get('.hero-welcome')
cy.get('[data-test-hero-welcome]')
.should('not.have.class', 'shepherd-target')
.and('not.have.class', 'shepherd-enabled');
});
Expand Down
12 changes: 6 additions & 6 deletions test/cypress/integration/test.acceptance.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ describe('Shepherd Acceptance Tests', () => {
.contains('Shepherd is a JavaScript library').should('be.visible');

cy.document().then((document) => {
assert.deepEqual(document.querySelector('.hero-welcome'), tour.getCurrentStep().target, '.hero-welcome is the target');
assert.deepEqual(document.querySelector('[data-test-hero-welcome]'), tour.getCurrentStep().target, 'hero welcome is the target');
});
});

it('works with DOM elements', () => {
cy.document().then((document) => {
const heroIncludingElement = document.querySelector('.hero-including');
const heroIncludingElement = document.querySelector('[data-test-hero-including]');

const steps = () => {
return [
Expand Down Expand Up @@ -192,19 +192,19 @@ describe('Shepherd Acceptance Tests', () => {
scrollTo: true
});
tour.start();
cy.get('.hero-scroll').should('have.prop', 'scrollTop').and('eq', 0);
cy.get('[data-test-hero-scroll]').should('have.prop', 'scrollTop').and('eq', 0);
cy.contains('Next').click();
cy.get('.hero-scroll').should('have.prop', 'scrollTop').and('gt', 0);
cy.get('[data-test-hero-scroll]').should('have.prop', 'scrollTop').and('gt', 0);
});

it('scrollTo:false does not scroll', () => {
const tour = setupTour(Shepherd, {
scrollTo: false
});
tour.start();
cy.get('.hero-scroll').should('have.prop', 'scrollTop').and('eq', 0);
cy.get('[data-test-hero-scroll]').should('have.prop', 'scrollTop').and('eq', 0);
cy.contains('Next').click();
cy.get('.hero-scroll').should('have.prop', 'scrollTop').and('eq', 0);
cy.get('[data-test-hero-scroll]').should('have.prop', 'scrollTop').and('eq', 0);
});
});
});
Expand Down
6 changes: 3 additions & 3 deletions test/dummy/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
</head>

<body>
<div class="hero-scroll">
<div class="hero-scroll" data-test-hero-scroll>
<div class="hero-outer">
<div class="hero-inner">
<div class="hero-welcome">
<div class="hero-welcome" data-test-hero-welcome>
<h1>Shepherd</h1>

<h2>Guide your users through a tour of your app.</h2>
</div>

<div class="hero-including">
<div class="hero-including" data-test-hero-including>
<h3>Including</h3>

<script type="text/plain" class="language-markup" id="hero-including-code">
Expand Down

0 comments on commit 95f9afa

Please sign in to comment.