@@ -2,7 +2,18 @@ describe("Intro.js tooltip position with scrollable container", () => {
2
2
beforeEach ( ( ) => {
3
3
cy . visit ( "./cypress/setup/index.html" ) ;
4
4
5
- // Add scrollable container and target element dynamically
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
+
16
+ // scrollable container and target element
6
17
cy . document ( ) . then ( ( doc ) => {
7
18
const container = doc . createElement ( "div" ) ;
8
19
container . id = "scrollable-container" ;
@@ -23,20 +34,9 @@ describe("Intro.js tooltip position with scrollable container", () => {
23
34
inner . appendChild ( target ) ;
24
35
container . appendChild ( inner ) ;
25
36
doc . body . prepend ( container ) ;
26
-
27
- // Add start tour button
28
- let btn = doc . getElementById ( "start-tour" ) ;
29
- if ( ! btn ) {
30
- btn = doc . createElement ( "button" ) ;
31
- btn . id = "start-tour" ;
32
- btn . textContent = "Start Tour" ;
33
- btn . style . display = "block" ;
34
- btn . className = "btn btn-success mb-4" ;
35
- doc . body . prepend ( btn ) ;
36
- }
37
37
} ) ;
38
38
39
- // Inject Intro .js script and initialize tour
39
+ // intro .js script and initialize tour
40
40
cy . window ( ) . then ( ( win ) => {
41
41
return new Promise ( ( resolve ) => {
42
42
const script = win . document . createElement ( "script" ) ;
@@ -51,9 +51,6 @@ describe("Intro.js tooltip position with scrollable container", () => {
51
51
intro : "Scrollable test tooltip 2" ,
52
52
} ,
53
53
] ,
54
- scrollToElement : true ,
55
- scrollTo : "element" ,
56
- tooltipPosition : "bottom" ,
57
54
} ) ;
58
55
win . __testTour = tour ;
59
56
resolve ( ) ;
@@ -64,21 +61,17 @@ describe("Intro.js tooltip position with scrollable container", () => {
64
61
} ) ;
65
62
66
63
it ( "scrolls and ensures tooltip is correctly positioned near target" , ( ) => {
67
- // Scroll target into view within the container
68
64
cy . get ( "#scrollable-container" ) . scrollTo ( "top" ) ;
69
65
cy . get ( "#target-element" )
70
66
. scrollIntoView ( { block : "center" } )
71
67
. should ( "be.visible" ) ;
72
68
73
- // Start the tour
74
69
cy . window ( ) . then ( ( win ) => {
75
70
win . __testTour . start ( ) ;
76
71
} ) ;
77
72
78
- // Wait for tooltip
79
- cy . get ( ".introjs-tooltip" , { timeout : 5000 } ) . should ( "be.visible" ) ;
73
+ cy . get ( ".introjs-tooltip" , { timeout : 500 } ) . should ( "be.visible" ) ;
80
74
81
- // Verify tooltip placement
82
75
cy . get ( "#target-element" ) . then ( ( $target ) => {
83
76
const targetRect = $target [ 0 ] . getBoundingClientRect ( ) ;
84
77
@@ -88,7 +81,6 @@ describe("Intro.js tooltip position with scrollable container", () => {
88
81
cy . log ( "Target Rect:" , JSON . stringify ( targetRect ) ) ;
89
82
cy . log ( "Tooltip Rect:" , JSON . stringify ( tooltipRect ) ) ;
90
83
91
- // Ensure not overlapping
92
84
const horizontallySeparate =
93
85
tooltipRect . right < targetRect . left ||
94
86
tooltipRect . left > targetRect . right ;
@@ -97,12 +89,11 @@ describe("Intro.js tooltip position with scrollable container", () => {
97
89
tooltipRect . top > targetRect . bottom ;
98
90
expect ( horizontallySeparate || verticallySeparate ) . to . be . true ;
99
91
100
- // Ensure tooltip is close to target (±10px tolerance)
101
92
const verticalDistance = Math . min (
102
93
Math . abs ( tooltipRect . top - targetRect . bottom ) ,
103
94
Math . abs ( targetRect . top - tooltipRect . bottom )
104
95
) ;
105
- expect ( verticalDistance ) . to . be . lessThan ( 15 ) ;
96
+ expect ( verticalDistance ) . to . be . lessThan ( 16 ) ;
106
97
} ) ;
107
98
} ) ;
108
99
} ) ;
0 commit comments