Skip to content

Add validation in catalog rule and shopping cart rule form #25172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,23 @@
<click selector="{{AdminNewCatalogPriceRuleConditions.activeConditionApplyButton}}" stepKey="clickApply"/>
<waitForElementNotVisible selector="{{AdminNewCatalogPriceRuleConditions.activeConditionApplyButton}}" stepKey="waitForApplyButtonInvisibility"/>
</actionGroup>

<actionGroup name="newCatalogPriceRuleWithInvalidData">
<annotations>
<description>Goes to the Catalog Price Rule grid. Clicks on Add. Fills in the provided Catalog Rule details with invalid data.</description>
</annotations>
<arguments>
<argument name="catalogRule" defaultValue="catalogRuleWithInvalid"/>
</arguments>

<!-- Go to the admin Catalog rule grid and add a new one -->
<amOnPage stepKey="goToPriceRulePage" url="{{CatalogRulePage.url}}"/>
<waitForPageLoad stepKey="waitForPriceRulePage"/>

<click stepKey="addNewRule" selector="{{AdminGridMainControls.add}}"/>
<fillField stepKey="fillPriority" selector="{{AdminNewCatalogPriceRule.priority}}" userInput="{{catalogRule.priority}}"/>
<scrollToTopOfPage stepKey="scrollToTop"/>
<click selector="{{AdminNewCatalogPriceRule.save}}" stepKey="clickSave"/>
<waitForPageLoad stepKey="waitForApplied"/>
</actionGroup>
</actionGroups>
15 changes: 15 additions & 0 deletions app/code/Magento/CatalogRule/Test/Mftf/Data/CatalogRuleData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,19 @@
<data key="defaultRuleLabelAllStoreViews">Free Shipping in conditions</data>
<data key="defaultStoreView">Free Shipping in conditions</data>
</entity>

<entity name="catalogRuleWithInvalid" type="catalogRule">
<data key="name" unique="suffix">CatalogPriceRule</data>
<data key="description">Catalog Price Rule Description</data>
<data key="is_active">1</data>
<array key="customer_group_ids">
<item>0</item>
</array>
<array key="website_ids">
<item>1</item>
</array>
<data key="simple_action">by_percent</data>
<data key="discount_amount">10</data>
<data key="priority">ten</data>
</entity>
</entities>
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
<element name="priority" type="input" selector="[name='sort_order']"/>
<element name="conditionsTab" type="block" selector="[data-index='block_promo_catalog_edit_tab_conditions']"/>
<element name="actionsTab" type="block" selector="[data-index='actions']"/>

<element name="fieldError" type="text" selector="//input[@name='{{fieldName}}']/following-sibling::label[@class='admin__field-error']" parameterized="true"/>
</section>

<section name="AdminNewCatalogPriceRuleActions">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,27 @@
<see selector="{{StorefrontCategoryProductSection.ProductInfoByNumber('1')}}" userInput="$$createProduct.name$$" stepKey="seeProduct2"/>
<see selector="{{StorefrontCategoryProductSection.ProductInfoByNumber('1')}}" userInput="$123.00" stepKey="seeDiscountedPrice2"/>
</test>

<test name="AdminCreateCatalogPriceRuleWithInvalidDataTest">
<annotations>
<features value="CatalogRule"/>
<stories value="Create Catalog Price Rule"/>
<title value="Admin can not create catalog price rule with the invalid data"/>
<description value="Admin can not create catalog price rule with the invalid data"/>
<severity value="MAJOR"/>
<group value="CatalogRule"/>
</annotations>
<before>
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
</before>
<after>
<amOnPage url="{{AdminLogoutPage.url}}" stepKey="amOnLogoutPage"/>
</after>

<actionGroup ref="newCatalogPriceRuleWithInvalidData" stepKey="createNewPriceRule">
<argument name="catalogRule" value="catalogRuleWithInvalid"/>
</actionGroup>

<see selector="{{AdminNewCatalogPriceRule.fieldError('sort_order')}}" userInput="Please enter a valid number in this field." stepKey="seeSortOrderError"/>
</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@
</item>
</argument>
<settings>
<validation>
<rule name="validate-digits" xsi:type="boolean">true</rule>
</validation>
<dataType>text</dataType>
<label translate="true">Priority</label>
<dataScope>sort_order</dataScope>
Expand Down
9 changes: 9 additions & 0 deletions app/code/Magento/SalesRule/Test/Mftf/Data/SalesRuleData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -464,4 +464,13 @@
<requiredEntity type="SalesRuleLabel">SalesRuleLabelDefault</requiredEntity>
<requiredEntity type="SalesRuleLabel">SalesRuleLabelStore1</requiredEntity>
</entity>

<entity name="TestSalesRuleWithInvalidData" type="SalesRule">
<data key="userPerCustomer">one</data>
<data key="userPerCoupon">one</data>
<data key="priority">one</data>
<data key="discountStep">one</data>
<data key="discountAmount">one</data>
<data key="maximumQtyDiscount">one</data>
</entity>
</entities>
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,6 @@
<element name="generateCouponsButton" type="button" selector="#coupons_generate_button" timeout="30"/>
<element name="generatedCouponByIndex" type="text" selector="#couponCodesGrid_table > tbody > tr:nth-child({{var}}) > td.col-code" parameterized="true"/>
<element name="couponGridUsedHeader" type="text" selector="#couponCodesGrid thead th[data-sort='used']"/>
<element name="fieldError" type="text" selector="//input[@name='{{fieldName}}']/following-sibling::label[@class='admin__field-error']" parameterized="true"/>
</section>
</sections>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminCreateInvalidRuleTest">
<annotations>
<features value="SalesRule"/>
<stories value="Create cart price rule with invalid data"/>
<title value="Admin can not create rule with invalid data"/>
<description value="Admin can not create rule with invalid data"/>
<severity value="MAJOR"/>
<group value="SalesRule"/>
</annotations>

