<?xml version="1.0" encoding="UTF-8"?>
<!--
 /**
  * Copyright © Magento, Inc. All rights reserved.
  * See COPYING.txt for license details.
  */
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
    <!-- action group to create a new catalog price rule giving a catalogRule entity -->
    <actionGroup name="NewCatalogPriceRuleByUIActionGroup">
        <annotations>
            <description>Consider using set of AG: AdminOpenNewCatalogPriceRuleFormPageActionGroup, AdminCatalogPriceRuleFillMainInfoActionGroup, AdminCatalogPriceRuleFillActionsActionGroup, AdminCatalogPriceRuleSaveAndApplyActionGroup
                Goes to the Catalog Price Rule grid. Clicks on Add. Fills in the provided Catalog Rule details.</description>
        </annotations>
        <arguments>
            <argument name="catalogRule" defaultValue="_defaultCatalogRule"/>
        </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}}"/>

        <!-- Fill the form according the attributes of the entity -->
        <fillField stepKey="fillName" selector="{{AdminNewCatalogPriceRule.ruleName}}" userInput="{{catalogRule.name}}"/>
        <fillField stepKey="fillDescription" selector="{{AdminNewCatalogPriceRule.description}}" userInput="{{catalogRule.description}}"/>
        <click stepKey="selectActive" selector="{{AdminCategoryBasicFieldSection.enableCategoryLabel}}"/>
        <selectOption stepKey="selectSite" selector="{{AdminNewCatalogPriceRule.websites}}" userInput="{{catalogRule.website_ids[0]}}"/>
        <click stepKey="clickFromCalender" selector="{{AdminNewCatalogPriceRule.fromDateButton}}"/>
        <click stepKey="clickFromToday" selector="{{AdminNewCatalogPriceRule.todayDate}}"/>
        <click stepKey="clickToCalender" selector="{{AdminNewCatalogPriceRule.toDateButton}}"/>
        <click stepKey="clickToToday" selector="{{AdminNewCatalogPriceRule.todayDate}}"/>
        <click stepKey="openActionDropdown" selector="{{AdminNewCatalogPriceRule.actionsTab}}"/>
        <fillField stepKey="fillDiscountValue" selector="{{AdminNewCatalogPriceRuleActions.discountAmount}}" userInput="{{catalogRule.discount_amount}}"/>
        <selectOption stepKey="discountType" selector="{{AdminNewCatalogPriceRuleActions.apply}}" userInput="{{catalogRule.simple_action}}"/>
        <selectOption stepKey="discardSubsequentRules" selector="{{AdminNewCatalogPriceRuleActions.disregardRules}}" userInput="Yes"/>

        <!-- Scroll to top and either save or save and apply after the action group -->
        <scrollToTopOfPage stepKey="scrollToTop"/>
        <waitForPageLoad stepKey="waitForApplied"/>
    </actionGroup>
</actionGroups>
