<?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="navigateToCreatedCMSPage">
        <arguments>
            <argument name="CMSPage" defaultValue=""/>
        </arguments>
        <amOnPage url="{{CmsPagesPage.url}}" stepKey="navigateToCMSPagesGrid"/>
        <waitForPageLoad stepKey="waitForPageLoad1"/>
        <conditionalClick selector="{{CmsPagesPageActionsSection.clearAllButton}}" dependentSelector="{{CmsPagesPageActionsSection.activeFilters}}" stepKey="clickToResetFilter" visible="true"/>
        <waitForPageLoad stepKey="waitForPageLoad2"/>
        <conditionalClick selector="//div[contains(@data-role, 'grid-wrapper')]/table/thead/tr/th/span[contains(text(), 'ID')]" dependentSelector="//span[contains(text(), 'ID')]/parent::th[not(contains(@class, '_descend'))]/parent::tr/parent::thead/parent::table/parent::div[contains(@data-role, 'grid-wrapper')]" stepKey="clickToAttemptSortByIdDescending" visible="true"/>
        <waitForLoadingMaskToDisappear stepKey="waitForFirstIdSortDescendingToFinish" />
        <!-- Conditional Click again in case it goes from default state to ascending on first click -->
        <conditionalClick selector="//div[contains(@data-role, 'grid-wrapper')]/table/thead/tr/th/span[contains(text(), 'ID')]" dependentSelector="//span[contains(text(), 'ID')]/parent::th[not(contains(@class, '_descend'))]/parent::tr/parent::thead/parent::table/parent::div[contains(@data-role, 'grid-wrapper')]" stepKey="secondClickToAttemptSortByIdDescending" visible="true"/>
        <waitForLoadingMaskToDisappear stepKey="waitForSecondIdSortDescendingToFinish" />
        <click selector="{{CmsPagesPageActionsSection.select(CMSPage.identifier)}}" stepKey="clickSelectCreatedCMSPage" />
        <click selector="{{CmsPagesPageActionsSection.edit(CMSPage.identifier)}}" stepKey="navigateToCreatedCMSPage" />
        <waitForPageLoad stepKey="waitForPageLoad3"/>
        <click selector="{{CmsNewPagePageContentSection.header}}" stepKey="clickExpandContentTabForPage"/>
        <waitForLoadingMaskToDisappear stepKey="waitForLoadingMaskOfStagingSection" />
    </actionGroup>
    <actionGroup name="navigateToCreatedCMSBlockPage">
        <arguments>
            <argument name="CMSBlockPage" defaultValue=""/>
        </arguments>
        <amOnPage url="{{CmsBlocksPage.url}}" stepKey="navigateToCMSBlocksGrid"/>
        <waitForPageLoad stepKey="waitForPageLoad1"/>
        <conditionalClick selector="{{CmsPagesPageActionsSection.clearAllButton}}" dependentSelector="{{CmsPagesPageActionsSection.activeFilters}}" stepKey="clickToResetFilter" visible="true"/>
        <waitForPageLoad stepKey="waitForPageLoad2"/>
        <conditionalClick selector="{{BlockPageActionsSection.idColumn}}" dependentSelector="//span[contains(text(), 'ID')]/parent::th[not(contains(@class, '_descend'))]/parent::tr/parent::thead/parent::table/parent::div[contains(@data-role, 'grid-wrapper')]" stepKey="clickToAttemptSortByIdDescending" visible="true"/>
        <waitForLoadingMaskToDisappear stepKey="waitForFirstIdSortDescendingToFinish" />
        <!-- Conditional Click again in case it goes from default state to ascending on first click  -->
        <conditionalClick selector="{{BlockPageActionsSection.idColumn}}" dependentSelector="//span[contains(text(), 'ID')]/parent::th[not(contains(@class, '_descend'))]/parent::tr/parent::thead/parent::table/parent::div[contains(@data-role, 'grid-wrapper')]" stepKey="secondClickToAttemptSortByIdDescending" visible="true"/>
        <waitForLoadingMaskToDisappear stepKey="waitForSecondIdSortDescendingToFinish" />
        <click selector="{{BlockPageActionsSection.select(CMSBlockPage.identifier)}}" stepKey="clickSelectCreatedCMSBlock" />
        <click selector="{{BlockPageActionsSection.edit(CMSBlockPage.identifier)}}" stepKey="navigateToCreatedCMSBlock" />
        <waitForPageLoad stepKey="waitForPageLoad3"/>
        <waitForLoadingMaskToDisappear stepKey="waitForLoadingMaskOfStagingSection" />
    </actionGroup>
    <actionGroup name="DeleteCMSBlockActionGroup">
        <amOnPage url="{{CmsBlocksPage.url}}" stepKey="navigateToCMSPagesGrid"/>
        <waitForPageLoad stepKey="waitForPageLoad"/>
        <click selector="{{CmsPagesPageActionsSection.select(_defaultBlock.title)}}" stepKey="ClickOnSelect"/>
        <click selector="{{CmsPagesPageActionsSection.delete(_defaultBlock.title)}}" stepKey="ClickOnEdit"/>
        <waitForPageLoad stepKey="waitForPageLoad3"/>
        <click selector="{{CmsPagesPageActionsSection.deleteConfirm}}" stepKey="ClickToConfirm"/>
        <waitForPageLoad stepKey="waitForPageLoad4"/>
        <see userInput="You deleted the block." stepKey="VerifyBlockIsDeleted"/>
    </actionGroup>
    <actionGroup name="AddStoreViewToCmsPage" extends="navigateToCreatedCMSPage">
        <arguments>
            <argument name="storeViewName" type="string"/>
        </arguments>
        <remove keyForRemoval="clickExpandContentTabForPage"/>
        <remove keyForRemoval="waitForLoadingMaskOfStagingSection"/>
        <click selector="{{CmsNewPagePiwSection.header}}" stepKey="clickPageInWebsites" after="waitForPageLoad3"/>
        <waitForElementVisible selector="{{CmsNewPagePiwSection.selectStoreView(storeViewName)}}" stepKey="waitForStoreGridReload"/>
        <clickWithLeftButton selector="{{CmsNewPagePiwSection.selectStoreView(storeViewName)}}" stepKey="clickStoreView"/>
        <click selector="{{CmsNewPagePageActionsSection.expandSplitButton}}" stepKey="expandButtonMenu"/>
        <waitForElementVisible selector="{{CmsNewPagePageActionsSection.splitButtonMenu}}" stepKey="waitForSplitButtonMenuVisible"/>
        <click selector="{{CmsNewPagePageActionsSection.savePage}}" stepKey="clickSavePage"/>
        <waitForPageLoad stepKey="waitForPageLoad"/>
        <see userInput="You saved the page." stepKey="seeMessage"/>
    </actionGroup>
    <actionGroup name="saveAndCloseCMSBlockWithSplitButton">
        <waitForElementVisible selector="{{BlockNewPagePageActionsSection.expandSplitButton}}" stepKey="waitForExpandSplitButtonToBeVisible" />
        <click selector="{{BlockNewPagePageActionsSection.expandSplitButton}}" stepKey="expandSplitButton"/>
        <click selector="{{BlockNewPagePageActionsSection.saveAndClose}}" stepKey="clickSaveBlock"/>
        <waitForPageLoad stepKey="waitForPageLoadAfterClickingSave" />
        <see userInput="You saved the block." stepKey="assertSaveBlockSuccessMessage"/>
    </actionGroup>
    <actionGroup name="navigateToStorefrontForCreatedPage">
        <arguments>
            <argument name="page" type="string"/>
        </arguments>
        <amOnPage url="{{page}}" stepKey="goToStorefront"/>
        <waitForPageLoad stepKey="waitForPageLoad"/>
    </actionGroup>
    <actionGroup name="saveCMSBlock">
        <waitForElementVisible selector="{{CmsNewBlockBlockActionsSection.savePage}}" stepKey="waitForSaveButton"/>
        <click selector="{{CmsNewBlockBlockActionsSection.savePage}}" stepKey="clickSaveButton"/>
        <waitForPageLoad stepKey="waitForPageLoad"/>
        <see userInput="You saved the block." stepKey="seeSuccessfulSaveMessage"/>
    </actionGroup>
    <actionGroup name="saveAndContinueEditCmsPage">
        <waitForElementVisible time="10" selector="{{CmsNewPagePageActionsSection.saveAndContinueEdit}}" stepKey="waitForSaveAndContinueVisibility"/>
        <click selector="{{CmsNewPagePageActionsSection.saveAndContinueEdit}}" stepKey="clickSaveAndContinueEditCmsPage"/>
        <waitForPageLoad stepKey="waitForCmsPageLoad"/>
        <waitForElementVisible time="1" selector="{{CmsNewPagePageActionsSection.cmsPageTitle}}" stepKey="waitForCmsPageSaveButton"/>
        <waitForLoadingMaskToDisappear stepKey="waitForLoadingMask"/>
    </actionGroup>
    <actionGroup name="saveCmsPage">
        <waitForElementVisible selector="{{CmsNewPagePageActionsSection.expandSplitButton}}" stepKey="waitForSplitButton"/>
        <click selector="{{CmsNewPagePageActionsSection.expandSplitButton}}" stepKey="expandSplitButton"/>
        <waitForElementVisible selector="{{CmsNewPagePageActionsSection.savePage}}" stepKey="waitForSaveCmsPage"/>
        <click selector="{{CmsNewPagePageActionsSection.savePage}}" stepKey="clickSaveCmsPage"/>
        <waitForElementVisible time="1" selector="{{CmsPagesPageActionsSection.addNewPageButton}}" stepKey="waitForCmsPageSaveButton"/>
        <see userInput="You saved the page." selector="{{CmsPagesPageActionsSection.savePageSuccessMessage}}" stepKey="assertSavePageSuccessMessage"/>
    </actionGroup>
    <actionGroup name="setLayout">
        <arguments>
            <argument name="designSection"/>
            <argument name="layoutOption"/>
        </arguments>
        <waitForElementVisible selector="{{designSection.DesignTab}}" stepKey="waitForDesignTabVisible"/>
        <conditionalClick selector="{{designSection.DesignTab}}" dependentSelector="{{designSection.LayoutDropdown}}" visible="false" stepKey="clickOnDesignTab"/>
        <waitForPageLoad stepKey="waitForPageLoadDesignTab"/>
        <waitForElementVisible selector="{{designSection.LayoutDropdown}}" stepKey="waitForLayoutDropDown" />
        <selectOption selector="{{designSection.LayoutDropdown}}" userInput="{{layoutOption}}" stepKey="selectLayout"/>
    </actionGroup>
</actionGroups>
