Skip to content

Commit 8bec34f

Browse files
authored
Merge pull request usablica#1259 from usablica/more-e2e-tests
chore: adding element highlight tests
2 parents ff27afc + 3d437e6 commit 8bec34f

13 files changed

+75
-10
lines changed

tests/cypress/integration/tour/highlight.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,30 @@ context('Highlight', () => {
33
cy.visit('./cypress/setup/index.html');
44
});
55

6+
it('should highlight the target element', () => {
7+
cy.window()
8+
.then(window => {
9+
window.introJs().setOptions({
10+
steps: [{
11+
intro: "step one"
12+
}, {
13+
element: "#clickable-button",
14+
intro: "step two"
15+
}]
16+
}).start();
17+
18+
cy.wait(500);
19+
20+
cy.compareSnapshot('highlight-element-first-step', 0);
21+
22+
cy.nextStep();
23+
24+
cy.wait(800);
25+
26+
cy.compareSnapshot('highlight-element-second-step', 0);
27+
});
28+
});
29+
630
it('should let user interact with the target element', () => {
731
cy.window()
832
.then(window => {
@@ -17,7 +41,7 @@ context('Highlight', () => {
1741

1842
let sp = cy.spy(window, "click");
1943

20-
cy.get('.introjs-nextbutton').click();
44+
cy.nextStep();
2145
cy.get('.introjs-tooltiptext').contains('step two');
2246

2347
cy.get(".introjs-helperLayer").realHover();

tests/cypress/integration/tour/modal.js

+35-2
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,48 @@ context('Modal', () => {
1717

1818
cy.compareSnapshot('first-step', 0);
1919

20-
cy.get('.introjs-nextbutton').click();
20+
cy.nextStep();
2121
cy.wait(800);
2222

2323
cy.compareSnapshot('second-step', 0);
2424

25-
cy.get('.introjs-nextbutton').click();
25+
cy.nextStep();
2626
cy.wait(800);
2727

2828
cy.compareSnapshot('exit', 0);
2929
});
3030
});
31+
32+
it('should set the position', () => {
33+
cy.window().then((win) => {
34+
cy.viewport('macbook-13');
35+
36+
win.introJs().setOptions({
37+
steps: [{
38+
element: '#main-section',
39+
intro: 'position bottom',
40+
position: 'bottom'
41+
}, {
42+
element: '#clickable-button',
43+
intro: 'position right',
44+
position: 'right'
45+
}, {
46+
element: '#clickable-absolute-button',
47+
intro: 'position left',
48+
position: 'left'
49+
}]
50+
}).start();
51+
52+
cy.wait(800);
53+
cy.compareSnapshot('position-bottom', 0);
54+
55+
cy.nextStep();
56+
cy.wait(500);
57+
cy.compareSnapshot('position-right', 0);
58+
59+
cy.nextStep();
60+
cy.wait(500);
61+
cy.compareSnapshot('position-left', 0);
62+
});
63+
});
3164
});

tests/cypress/integration/tour/navigation.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,28 @@ context('Navigation', () => {
1313

1414
it('should go to the next step', () => {
1515
cy.get('.introjs-tooltiptext').contains('step one');
16-
cy.get('.introjs-nextbutton').click();
16+
cy.nextStep();
1717
cy.get('.introjs-tooltiptext').contains('step two');
1818
});
1919

2020
it('previous button should be disabled', () => {
2121
cy.get('.introjs-tooltiptext').contains('step one');
2222
cy.get('.introjs-prevbutton').should('have.class', 'introjs-disabled');
23-
cy.get('.introjs-prevbutton').click();
23+
cy.prevStep();
2424
cy.get('.introjs-tooltiptext').contains('step one');
2525
});
2626

2727
it('should go to the previous step', () => {
2828
cy.get('.introjs-tooltiptext').contains('step one');
29-
cy.get('.introjs-nextbutton').click();
29+
cy.nextStep();
3030
cy.get('.introjs-tooltiptext').contains('step two');
31-
cy.get('.introjs-prevbutton').click();
31+
cy.prevStep();
3232
cy.get('.introjs-tooltiptext').contains('step one');
3333
});
3434

3535
it('should exit the tour after clicking on Done', () => {
3636
cy.get('.introjs-tooltiptext').contains('step one');
37-
cy.get('.introjs-nextbutton').click();
37+
cy.nextStep();
3838
cy.get('.introjs-tooltiptext').contains('step two');
3939
cy.get('.introjs-donebutton').should('exist');
4040
cy.get('.introjs-donebutton').click();

tests/cypress/setup/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
</header>
2626

2727
<div class="p-5 mb-4 bg-light rounded-3">
28-
<div class="container-fluid py-5">
28+
<div class="container-fluid py-5" id="main-section">
2929
<h1 class="display-5 fw-bold">Custom jumbotron</h1>
3030
<p class="col-md-8 fs-4">Using a series of utilities, you can create this jumbotron, just like the one in previous versions of Bootstrap. Check out the examples below for how you can remix and restyle it to your liking.</p>
3131
<button class="btn btn-primary btn-lg" type="button" id="clickable-button" onclick="window.click()" onmouseover="this.innerHTML='Hovered'">Example button</button>
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

tests/cypress/support/commands.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ const compareSnapshotCommand = require('cypress-visual-regression/dist/command')
2828

2929
compareSnapshotCommand({
3030
capture: 'fullPage'
31-
});
31+
});
32+
33+
Cypress.Commands.add('nextStep', () => {
34+
cy.get('.introjs-nextbutton').click();
35+
});
36+
37+
Cypress.Commands.add('prevStep', () => {
38+
cy.get('.introjs-prevbutton').click();
39+
});

0 commit comments

Comments
 (0)