<?xml version="1.0" encoding="UTF-8"?>
<!--
 /**
  * Copyright © Magento, Inc. All rights reserved.
  * See COPYING.txt for license details.
  *
  * This file is part of the Klarna KP module
  *
  * (c) Klarna Bank AB (publ)
  *
  * For the full copyright and license information, please view the NOTICE
  * and LICENSE files that were distributed with this source code.
  */
-->
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
    <actionGroup name="KlarnaCreateTaxRuleActionGroup">
        <arguments>
            <argument name="taxRateCode" type="string"/>
            <argument name="taxRuleCode" type="string"/>
        </arguments>

        <!-- Going to the "Create a tax rule" page -->
        <amOnPage url="{{AdminTaxRuleGridPage.url}}" stepKey="goToTaxRuleOverviewPage"/>
        <waitForPageLoad stepKey="waitForTaxRuleOverviewPage"/>
        <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAddNewTaxRuleButton"/>
        <waitForPageLoad stepKey="waitUntilTaxRuleCreationPageLoaded"/>

        <!-- Doing the default settings -->
        <fillField selector="{{AdminTaxRuleFormSection.code}}" userInput="{{taxRuleCode}}" stepKey="fillTaxRuleCode"/>
        <fillField selector="{{AdminTaxRuleFormSection.taxRateSearch}}" userInput="{{taxRateCode}}" stepKey="fillTaxRateSearch"/>
        <wait stepKey="waitForSearch" time="5"/>
        <click selector="{{AdminTaxRuleFormSection.taxRateOption(taxRateCode)}}" stepKey="clickSelectNeededItem"/>

        <!-- Open the additional settings section -->
        <click selector="{{AdminTaxRuleFormSection.additionalSettings}}" stepKey="clickAdditionalSettings"/>
        <scrollTo selector="{{AdminTaxRuleFormSection.additionalSettings}}" x="0" y="-80" stepKey="scrollToAdvancedSettings"/>

        <!-- Updating the used tax class -->
        <wait stepKey="waitForAdditionalSettings" time="5"/>
        <click selector="{{AdminTaxRuleFormSection.productTaxClassOption(taxableGoodsTaxClass.class_name)}}" stepKey="disableDefaultTaxClass"/>
        <click selector="{{AdminTaxRuleFormSection.productTaxClassOption(taxRuleCode)}}" stepKey="selectTargetTaxClass"/>

        <!-- Updating the values for the remaining fields of the additional settings section -->
        <fillField selector="{{AdminTaxRuleFormSection.priority}}" userInput="{{taxRuleWithCustomPriorityPosition.priority}}" stepKey="fillPriority"/>
        <fillField selector="{{AdminTaxRuleFormSection.sortOrder}}" userInput="{{taxRuleWithCustomPriorityPosition.position}}" stepKey="fillSortOrder"/>

        <!-- Saving the tax rule -->
        <click selector="{{AdminTaxRuleFormSection.save}}" stepKey="clickSaveTaxRule"/>
        <waitForPageLoad stepKey="waitForTaxRuleSaved"/>
        <see selector="{{AdminTaxRuleGridSection.successMessage}}" userInput="You saved the tax rule." stepKey="seeAssertTaxRuleSuccessMessage"/>
    </actionGroup>
</actionGroups>
