<?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="StoreFrontAddZeroPriceProductToCardWithFixedAmountPriceRule">
        <annotations>
            <features value="SalesRule"/>
            <stories value="Zero price product added to cart while cart price rule is Fixed amount discount for whole cart"/>
            <title value="Add zero price product to cart when fixed amount discount for the whole cart rule is active"/>
            <description value="Customers should be able to add a zero price product from the storefront when the cart price rule of type Fixed amount discount for the whole cart is configured"/>
            <severity value="MAJOR"/>
            <testCaseId value="AC-1618"/>
            <useCaseId value="ACP2E-285"/>
            <group value="SalesRule"/>
        </annotations>

        <before>
            <!-- Create Simple Product and Category -->
            <createData entity="_defaultCategory" stepKey="createPreReqCategory"/>
            <createData entity="SimpleProduct_zero" stepKey="createSimpleProduct">
                <requiredEntity createDataKey="createPreReqCategory"/>
            </createData>
            <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>

            <!-- Create cart price rule -->
            <actionGroup ref="AdminCreateCartPriceRuleActionGroup" stepKey="createCartPriceRule">
                <argument name="ruleName" value="PriceRuleWithCondition"/>
            </actionGroup>
        </before>

        <after>
            <!-- Delete the cart price rule we made during the test -->
            <actionGroup ref="DeleteCartPriceRuleByName" stepKey="cleanUpRule">
                <argument name="ruleName" value="{{PriceRuleWithCondition.name}}"/>
            </actionGroup>
            <deleteData createDataKey="createSimpleProduct" stepKey="deleteProduct"/>
            <deleteData createDataKey="createPreReqCategory" stepKey="deleteCategory"/>
            <actionGroup ref="AdminLogoutActionGroup" stepKey="adminLogout"/>
        </after>

        <!-- Go to the storefront and add the product to the cart -->
        <actionGroup ref="AddSimpleProductToCartActionGroup" stepKey="gotoAndAddProductToCart">
            <argument name="product" value="$$createSimpleProduct$$"/>
        </actionGroup>

        <!-- Go to the cart page and verify we see the product -->
        <actionGroup ref="StorefrontCartPageOpenActionGroup" stepKey="gotoCart"/>
        <actionGroup ref="AssertStorefrontCheckoutCartItemsActionGroup" stepKey="assertProductItemInCheckOutCart">
            <argument name="productName" value="$$createSimpleProduct.name$$"/>
            <argument name="productPrice" value="$$createSimpleProduct.price$$"/>
            <argument name="subtotal" value="$$createSimpleProduct.price$$" />
            <argument name="qty" value="1"/>
        </actionGroup> 
    </test>
</tests>
