Skip to content

Commit 477fcf8

Browse files
authored
Merge pull request #208 from magento-l3/PR-02142023
Pr 02142023
2 parents d52a3e8 + 7f2b374 commit 477fcf8

File tree

3 files changed

+199
-1
lines changed

3 files changed

+199
-1
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="StorefrontProductMultipleWidgetsAddToCartSameProductOnce">
11+
<annotations>
12+
<features value="PageBuilder"/>
13+
<stories value="Add to cart from product widget"/>
14+
<title value="Adding to cart from product widget when two widgets on the same page, should add to cart once"/>
15+
<description value="The product should be added to the cart only once from the product widget when the CMS page contains two rows, the first row contains the regular product widget, and the second row contains the product carousel widget and both of them are displaying the same product"/>
16+
<severity value="MAJOR"/>
17+
<useCaseId value="ACP2E-1564"/>
18+
<testCaseId value="AC-7939"/>
19+
<group value="pagebuilder"/>
20+
<group value="pagebuilder-cms-page"/>
21+
<group value="pagebuilder-products"/>
22+
<group value="pagebuilder-productsCarousel"/>
23+
</annotations>
24+
<before>
25+
<createData entity="_defaultCategory" stepKey="createCategory"/>
26+
<createData entity="_defaultProduct" stepKey="createProduct">
27+
<requiredEntity createDataKey="createCategory"/>
28+
</createData>
29+
<createData entity="_emptyCmsPage" stepKey="createCMSPage"/>
30+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
31+
</before>
32+
<after>
33+
<deleteData createDataKey="createCategory" stepKey="deleteCreatedCategory"/>
34+
<deleteData createDataKey="createProduct" stepKey="deleteCreatedProduct"/>
35+
<deleteData createDataKey="createCMSPage" stepKey="deleteCMSPage"/>
36+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
37+
</after>
38+
39+
<!-- Open the newly created CMS Page for editing and expand the Page Builder editor -->
40+
<actionGroup ref="NavigateToCreatedCMSPageActionGroup" stepKey="navigateToCreatedCMSPage">
41+
<argument name="CMSPage" value="$$createCMSPage$$"/>
42+
</actionGroup>
43+
<actionGroup ref="AdminOpenPageBuilderFromContentPreviewOverlayActionGroup" stepKey="openPageBuilderFullScreen"/>
44+
45+
<!-- Add the product widget with Page Builder, set it to carousel mode and assign the product category -->
46+
<actionGroup ref="dragContentTypeToStage" stepKey="dragRowToRootContainer">
47+
<argument name="contentType" value="PageBuilderRowContentType"/>
48+
<argument name="containerTargetType" value="PageBuilderRootContainerContentType"/>
49+
</actionGroup>
50+
<actionGroup ref="expandPageBuilderPanelMenuSection" stepKey="expandMenuSectionAddContent">
51+
<argument name="contentType" value="PageBuilderProductsContentType"/>
52+
</actionGroup>
53+
<actionGroup ref="dragContentTypeToStage" stepKey="dragOntoStage">
54+
<argument name="contentType" value="PageBuilderProductsContentType"/>
55+
</actionGroup>
56+
<actionGroup ref="openPageBuilderEditPanel" stepKey="openEditAfterDrop">
57+
<argument name="contentType" value="PageBuilderProductsContentType"/>
58+
</actionGroup>
59+
<actionGroup ref="chooseVisualSelectOption" stepKey="selectAppearance">
60+
<argument name="property" value="PageBuilderProductsProductCarouselAppearance"/>
61+
</actionGroup>
62+
<actionGroup ref="chooseVisualSelectOption" stepKey="chooseSelectProductsBy">
63+
<argument name="property" value="PageBuilderProductsSelectProductsByCategory"/>
64+
</actionGroup>
65+
<actionGroup ref="selectCategoryFromCategoryDropDown" stepKey="selectCategory">
66+
<argument name="category" value="$$createCategory.name$$"/>
67+
</actionGroup>
68+
<actionGroup ref="saveEditPanelSettings" stepKey="saveEditPanelSettings"/>
69+
70+
<!-- Add the regular product widget with Page Builder and assign the product category -->
71+
<actionGroup ref="dragContentTypeToStage" stepKey="dragSecondRowToRootContainer">
72+
<argument name="contentType" value="PageBuilderRowContentType"/>
73+
<argument name="containerTargetType" value="PageBuilderRootContainerContentType"/>
74+
</actionGroup>
75+
<actionGroup ref="expandPageBuilderPanelMenuSection" stepKey="expandMenuSectionAddContentForSecondRow">
76+
<argument name="contentType" value="PageBuilderProductsContentType"/>
77+
</actionGroup>
78+
<actionGroup ref="dragContentTypeToStage" stepKey="dragOntoStageForSecondRow">
79+
<argument name="contentType" value="PageBuilderProductsContentType"/>
80+
</actionGroup>
81+
<actionGroup ref="openPageBuilderEditPanel" stepKey="openEditAfterDropForSecondRow">
82+
<argument name="contentType" value="PageBuilderProductsContentType"/>
83+
</actionGroup>
84+
<actionGroup ref="chooseVisualSelectOption" stepKey="chooseSelectProductsByForSecondRow">
85+
<argument name="property" value="PageBuilderProductsSelectProductsByCategory"/>
86+
</actionGroup>
87+
<actionGroup ref="selectCategoryFromCategoryDropDown" stepKey="selectCategoryForSecondRow">
88+
<argument name="category" value="$$createCategory.name$$"/>
89+
</actionGroup>
90+
91+
<!-- Save the Page Builder stage -->
92+
<actionGroup ref="saveEditPanelSettings" stepKey="saveEditPanelSettingsForSecondRow"/>
93+
<actionGroup ref="exitPageBuilderFullScreen" stepKey="exitPageBuilderFullScreenBeforeSave"/>
94+
95+
<!-- Save the CMS Page -->
96+
<actionGroup ref="SaveCmsPageActionGroup" stepKey="saveCMSPage"/>
97+
98+
<!-- Validate Add to Cart on the storefront -->
99+
<actionGroup ref="NavigateToStorefrontForCreatedPageActionGroup" stepKey="navigateToCMSPageStorefront">
100+
<argument name="page" value="$$createCMSPage.identifier$$"/>
101+
</actionGroup>
102+
<actionGroup ref="StorefrontClickProductAddToCartValidateAsyncActionGroup" stepKey="clickProductAddToCartInProductsCMSPageStorefront">
103+
<argument name="product" value="$$createProduct.name$$"/>
104+
</actionGroup>
105+
106+
<!-- Validate the product was added to the cart just once -->
107+
<see selector="{{StorefrontMinicartSection.quantity}}" userInput="1" stepKey="seeCartQuantityToBeJustOne"/>
108+
<actionGroup ref="StorefrontAssertProductQtyInMinicartActionGroup" stepKey="assertProductQtyInMinicartToBeJustOne">
109+
<argument name="product" value="$$createProduct$$"/>
110+
<argument name="qty" value="1"/>
111+
</actionGroup>
112+
</test>
113+
</tests>

