Skip to content

Commit 3419b4a

Browse files
committed
MC-3934: Slide/Banner Overlay & Button Do Not Show On Storefront When Set To On Hover
Tweak unit test to prevent calling window.open
1 parent 41e6124 commit 3419b4a

File tree

2 files changed

+10
-27
lines changed

2 files changed

+10
-27
lines changed

app/code/Magento/PageBuilder/view/base/web/js/widget/click-event-binder.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ define(['jquery'], function ($) {
4545
* @param {String} target
4646
*/
4747
clickEventBinder.redirectTo = function (href, target) {
48-
if (target === '_blank') {
49-
window.open(href, target);
50-
} else {
51-
window.location.href = href;
48+
if (!target) {
49+
target = '_self';
5250
}
51+
52+
window.open(href, target, 'noopener');
5353
};
5454

5555
return clickEventBinder;

dev/tests/js/jasmine/tests/app/code/Magento/PageBuilder/view/frontend/web/js/widget/click-event-binder.test.js

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ define([
88
], function (clickEventBinderInitializerWidget, $) {
99
'use strict';
1010

11-
var $el,
12-
originalRedirectTo = clickEventBinderInitializerWidget.redirectTo;
11+
var $el;
1312

1413
afterEach(function () {
1514
if ($el !== undefined) {
@@ -18,9 +17,8 @@ define([
1817
});
1918

2019
describe('Magento_PageBuilder/js/widget/click-event-binder', function () {
21-
it('Should not navigate away from page if it is missing href attribute', function () {
20+
it('Should not navigate away from page if it is missing data-href attribute', function () {
2221
spyOn(clickEventBinderInitializerWidget, 'redirectTo');
23-
spyOn(window, 'open');
2422

2523
$el = $(
2624
'<div data-role="content-type">' +
@@ -38,12 +36,10 @@ define([
3836
$el.find('.span-outside-inner-anchor').click();
3937

4038
expect(clickEventBinderInitializerWidget.redirectTo).not.toHaveBeenCalled();
41-
expect(window.open).not.toHaveBeenCalled();
4239
});
4340

44-
it('Should not navigate away from page if href is javascript:void(0)', function () {
41+
it('Should not navigate away from page if data-href is javascript:void(0)', function () {
4542
spyOn(clickEventBinderInitializerWidget, 'redirectTo');
46-
spyOn(window, 'open');
4743

4844
$el = $(
4945
'<div data-role="content-type">' +
@@ -61,12 +57,10 @@ define([
6157
$el.find('.span-outside-inner-anchor').click();
6258

6359
expect(clickEventBinderInitializerWidget.redirectTo).not.toHaveBeenCalled();
64-
expect(window.open).not.toHaveBeenCalled();
6560
});
6661

6762
it('Should not navigate away from page if it is missing data-link-type attribute', function () {
6863
spyOn(clickEventBinderInitializerWidget, 'redirectTo');
69-
spyOn(window, 'open');
7064

7165
$el = $(
7266
'<div data-role="content-type">' +
@@ -84,12 +78,10 @@ define([
8478
$el.find('.span-outside-inner-anchor').click();
8579

8680
expect(clickEventBinderInitializerWidget.redirectTo).not.toHaveBeenCalled();
87-
expect(window.open).not.toHaveBeenCalled();
8881
});
8982

90-
it('Should not navigate to simulated anchor\'s href if clicked inside of nested anchor', function () {
83+
it('Should not navigate to simulated anchor\'s data-href if clicked inside of nested anchor', function () {
9184
spyOn(clickEventBinderInitializerWidget, 'redirectTo');
92-
spyOn(window, 'open');
9385

9486
$el = $(
9587
'<div data-role="content-type">' +
@@ -107,12 +99,10 @@ define([
10799
$el.find('.inner-anchor').click();
108100

109101
expect(clickEventBinderInitializerWidget.redirectTo).not.toHaveBeenCalled();
110-
expect(window.open).not.toHaveBeenCalled();
111102
});
112103

113-
it('Should navigate to simulated anchor\'s href if clicked outside of nested anchor', function () {
104+
it('Should navigate to simulated anchor\'s data-href if clicked outside of nested anchor', function () {
114105
spyOn(clickEventBinderInitializerWidget, 'redirectTo');
115-
spyOn(window, 'open');
116106

117107
$el = $(
118108
'<div data-role="content-type">' +
@@ -130,13 +120,9 @@ define([
130120
$el.find('.span-outside-inner-anchor').click();
131121

132122
expect(clickEventBinderInitializerWidget.redirectTo).toHaveBeenCalledWith('https://adobe.com', '');
133-
134-
originalRedirectTo('https://adobe.com', '');
135-
expect(window.open).not.toHaveBeenCalled();
136123
});
137124

138-
it('Should call window.open if data-target is _blank', function () {
139-
spyOn(window, 'open');
125+
it('Should call .redirectTo with _blank target if data-target is _blank', function () {
140126
spyOn(clickEventBinderInitializerWidget, 'redirectTo');
141127

142128
$el = $(
@@ -155,9 +141,6 @@ define([
155141
$el.find('.span-outside-inner-anchor').click();
156142

157143
expect(clickEventBinderInitializerWidget.redirectTo).toHaveBeenCalledWith('https://adobe.com', '_blank');
158-
159-
originalRedirectTo('https://adobe.com', '_blank');
160-
expect(window.open).toHaveBeenCalledWith('https://adobe.com', '_blank');
161144
});
162145
});
163146
});

0 commit comments

Comments
 (0)