8
8
] , function ( bindClickToLinkInitializerWidget , $ ) {
9
9
'use strict' ;
10
10
11
- var $el ;
11
+ var $el ,
12
+ originalRedirectTo = bindClickToLinkInitializerWidget . redirectTo ;
12
13
13
14
afterEach ( function ( ) {
14
15
if ( $el !== undefined ) {
@@ -19,9 +20,11 @@ define([
19
20
describe ( 'Magento_PageBuilder/js/widget/bind-click-to-data-link-element' , function ( ) {
20
21
it ( 'Should not navigate away from page if it is missing href attribute' , function ( ) {
21
22
spyOn ( bindClickToLinkInitializerWidget , 'redirectTo' ) ;
23
+ spyOn ( window , 'open' ) ;
24
+
22
25
$el = $ (
23
26
'<div data-role="content-type">' +
24
- '<div data-link-type="link" href="">' +
27
+ '<div data-link-type="link" href="" target >' +
25
28
'<span class="span-outside-inner-anchor">Hello world</span>' +
26
29
'<a class="inner-anchor" href="https://something.com"><span>Something</span></a>' +
27
30
'</div>' +
@@ -35,13 +38,16 @@ define([
35
38
$el . find ( '.span-outside-inner-anchor' ) . click ( ) ;
36
39
37
40
expect ( bindClickToLinkInitializerWidget . redirectTo ) . not . toHaveBeenCalled ( ) ;
41
+ expect ( window . open ) . not . toHaveBeenCalled ( ) ;
38
42
} ) ;
39
43
40
44
it ( 'Should not navigate away from page if href is javascript:void(0)' , function ( ) {
41
45
spyOn ( bindClickToLinkInitializerWidget , 'redirectTo' ) ;
46
+ spyOn ( window , 'open' ) ;
47
+
42
48
$el = $ (
43
49
'<div data-role="content-type">' +
44
- '<div data-link-type="link" href="javascript:void(0)">' +
50
+ '<div data-link-type="link" href="javascript:void(0)" target >' +
45
51
'<span class="span-outside-inner-anchor">Hello world</span>' +
46
52
'<a class="inner-anchor" href="https://something.com"><span>Something</span></a>' +
47
53
'</div>' +
@@ -55,13 +61,16 @@ define([
55
61
$el . find ( '.span-outside-inner-anchor' ) . click ( ) ;
56
62
57
63
expect ( bindClickToLinkInitializerWidget . redirectTo ) . not . toHaveBeenCalled ( ) ;
64
+ expect ( window . open ) . not . toHaveBeenCalled ( ) ;
58
65
} ) ;
59
66
60
67
it ( 'Should not navigate away from page if it is missing data-link-type attribute' , function ( ) {
61
68
spyOn ( bindClickToLinkInitializerWidget , 'redirectTo' ) ;
69
+ spyOn ( window , 'open' ) ;
70
+
62
71
$el = $ (
63
72
'<div data-role="content-type">' +
64
- '<div href="https://adobe.com">' +
73
+ '<div href="https://adobe.com" target >' +
65
74
'<span class="span-outside-inner-anchor">Hello world</span>' +
66
75
'<a class="inner-anchor" href="https://something.com"><span>Something</span></a>' +
67
76
'</div>' +
@@ -75,14 +84,16 @@ define([
75
84
$el . find ( '.span-outside-inner-anchor' ) . click ( ) ;
76
85
77
86
expect ( bindClickToLinkInitializerWidget . redirectTo ) . not . toHaveBeenCalled ( ) ;
87
+ expect ( window . open ) . not . toHaveBeenCalled ( ) ;
78
88
} ) ;
79
89
80
90
it ( 'Should not navigate to an simulated anchor\'s href if clicked inside of nested anchor' , function ( ) {
81
91
spyOn ( bindClickToLinkInitializerWidget , 'redirectTo' ) ;
92
+ spyOn ( window , 'open' ) ;
82
93
83
94
$el = $ (
84
95
'<div data-role="content-type">' +
85
- '<div data-link-type="link" href="https://adobe.com">' +
96
+ '<div data-link-type="link" href="https://adobe.com" target >' +
86
97
'<span class="span-outside-inner-anchor">Hello world</span>' +
87
98
'<a class="inner-anchor" href="https://something.com"><span>Something</span></a>' +
88
99
'</div>' +
@@ -96,14 +107,16 @@ define([
96
107
$el . find ( '.inner-anchor' ) . click ( ) ;
97
108
98
109
expect ( bindClickToLinkInitializerWidget . redirectTo ) . not . toHaveBeenCalled ( ) ;
110
+ expect ( window . open ) . not . toHaveBeenCalled ( ) ;
99
111
} ) ;
100
112
101
113
it ( 'Should navigate to an simulated anchor\'s href if clicked outside of nested anchor' , function ( ) {
102
114
spyOn ( bindClickToLinkInitializerWidget , 'redirectTo' ) ;
115
+ spyOn ( window , 'open' ) ;
103
116
104
117
$el = $ (
105
118
'<div data-role="content-type">' +
106
- '<div data-link-type="link" href="https://adobe.com">' +
119
+ '<div data-link-type="link" href="https://adobe.com" target >' +
107
120
'<span class="span-outside-inner-anchor">Hello world</span>' +
108
121
'<a class="inner-anchor" href="https://something.com"><span>Something</span></a>' +
109
122
'</div>' +
@@ -116,7 +129,35 @@ define([
116
129
117
130
$el . find ( '.span-outside-inner-anchor' ) . click ( ) ;
118
131
119
- expect ( bindClickToLinkInitializerWidget . redirectTo ) . toHaveBeenCalledWith ( 'https://adobe.com' ) ;
132
+ expect ( bindClickToLinkInitializerWidget . redirectTo ) . toHaveBeenCalledWith ( 'https://adobe.com' , '' ) ;
133
+
134
+ originalRedirectTo ( 'https://adobe.com' , '' ) ;
135
+ expect ( window . open ) . not . toHaveBeenCalled ( ) ;
136
+ } ) ;
137
+
138
+ it ( 'Should call window.open if target is _blank' , function ( ) {
139
+ spyOn ( window , 'open' ) ;
140
+ spyOn ( bindClickToLinkInitializerWidget , 'redirectTo' ) ;
141
+
142
+ $el = $ (
143
+ '<div data-role="content-type">' +
144
+ '<div data-link-type="link" href="https://adobe.com" target="_blank">' +
145
+ '<span class="span-outside-inner-anchor">Hello world</span>' +
146
+ '<a class="inner-anchor" href="https://something.com"><span>Something</span></a>' +
147
+ '</div>' +
148
+ '</div>'
149
+ ) ;
150
+
151
+ $el . appendTo ( 'body' ) ;
152
+
153
+ bindClickToLinkInitializerWidget ( null , $el ) ;
154
+
155
+ $el . find ( '.span-outside-inner-anchor' ) . click ( ) ;
156
+
157
+ expect ( bindClickToLinkInitializerWidget . redirectTo ) . toHaveBeenCalledWith ( 'https://adobe.com' , '_blank' ) ;
158
+
159
+ originalRedirectTo ( 'https://adobe.com' , '_blank' ) ;
160
+ expect ( window . open ) . toHaveBeenCalledWith ( 'https://adobe.com' , '_blank' ) ;
120
161
} ) ;
121
162
} ) ;
122
163
} ) ;
0 commit comments