Skip to content

Commit 70e873b

Browse files
authored
Merge pull request #2131 from usablica/fix-position-cy
Add snapshot tests for scrollable elements
2 parents 92ba45d + 727f57f commit 70e873b

File tree

7 files changed

+37
-122
lines changed

7 files changed

+37
-122
lines changed
142 KB
Loading
129 KB
Loading
146 KB
Loading
149 KB
Loading

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"test:prettier": "prettier --check '(src|tests)/**/*.(js|ts|json|html)' '!tests/cypress/setup/dist'",
2828
"test:watch": "jest --watch",
2929
"test:jest": "jest --coverage --silent --ci --coverage --coverageReporters=\"text\" --coverageReporters=\"text-summary\"",
30+
"test:cypress:docker": "start-server-and-test dev http://localhost:10001/dist/intro.js 'docker run -it -v $PWD:/e2e -w /e2e --entrypoint=cypress cypress/included:cypress-13.17.0-node-22.13.0-chrome-131.0.6778.264-1-ff-134.0-edge-131.0.2903.112-1 run --env visualRegressionType=regression'",
3031
"test:cypress": "start-server-and-test dev http://localhost:10001/dist/intro.js 'docker run -it -v $PWD:/e2e -w /e2e --entrypoint=cypress cypress/included:cypress-13.17.0-node-22.13.0-chrome-131.0.6778.264-1-ff-134.0-edge-131.0.2903.112-1 run --env visualRegressionType=regression || cypress run --env visualRegressionType=regression'",
3132
"release": "./bin/release.sh || true",
3233
"prebuild": "rimraf ./dist",

src/packages/tour/position.cy.ts

Lines changed: 36 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,58 @@
1-
describe("Intro.js tooltip position with scrollable container", () => {
1+
context("Intro.js tooltip position with scrollable container", () => {
22
beforeEach(() => {
33
cy.visit("./cypress/setup/index.html");
44

5-
// intro.js CSS
6-
cy.document().then((doc) => {
7-
if (!doc.getElementById("introjs-css")) {
8-
const link = doc.createElement("link");
9-
link.id = "introjs-css";
10-
link.rel = "stylesheet";
11-
link.href = "https://unpkg.com/intro.js/minified/introjs.min.css";
12-
doc.head.appendChild(link);
13-
}
14-
});
15-
165
// scrollable container and target element
176
cy.document().then((doc) => {
187
const container = doc.createElement("div");
198
container.id = "scrollable-container";
209
container.style.cssText =
21-
"height: 600px; overflow-y: auto; border: 2px solid gray; margin-bottom: 20px;";
22-
23-
const inner = doc.createElement("div");
24-
inner.style.height = "1000px";
25-
inner.style.position = "relative";
26-
27-
const target = doc.createElement("div");
28-
target.id = "target-element";
29-
target.style.cssText =
30-
"margin-top: 800px; background-color: yellow; padding: 10px;";
31-
target.setAttribute("data-intro", "Scrollable test element");
32-
target.textContent = "Step Element (scrollable test)";
33-
34-
inner.appendChild(target);
35-
container.appendChild(inner);
10+
"height: 600px; overflow-y: scroll; border: 2px solid gray; margin-bottom: 20px;";
11+
12+
const getTargetElement = (id, marginTop, label) => {
13+
const target = doc.createElement("div");
14+
target.id = id;
15+
target.style.cssText = `margin-top: ${marginTop}; background-color: yellow; padding: 10px;`;
16+
target.setAttribute("data-intro", label);
17+
target.textContent = `Step Element (${label})`;
18+
return target;
19+
};
20+
21+
container.appendChild(
22+
getTargetElement(
23+
"scrollable-target-element-1",
24+
"5px",
25+
"First Scrollable Step"
26+
)
27+
);
28+
container.appendChild(
29+
getTargetElement(
30+
"scrollable-target-element-2",
31+
"800px",
32+
"Second Scrollable Step"
33+
)
34+
);
3635
doc.body.prepend(container);
3736
});
38-
39-
// intro.js script and initialize tour
40-
cy.window().then((win) => {
41-
return new Promise((resolve) => {
42-
const script = win.document.createElement("script");
43-
script.src = "https://unpkg.com/intro.js/minified/intro.min.js";
44-
script.onload = () => {
45-
const tour = win.introJs.tour();
46-
tour.setOptions({
47-
steps: [
48-
{ element: "#target-element", intro: "Scrollable test tooltip" },
49-
{
50-
element: "#target-element",
51-
intro: "Scrollable test tooltip 2",
52-
},
53-
],
54-
});
55-
win.__testTour = tour;
56-
resolve();
57-
};
58-
win.document.head.appendChild(script);
59-
});
60-
});
6137
});
6238

6339
it("scrolls and ensures tooltip is correctly positioned near target", () => {
6440
cy.get("#scrollable-container").scrollTo("top");
65-
cy.get("#target-element")
66-
.scrollIntoView({ block: "center" })
67-
.should("be.visible");
6841

6942
cy.window().then((win) => {
70-
win.__testTour.start();
71-
});
72-
73-
cy.get(".introjs-tooltip", { timeout: 500 }).should("be.visible");
74-
75-
cy.get("#target-element").then(($target) => {
76-
const targetRect = $target[0].getBoundingClientRect();
77-
78-
cy.get(".introjs-tooltip").then(($tooltip) => {
79-
const tooltipRect = $tooltip[0].getBoundingClientRect();
43+
cy.compareSnapshot("scrollable-first-step");
8044

81-
cy.log("Target Rect:", JSON.stringify(targetRect));
82-
cy.log("Tooltip Rect:", JSON.stringify(tooltipRect));
45+
win.introJs.tour().start();
46+
cy.wait(500);
47+
cy.compareSnapshot("scrollable-second-step");
8348

84-
const horizontallySeparate =
85-
tooltipRect.right < targetRect.left ||
86-
tooltipRect.left > targetRect.right;
87-
const verticallySeparate =
88-
tooltipRect.bottom < targetRect.top ||
89-
tooltipRect.top > targetRect.bottom;
90-
expect(horizontallySeparate || verticallySeparate).to.be.true;
49+
cy.nextStep();
50+
cy.wait(500);
51+
cy.compareSnapshot("scrollable-third-step");
9152

92-
const verticalDistance = Math.min(
93-
Math.abs(tooltipRect.top - targetRect.bottom),
94-
Math.abs(targetRect.top - tooltipRect.bottom)
95-
);
96-
expect(verticalDistance).to.be.lessThan(16);
97-
});
53+
cy.nextStep();
54+
cy.wait(800);
55+
cy.compareSnapshot("scrollable-fourth-step");
9856
});
9957
});
10058
});

src/packages/tour/position.test.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)