app/code/Magento/PageBuilder/view/adminhtml/web/js/form/element/wysiwyg.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,26 @@ define([
131131
editableValue = this.pageBuilder.isFullScreen();
132132

133133
editable.attr('contenteditable', editableValue);
134-
$(pageBuilderSelector + focusableSelector).attr('tabindex', tabIndexValue);
134+
if (this.pageBuilder.isFullScreen()) {
135+
$(pageBuilderSelector + focusableSelector)
136+
.each(function () {
137+
if ($(this).data('original-tabindex')) {
138+
$(this).attr('tabindex', $(this).data('original-tabindex'));
139+
} else if ($(this).data('original-tabindex') === '') {
140+
$(this).removeAttr('tabindex');
141+
}
142+
$(this).removeData('original-tabindex');
143+
});
144+
} else {
145+
$(pageBuilderSelector + focusableSelector).each(function () {
146+
if ($(this).attr('tabindex')) {
147+
$(this).data('original-tabindex', $(this).attr('tabindex'));
148+
} else {
149+
$(this).data('original-tabindex', '');
150+
}
151+
$(this).attr('tabindex', '-1');
152+
});
153+
}
135154
$(mediaSelector).attr('tabindex', tabIndexValue);
136155
},
137156

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
*
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/* eslint-disable max-nested-callbacks */
8+
define([
9+
'jquery',
10+
'Magento_PageBuilder/js/form/element/wysiwyg'
11+
], function ($, UiWysiwyg) {
12+
'use strict';
13+
14+
var wysiwyg;
15+
16+
function createWysiwygMock() {
17+
var mock,
18+
MockWysiwyg = function () {};
19+
20+
MockWysiwyg.prototype = Object.create(UiWysiwyg.prototype);
21+
MockWysiwyg.prototype.constructor = MockWysiwyg;
22+
mock = new MockWysiwyg();
23+
$.extend(mock, UiWysiwyg.defaults);
24+
return mock;
25+
}
26+
27+
beforeEach(function () {
28+
wysiwyg = createWysiwygMock();
29+
wysiwyg.pageBuilder = {id: 'pb-wysiwyg-test'};
30+
$(document.body).append(
31+
$('<div><div contenteditable="true"><a href="/login"></a><span tabindex="0"></span></div></div>')
32+
.attr('id', wysiwyg.pageBuilder.id)
33+
);
34+
});
35+
36+
afterEach(function () {
37+
$('#' + wysiwyg.pageBuilder.id).remove();
38+
});
39+
40+
describe('Magento_PageBuilder/js/form/element/wysiwyg', function () {
41+
describe('toggleFocusableElements', function () {
42+
it('Should restore tabindex and contenteditable in fullscreen mode', function () {
43+
var $div = $('#' + wysiwyg.pageBuilder.id);
44+
45+
wysiwyg.pageBuilder.isFullScreen = jasmine.createSpy().and.returnValue(false);
46+
wysiwyg.toggleFocusableElements();
47+
expect($div.find('a').attr('tabindex')).toBe('-1');
48+
expect($div.find('a').data('original-tabindex')).toBe('');
49+
expect($div.find('span').attr('tabindex')).toBe('-1');
50+
expect($div.find('span').data('original-tabindex')).toBe('0');
51+
expect($div.find('[contenteditable]').attr('contenteditable')).toBe('false');
52+
53+
// check full screen mode
54+
wysiwyg.pageBuilder.isFullScreen = jasmine.createSpy().and.returnValue(true);
55+
wysiwyg.toggleFocusableElements();
56+
// check that taindex is removed from "a"
57+
expect($div.find('a').attr('tabindex')).toBe(undefined);
58+
expect($div.find('a').data('original-tabindex')).toBe(undefined);
59+
// check that taindex is restored for "span"
60+
expect($div.find('span').attr('tabindex')).toBe('0');
61+
expect($div.find('span').data('original-tabindex')).toBe(undefined);
62+
expect($div.find('[contenteditable]').attr('contenteditable')).toBe('true');
63+
});
64+
});
65+
});
66+
});

0 commit comments

Comments
 (0)