<before>
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
</before>

<after>
<actionGroup ref="logout" stepKey="adminLogout"/>
</after>

<amOnPage url="{{AdminCartPriceRulesPage.url}}" stepKey="amOnCartPriceList"/>
<waitForPageLoad stepKey="waitForRulesPage"/>
<click selector="{{AdminCartPriceRulesSection.addNewRuleButton}}" stepKey="clickAddNewRule"/>

<click selector="{{AdminCartPriceRulesFormSection.actionsHeader}}" stepKey="clickToExpandActions"/>
<selectOption selector="{{AdminCartPriceRulesFormSection.apply}}" userInput="Buy X get Y free (discount amount is Y)" stepKey="selectActionType"/>
<fillField selector="{{AdminCartPriceRulesFormSection.discountAmount}}" userInput="{{TestSalesRuleWithInvalidData.discountAmount}}" stepKey="fillDiscountAmount"/>
<fillField selector="{{AdminCartPriceRulesFormSection.maximumQtyDiscount}}" userInput="{{TestSalesRuleWithInvalidData.maximumQtyDiscount}}" stepKey="fillDiscountQty"/>
<fillField selector="{{AdminCartPriceRulesFormSection.discountStep}}" userInput="{{TestSalesRuleWithInvalidData.discountStep}}" stepKey="fillDiscountStep"/>

<fillField selector="{{AdminCartPriceRulesFormSection.userPerCustomer}}" userInput="{{TestSalesRuleWithInvalidData.userPerCustomer}}" stepKey="fillUsePerCustomer"/>
<selectOption selector="{{AdminCartPriceRulesFormSection.coupon}}" userInput="Specific Coupon" stepKey="selectCouponType"/>
<fillField selector="{{AdminCartPriceRulesFormSection.userPerCoupon}}" userInput="{{TestSalesRuleWithInvalidData.userPerCoupon}}" stepKey="fillUsePerCoupon"/>
<fillField selector="{{AdminCartPriceRulesFormSection.priority}}" userInput="{{TestSalesRuleWithInvalidData.priority}}" stepKey="fillPriority"/>

<click selector="{{AdminCartPriceRulesFormSection.save}}" stepKey="clickSaveButton"/>

<see selector="{{AdminNewCatalogPriceRule.fieldError('uses_per_coupon')}}" userInput="Please enter a valid number in this field." stepKey="seePerCouponError"/>
<see selector="{{AdminNewCatalogPriceRule.fieldError('uses_per_customer')}}" userInput="Please enter a valid number in this field." stepKey="seePerCustomerError"/>
<see selector="{{AdminNewCatalogPriceRule.fieldError('sort_order')}}" userInput="Please enter a valid number in this field." stepKey="seePriorityError"/>
<see selector="{{AdminNewCatalogPriceRule.fieldError('discount_amount')}}" userInput="Please enter a valid number in this field." stepKey="seeDiscountAmountError"/>
<see selector="{{AdminNewCatalogPriceRule.fieldError('discount_qty')}}" userInput="Please enter a valid number in this field." stepKey="seeMaximumQtyError"/>
<see selector="{{AdminNewCatalogPriceRule.fieldError('discount_step')}}" userInput="Please enter a valid number in this field." stepKey="seeDiscountStepError"/>
</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@
</item>
</argument>
<settings>
<validation>
<rule name="validate-digits" xsi:type="boolean">true</rule>
</validation>
<dataType>text</dataType>
<label translate="true">Uses per Coupon</label>
<dataScope>uses_per_coupon</dataScope>
Expand All @@ -309,6 +312,9 @@
</item>
</argument>
<settings>
<validation>
<rule name="validate-digits" xsi:type="boolean">true</rule>
</validation>
<notice translate="true">
Usage limit enforced for logged in customers only.
</notice>
Expand Down Expand Up @@ -356,6 +362,9 @@
</item>
</argument>
<settings>
<validation>
<rule name="validate-digits" xsi:type="boolean">true</rule>
</validation>
<dataType>text</dataType>
<label translate="true">Priority</label>
<dataScope>sort_order</dataScope>
Expand Down Expand Up @@ -422,6 +431,8 @@
<settings>
<validation>
<rule name="required-entry" xsi:type="boolean">true</rule>
<rule name="validate-number" xsi:type="boolean">true</rule>
<rule name="validate-zero-or-greater" xsi:type="boolean">true</rule>
</validation>
<dataType>text</dataType>
<label translate="true">Discount Amount</label>
Expand All @@ -435,6 +446,10 @@
</item>
</argument>
<settings>
<validation>
<rule name="validate-number" xsi:type="boolean">true</rule>
<rule name="validate-zero-or-greater" xsi:type="boolean">true</rule>
</validation>
<dataType>text</dataType>
<label translate="true">Maximum Qty Discount is Applied To</label>
<dataScope>discount_qty</dataScope>
Expand All @@ -447,6 +462,10 @@
</item>
</argument>
<settings>
<validation>
<rule name="validate-number" xsi:type="boolean">true</rule>
<rule name="validate-zero-or-greater" xsi:type="boolean">true</rule>
</validation>
<dataType>text</dataType>
<label translate="true">Discount Qty Step (Buy X)</label>
<dataScope>discount_step</dataScope>
Expand Down