<?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="AdminCreateStoreViewActionGroup">
        <annotations>
            <description>Goes to the Admin Store View creation page. Fills in the provided Store View and Store details. Clicks on Save. Validates that the Success Message is present and correct.</description>
        </annotations>
        <arguments>
            <argument name="StoreGroup" defaultValue="_defaultStoreGroup"/>
            <argument name="customStore" defaultValue="customStore"/>
        </arguments>

        <amOnPage url="{{AdminSystemStoreViewPage.url}}" stepKey="navigateToNewStoreView"/>
        <waitForPageLoad stepKey="waitForPageLoad1"/>
        <comment userInput="Creating Store View" stepKey="storeViewCreationComment"/>

        <!--Create Store View-->
        <selectOption selector="{{AdminNewStoreSection.storeGrpDropdown}}" userInput="{{StoreGroup.name}}" stepKey="selectStore"/>
        <fillField selector="{{AdminNewStoreSection.storeNameTextField}}" userInput="{{customStore.name}}" stepKey="enterStoreViewName"/>
        <fillField selector="{{AdminNewStoreSection.storeCodeTextField}}" userInput="{{customStore.code}}" stepKey="enterStoreViewCode"/>
        <selectOption selector="{{AdminNewStoreSection.statusDropdown}}" userInput="Enabled" stepKey="setStatus"/>
        <click selector="{{AdminNewStoreViewActionsSection.saveButton}}" stepKey="clickSaveStoreView"/>
        <waitForElementVisible selector="{{AdminConfirmationModalSection.ok}}" stepKey="waitForModal"/>
        <see selector="{{AdminConfirmationModalSection.title}}" userInput="Warning message" stepKey="seeWarningAboutTakingALongTimeToComplete"/>
        <click selector="{{AdminConfirmationModalSection.ok}}" stepKey="confirmModal"/>
        <waitForElementVisible selector="{{AdminMessagesSection.success}}" stepKey="waitForPageReload"/>
        <see selector="{{AdminMessagesSection.success}}" userInput="You saved the store view." stepKey="seeSavedMessage"/>
    </actionGroup>

    <actionGroup name="AdminCreateStoreViewWithoutCheckActionGroup" extends="AdminCreateStoreViewActionGroup">
        <annotations>
            <description>EXTENDS: AdminCreateStoreViewActionGroup. Removes 'waitForPageReload' and 'seeSavedMessage'.</description>
        </annotations>

        <remove keyForRemoval="waitForPageReload"/>
        <remove keyForRemoval="seeSavedMessage"/>
    </actionGroup>

    <!--Save the Store view-->
    <actionGroup name="AdminCreateStoreViewActionSaveGroup">
        <annotations>
            <description>Validates that the Success Message is present and correct.</description>
        </annotations>
        
        <waitForLoadingMaskToDisappear stepKey="waitForGridLoad"/>
        <waitForElementVisible selector="{{AdminStoresGridSection.websiteFilterTextField}}" stepKey="waitForStoreGridToReload2"/>
        <see userInput="You saved the store view." stepKey="seeSavedMessage"/>
    </actionGroup>

    <actionGroup name="navigateToAdminContentManagementPage">
        <annotations>
            <description>Goes to the 'Configuration' page for 'Content Management'.</description>
        </annotations>

        <amOnPage url="{{AdminContentManagementPage.url}}" stepKey="navigateToConfigurationPage"/>
        <waitForPageLoad stepKey="waitForPageLoad1"/>
    </actionGroup>

    <actionGroup name="saveStoreConfiguration">
        <annotations>
            <description>Clicks on the Save button.</description>
        </annotations>

        <comment userInput="saveStoreConfiguration" stepKey="comment"/>
        <waitForElementVisible selector="{{StoreConfigSection.Save}}" stepKey="waitForSaveButton"/>
        <click selector="{{StoreConfigSection.Save}}" stepKey="clickSaveButton"/>
        <waitForPageLoad stepKey="waitForPageLoad"/>
    </actionGroup>

    <actionGroup name="saveStoreConfigurationAndValidateFieldError">
        <annotations>
            <description>Clicks on Save. Validates that the fields are required.</description>
        </annotations>
        <arguments>
            <argument name="inputFieldError" type="string"/>
            <argument name="errorMessageSelector" type="string"/>
            <argument name="errorMessage" type="string"/>
        </arguments>

        <comment userInput="saveStoreConfigurationAndValidateFieldError" stepKey="comment"/>
        <waitForElementVisible selector="{{StoreConfigSection.Save}}" stepKey="waitForSaveButton"/>
        <click selector="{{StoreConfigSection.Save}}" stepKey="clickSaveButton"/>
        <waitForElement selector="{{inputFieldError}}" stepKey="waitForErrorField"/>
        <waitForElementVisible selector="{{errorMessageSelector}}" stepKey="waitForErrorMessage"/>
        <see selector="{{errorMessageSelector}}" userInput="{{errorMessage}}" stepKey="seeErrorMessage"/>
    </actionGroup>
</actionGroups>
