<?xml version="1.0" encoding="UTF-8" ?>
<!--
 /**
  * @copyright  Vertex. All rights reserved.  https://www.vertexinc.com/
  * @author     Mediotype                     https://www.mediotype.com/
  */
-->
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">

    <actionGroup name="VertexAddressValidationUpdatedToValidSystemMessage">
        <annotations>
            <description>See the update to valid message after we hit the button update to valid.</description>
        </annotations>
        <arguments>
            <argument type="string" name="postCode"/>
        </arguments>
        <see stepKey="postCode" selector="{{CheckoutShippingSection.addressInvalidFieldsContainer}}"
             userInput="{{postCode}}"/>

        <conditionalClick selector="{{CheckoutShippingSection.updateLinkToValidAddress}}"
                          dependentSelector="{{CheckoutShippingSection.addressMessageWarning}}"
                          visible="true"
                          stepKey="updateButtonToValidAddress"/>
        
        <waitForLoadingMaskToDisappear stepKey="waitForLoadingMask"/>
        <waitForElement selector="{{CheckoutShippingSection.next}}" time="30" stepKey="waitForNextButton"/>
        <click selector="{{CheckoutShippingSection.next}}" stepKey="clickNext"/>
        <waitForElement selector="{{CheckoutPaymentSection.paymentSectionTitle}}" time="30"
                        stepKey="waitForPaymentSectionLoaded"/>
        <seeInCurrentUrl url="{{CheckoutPage.url}}/#payment" stepKey="assertCheckoutPaymentUrl"/>
    </actionGroup>

    <actionGroup name="VertexAddressValidationUpdatedToValidMessageTextFromShippingAddress">
        <annotations>
            <description>See the valid details on the payment method after update.</description>
        </annotations>
        <arguments>
            <argument type="string" name="postCode"/>
        </arguments>
        <see stepKey="postCode" selector="{{CheckoutBillingSection.updatedAddressDetails}}" userInput="{{postCode}}"/>
    </actionGroup>

    <actionGroup name="VertexAddressValidationDefaultErrorOrInvalidSystemMessage">

        <waitForLoadingMaskToDisappear stepKey="waitForLoadingMask"/>
        <waitForElement selector="{{CheckoutShippingSection.next}}" time="30" stepKey="waitForNextButton"/>

        <see stepKey="warningMessage"
             selector="{{CheckoutShippingSection.addressMessageWarning}}"
             userInput="We did not find a valid address"/>

        <conditionalClick selector="{{CheckoutShippingSection.next}}"
                          dependentSelector="{{CheckoutShippingSection.updateLinkToValidAddress}}"
                          visible="false"
                          stepKey="clickNext"/>

        <waitForElement selector="{{CheckoutPaymentSection.paymentSectionTitle}}" time="30"
                        stepKey="waitForPaymentSectionLoaded"/>
        <seeInCurrentUrl url="{{CheckoutPage.url}}/#payment" stepKey="assertCheckoutPaymentUrl"/>
    </actionGroup>

    <actionGroup name="VertexAddressValidationValidSystemMessage">

        <waitForLoadingMaskToDisappear stepKey="waitForLoadingMask"/>
        <waitForElement selector="{{CheckoutShippingSection.next}}" time="30" stepKey="waitForNextButton"/>

        <see stepKey="successMessage"
             selector="{{CheckoutShippingSection.addressMessageWasValid}}"
             userInput="The address is valid"/>

        <conditionalClick selector="{{CheckoutShippingSection.next}}"
                          dependentSelector="{{CheckoutShippingSection.updateLinkToValidAddress}}"
                          visible="false"
                          stepKey="clickNext"/>

        <waitForElement selector="{{CheckoutPaymentSection.paymentSectionTitle}}" time="30"
                        stepKey="waitForPaymentSectionLoaded"/>
        <seeInCurrentUrl url="{{CheckoutPage.url}}/#payment" stepKey="assertCheckoutPaymentUrl"/>
    </actionGroup>

    <actionGroup name="FillNewShippingAddressModalActionGroupNoCompany"
                 extends="FillShippingAddressOneStreetActionGroup">
        <annotations>
            <description>EXTENDS: FillShippingAddressOneStreetActionGroup. Selects the provided State in the 'Shipping
                Address' section of the Storefront Checkout page.
            </description>
        </annotations>
        <arguments>
            <argument name="address"/>
        </arguments>
        <remove keyForRemoval="fillCompany"/>
        <selectOption stepKey="selectRegion" selector="{{CheckoutShippingSection.region}}" userInput="{{address.state}}"
                      after="fillCityName"/>
    </actionGroup>

    <actionGroup name="VertexUpdateRegisteredAddress">
        <waitForElement selector="{{CheckoutShippingSection.next}}" time="30" stepKey="waitForNextButton"/>
        <click selector="{{CheckoutShippingSection.next}}" stepKey="clickNext"/>

        <see stepKey="warningMessage"
             selector="{{CheckoutShippingSection.addressMessageWarning}}"
             userInput="The address is not valid"/>

        <conditionalClick selector="{{CheckoutShippingSection.updateLinkToValidAddress}}"
                          dependentSelector="{{CheckoutShippingSection.addressMessageWarning}}"
                          visible="true"
                          stepKey="updateButtonToValidAddress"/>

        <see stepKey="updateMessage"
             selector="{{CheckoutShippingSection.addressMessageWasValid}}"
             userInput="The address was updated"/>
    </actionGroup>

    <actionGroup name="VertexUpdatedRegisteredShippingAddress">
        <arguments>
            <argument type="string" name="postCode"/>
            <argument type="string" name="city"/>
        </arguments>
        <see stepKey="postCode" selector="{{CheckoutShippingSection.selectedShippingAddress}}"
             userInput="{{postCode}}"/>
        <see stepKey="city" selector="{{CheckoutShippingSection.selectedShippingAddress}}" userInput="{{city}}"/>

        <waitForLoadingMaskToDisappear stepKey="waitForLoadingMask"/>
        <waitForElement selector="{{CheckoutShippingSection.next}}" time="30" stepKey="waitForNextButton"/>
        <click selector="{{CheckoutShippingSection.next}}" stepKey="clickNext"/>
        <waitForElement selector="{{CheckoutPaymentSection.paymentSectionTitle}}" time="30"
                        stepKey="waitForPaymentSectionLoaded"/>
        <seeInCurrentUrl url="{{CheckoutPage.url}}/#payment" stepKey="assertCheckoutPaymentUrl"/>
    </actionGroup>

</actionGroups>
