<?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">
    <actionGroup name="NavigateToNewOrderPageExistingCustomerActionGroup" deprecated="This Action Group is deprecated. Please use AdminNavigateToNewOrderPageExistingCustomerActionGroup + AdminSelectStoreDuringOrderCreationActionGroup.">
        <annotations>
            <description>Goes to the Admin Orders grid page. Clicks on 'Create New Order'. Filters the grid for the provided Customer. Clicks on the Customer. Selects the provided Store View, if present. Validates that the Page Title is present and correct.</description>
        </annotations>
        <arguments>
            <argument name="customer"/>
            <argument name="storeView" defaultValue="_defaultStore"/>
        </arguments>

        <amOnPage url="{{AdminOrdersPage.url}}" stepKey="navigateToOrderIndexPage"/>
        <waitForPageLoad stepKey="waitForIndexPageLoad"/>
        <see selector="{{AdminHeaderSection.pageTitle}}" userInput="Orders" stepKey="seeIndexPageTitle"/>
        <click selector="{{AdminOrdersGridSection.createNewOrder}}" stepKey="clickCreateNewOrder"/>
        <waitForPageLoad stepKey="waitForCustomerGridLoad"/>

        <!--Clear grid filters-->
        <conditionalClick selector="{{AdminOrderCustomersGridSection.resetButton}}" dependentSelector="{{AdminOrderCustomersGridSection.resetButton}}" visible="true" stepKey="clearExistingCustomerFilters"/>
        <fillField userInput="{{customer.email}}" selector="{{AdminOrderCustomersGridSection.emailInput}}" stepKey="filterEmail"/>
        <click selector="{{AdminOrderCustomersGridSection.apply}}" stepKey="applyFilter"/>
        <waitForPageLoad stepKey="waitForFilteredCustomerGridLoad"/>
        <click selector="{{AdminOrderCustomersGridSection.firstRow}}" stepKey="clickOnCustomer"/>
        <waitForPageLoad stepKey="waitForCreateOrderPageLoad"/>

        <!-- Select store view if appears -->
        <!--
            Adding wait for 5 seconds to make sure AdminOrderStoreScopeTreeSection.storeForOrder(storeView.name)
            renders properly. Unfortunately can not add waitForElement because in some scenarios where this action group
            is used the step with Store selection is absent. That is why click is conditional.
        -->
        <wait time="5" stepKey="wait" />
        <conditionalClick selector="{{AdminOrderStoreScopeTreeSection.storeOption(storeView.name)}}" dependentSelector="{{AdminOrderStoreScopeTreeSection.storeOption(storeView.name)}}" visible="true" stepKey="selectStoreViewIfAppears"/>
        <waitForPageLoad stepKey="waitForCreateOrderPageLoadAfterStoreSelect"/>
        <see selector="{{AdminHeaderSection.pageTitle}}" userInput="Create New Order" stepKey="seeNewOrderPageTitle"/>
    </actionGroup>
</actionGroups>
