|
7 | 7 | prevButton,
|
8 | 8 | doneButton,
|
9 | 9 | tooltipText,
|
| 10 | + appendDummyElement, |
10 | 11 | } from "./helper";
|
11 | 12 |
|
12 | 13 | describe("intro", () => {
|
@@ -139,4 +140,75 @@ describe("intro", () => {
|
139 | 140 | "introjs-relativePosition"
|
140 | 141 | );
|
141 | 142 | });
|
| 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 | + }); |
142 | 214 | });
|
0 commit comments