<?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="AdminCreateFixedAmountDiscountTest">
        <annotations>
            <features value="SalesRule"/>
            <stories value="Create cart price rule"/>
            <title value="Admin should be able to create a cart price rule of type Fixed amount discount"/>
            <description value="Admin should be able to create a cart price rule of type Fixed amount discount"/>
            <severity value="AVERAGE"/>
            <testCaseId value="MC-62"/>
            <group value="SalesRule"/>
        </annotations>

        <before>
            <createData entity="_defaultCategory" stepKey="createPreReqCategory"/>
            <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
        </before>

        <after>
            <!-- Delete the cart price rule we made during the test -->
            <actionGroup ref="DeleteCartPriceRuleByName" stepKey="cleanUpRule">
                <argument name="ruleName" value="{{_defaultCoupon.code}}"/>
            </actionGroup>
            <deleteData createDataKey="createPreReqCategory" stepKey="deletePreReqCategory"/>
            <actionGroup ref="DeleteProductBySkuActionGroup" stepKey="deleteProduct">
                <argument name="sku" value="{{_defaultProduct.sku}}"/>
            </actionGroup>
            <actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="clearFilter"/>
            <actionGroup ref="AdminLogoutActionGroup" stepKey="adminLogout"/>
        </after>

        <!-- Create a cart price rule for $10 Fixed amount discount -->
        <actionGroup ref="AdminOpenCartPriceRulesPageActionGroup" stepKey="amOnCartPriceList"/>
        <click selector="{{AdminCartPriceRulesSection.addNewRuleButton}}" stepKey="clickAddNewRule"/>
        <fillField selector="{{AdminCartPriceRulesFormSection.ruleName}}" userInput="{{_defaultCoupon.code}}" stepKey="fillRuleName"/>
        <selectOption selector="{{AdminCartPriceRulesFormSection.websites}}" userInput="Main Website" stepKey="selectWebsites"/>
        <selectOption selector="{{AdminCartPriceRulesFormSection.customerGroups}}" userInput="NOT LOGGED IN" stepKey="selectCustomerGroup"/>
        <generateDate date="-1 day" format="m/d/Y" stepKey="yesterdayDate"/>
        <fillField selector="{{AdminCartPriceRulesFormSection.fromDate}}" userInput="{$yesterdayDate}" stepKey="fillFromDate"/>
        <click selector="{{AdminCartPriceRulesFormSection.actionsHeader}}" stepKey="clickToExpandActions"/>
        <selectOption selector="{{AdminCartPriceRulesFormSection.apply}}" userInput="Fixed amount discount" stepKey="selectActionType"/>
        <fillField selector="{{AdminCartPriceRulesFormSection.discountAmount}}" userInput="10" stepKey="fillDiscountAmount"/>
        <click selector="{{AdminCartPriceRulesFormSection.save}}" stepKey="clickSaveButton"/>
        <see selector="{{AdminCartPriceRulesSection.messages}}" userInput="You saved the rule." stepKey="seeSuccessMessage"/>

        <!-- Create a product to check the storefront -->
        <actionGroup ref="FillAdminSimpleProductFormActionGroup" stepKey="fillProductFieldsInAdmin">
            <argument name="category" value="$$createPreReqCategory$$"/>
            <argument name="simpleProduct" value="_defaultProduct"/>
        </actionGroup>

        <!-- Spot check the storefront -->
        <actionGroup ref="VerifyDiscountAmountActionGroup" stepKey="verifyStorefront">
            <argument name="productUrl" value="{{_defaultProduct.urlKey}}.html"/>
            <argument name="quantity" value="2"/>
            <argument name="expectedDiscount" value="-$20.00"/>
        </actionGroup>
    </test>
</tests>
