Skip to content

Commit e0fdfc6

Browse files
committed
chore: tour tests
1 parent e9a3097 commit e0fdfc6

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

tests/helper.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,16 @@ export function doneButton() {
4949
export function tooltipText() {
5050
return find(".introjs-tooltiptext");
5151
}
52+
53+
/**
54+
* @returns {Element}
55+
*/
56+
export function appendDummyElement(name, text, style) {
57+
const el = document.createElement(name || "p");
58+
el.innerHTML = text || "hello world";
59+
el.style = style;
60+
61+
document.body.appendChild(el);
62+
63+
return el;
64+
}

tests/index.test.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
prevButton,
88
doneButton,
99
tooltipText,
10+
appendDummyElement,
1011
} from "./helper";
1112

1213
describe("intro", () => {
@@ -139,4 +140,75 @@ describe("intro", () => {
139140
"introjs-relativePosition"
140141
);
141142
});
143+
144+
test("should highlight the target element", () => {
145+
const p = appendDummyElement();
146+
147+
introJs()
148+
.setOptions({
149+
steps: [
150+
{
151+
intro: "step one",
152+
element: document.querySelector("p"),
153+
},
154+
],
155+
})
156+
.start();
157+
158+
expect(p.className).toContain("introjs-showElement");
159+
expect(p.className).toContain("introjs-relativePosition");
160+
});
161+
162+
test("should not highlight the target element if queryString is incorrect", () => {
163+
const p = appendDummyElement();
164+
165+
introJs()
166+
.setOptions({
167+
steps: [
168+
{
169+
intro: "step one",
170+
element: document.querySelector("div"),
171+
},
172+
],
173+
})
174+
.start();
175+
176+
expect(p.className).not.toContain("introjs-showElement");
177+
expect(className(".introjs-showElement")).toContain(
178+
"introjsFloatingElement"
179+
);
180+
});
181+
182+
test("should not add relativePosition if target element is fixed or absolute", () => {
183+
const absolute = appendDummyElement(
184+
"h1",
185+
"hello world",
186+
"position: absolute"
187+
);
188+
const fixed = appendDummyElement("h2", "hello world", "position: fixed");
189+
190+
const intro = introJs();
191+
intro
192+
.setOptions({
193+
steps: [
194+
{
195+
intro: "step one",
196+
element: document.querySelector("h1"),
197+
},
198+
{
199+
intro: "step two",
200+
element: document.querySelector("h2"),
201+
},
202+
],
203+
})
204+
.start();
205+
206+
expect(absolute.className).toContain("introjs-showElement");
207+
expect(absolute.className).not.toContain("introjs-relativePosition");
208+
209+
intro.nextStep();
210+
211+
expect(fixed.className).toContain("introjs-showElement");
212+
expect(fixed.className).not.toContain("introjs-relativePosition");
213+
});
142214
});

0 commit comments

Comments
 (0)