Skip to content

Commit 694b619

Browse files
ENGCOM-6131: ["Save in New Attribute Set"] : Form should be validated before prompt the popup #25132
2 parents bf86b77 + 6be9382 commit 694b619

6 files changed

+167
-28
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
12+
<actionGroup name="AdminAssertProductEditPageCreateAttributeSaveInAttributeSetPopUpShownActionGroup">
13+
<annotations>
14+
<description>Asserts that after click on "Save In New Attribute Set" poup shown .</description>
15+
</annotations>
16+
<see userInput="Enter Name for New Attribute Set" stepKey="seeContent"/>
17+
</actionGroup>
18+
</actionGroups>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
12+
<actionGroup name="AdminClickAddAttributeOnProductEditPageActionGroup">
13+
<annotations>
14+
<description>Clicks on 'Add Attribute'. Admin Product creation/edit page .</description>
15+
</annotations>
16+
<click selector="{{AdminProductFormSection.addAttributeBtn}}" stepKey="clickAddAttributeBtn"/>
17+
<waitForPageLoad stepKey="waitForSidePanel"/>
18+
<see userInput="Select Attribute" stepKey="checkNewAttributePopUpAppeared"/>
19+
</actionGroup>
20+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
12+
<actionGroup name="AdminClickCreateNewAttributeFromProductEditPageActionGroup">
13+
<annotations>
14+
<description>Clicks on 'Create New Attribute'. Admin Product creation/edit page .</description>
15+
</annotations>
16+
<click selector="{{AdminProductFormAttributeSection.createNewAttribute}}" stepKey="clickCreateNewAttribute"/>
17+
<waitForPageLoad stepKey="waitForSidePanel"/>
18+
</actionGroup>
19+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
12+
<actionGroup name="AdminFillAttributeDataProductFormNewAttributeActionGroup">
13+
<arguments>
14+
<argument name="attributeName" type="string" defaultValue="TestAttributeName"/>
15+
<argument name="attributeType" type="string" defaultValue="Text Field"/>
16+
</arguments>
17+
<annotations>
18+
<description>Fill attribute data on 'Create New Attribute' page Admin Product creation/edit page .</description>
19+
</annotations>
20+
<fillField selector="{{AdminProductFormNewAttributeSection.attributeLabel}}" userInput="{{attributeName}}"
21+
stepKey="fillAttributeLabel"/>
22+
<selectOption selector="{{AdminProductFormNewAttributeSection.attributeType}}" userInput="{{attributeType}}"
23+
stepKey="selectAttributeType"/>
24+
</actionGroup>
25+
</actionGroups>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminCreateNewAttributeFromProductPageTest">
12+
<annotations>
13+
<features value="Catalog"/>
14+
<stories value="We should validate the form when the user click Save in New Attribute Set"/>
15+
<title value="We should validate the form when the user click Save in New Attribute Set"/>
16+
<description
17+
value="Admin should be able to create product attribute and validate the form when the user click Save in New Attribute Set"/>
18+
<testCaseId value="https://github.com/magento/magento2/pull/25132"/>
19+
<severity value="CRITICAL"/>
20+
<group value="Catalog"/>
21+
</annotations>
22+
<before>
23+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
24+
</before>
25+
<after>
26+
<actionGroup ref="logout" stepKey="logout"/>
27+
</after>
28+
29+
<actionGroup ref="GoToProductCatalogPage" stepKey="goToProductCatalogPage"/>
30+
<actionGroup ref="goToCreateProductPage" stepKey="goToCreateProduct">
31+
<argument name="product" value="SimpleProduct"/>
32+
</actionGroup>
33+
<actionGroup ref="AdminClickAddAttributeOnProductEditPageActionGroup" stepKey="clickAddAttribute"/>
34+
<actionGroup ref="AdminClickCreateNewAttributeFromProductEditPageActionGroup" stepKey="clickCreateNewAttribute1" />
35+
<actionGroup ref="AdminFillAttributeDataProductFormNewAttributeActionGroup" stepKey="fillAttributeData" />
36+
37+
<click selector="{{AdminProductFormNewAttributeSection.saveInNewSet}}" stepKey="saveAttributeInSet"/>
38+
<actionGroup ref="AdminAssertProductEditPageCreateAttributeSaveInAttributeSetPopUpShownActionGroup" stepKey="assertPopUp"/>
39+
<click selector="{{ModalConfirmationSection.CancelButton}}" stepKey="cancelButton"/>
40+
41+
<actionGroup ref="AdminFillAttributeDataProductFormNewAttributeActionGroup" stepKey="emptyAttributeData" >
42+
<argument name="attributeName" value=" "/>
43+
<argument name="attributeType" value=" "/>
44+
</actionGroup>
45+
46+
<click selector="{{AdminProductFormNewAttributeSection.saveInNewSet}}" stepKey="clickSaveInSet"/>
47+
<see userInput="This is a required field." stepKey="seeThisIsRequiredField"/>
48+
<dontSee userInput="Enter Name for New Attribute Set" stepKey="dontSeePopUp" />
49+
50+
</test>
51+
</tests>

app/code/Magento/Catalog/view/adminhtml/web/js/components/new-attribute-form.js

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,41 +42,47 @@ define([
4242

4343
var self = this;
4444

45-
prompt({
46-
content: this.newSetPromptMessage,
47-
actions: {
45+
this.validate();
4846

49-
/**
50-
* @param {String} val
51-
* @this {actions}
52-
*/
53-
confirm: function (val) {
54-
var rules = ['required-entry', 'validate-no-html-tags'],
55-
editForm = self,
56-
newAttributeSetName = val,
57-
i,
58-
params = {};
47+
if (!this.additionalInvalid && !this.source.get('params.invalid')) {
48+
prompt({
49+
content: this.newSetPromptMessage,
50+
actions: {
5951

60-
if (!newAttributeSetName) {
61-
return;
62-
}
63-
64-
for (i = 0; i < rules.length; i++) {
65-
if (!$.validator.methods[rules[i]](newAttributeSetName)) {
66-
alert({
67-
content: $.validator.messages[rules[i]]
68-
});
52+
/**
53+
* @param {String} val
54+
* @this {actions}
55+
*/
56+
confirm: function (val) {
57+
var rules = ['required-entry', 'validate-no-html-tags'],
58+
editForm = self,
59+
newAttributeSetName = val,
60+
i,
61+
params = {};
6962

63+
if (!newAttributeSetName) {
7064
return;
7165
}
72-
}
7366

74-
params['new_attribute_set_name'] = newAttributeSetName;
75-
editForm.setAdditionalData(params);
76-
editForm.save();
67+
for (i = 0; i < rules.length; i++) {
68+
if (!$.validator.methods[rules[i]](newAttributeSetName)) {
69+
alert({
70+
content: $.validator.messages[rules[i]]
71+
});
72+
73+
return;
74+
}
75+
}
76+
77+
params['new_attribute_set_name'] = newAttributeSetName;
78+
editForm.setAdditionalData(params);
79+
editForm.save();
80+
}
7781
}
78-
}
79-
});
82+
});
83+
} else {
84+
this.focusInvalid();
85+
}
8086
}
8187
});
8288
});

0 commit comments

Comments
 (0)