<?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">
    <!-- Filter by search query and select -->
    <actionGroup name="searchTermFilterBySearchQuery">
        <annotations>
            <description>Fills in the provided Search Query on the Admin Search Term grid page.</description>
        </annotations>
        <arguments>
            <argument name="searchQuery" type="string"/>
        </arguments>

        <click selector="{{AdminCatalogSearchTermIndexSection.resetFilterButton}}" stepKey="clickOnResetButton"/>
        <waitForPageLoad stepKey="waitForResetFilter"/>
        <fillField selector="{{AdminCatalogSearchTermIndexSection.searchQuery}}" userInput="{{searchQuery}}" stepKey="fillSearchQuery"/>
        <click selector="{{AdminCatalogSearchTermIndexSection.searchButton}}" stepKey="clickSearchButton"/>
        <waitForPageLoad stepKey="waitForSearchResultLoad"/>
        <checkOption selector="{{AdminCatalogSearchTermIndexSection.searchTermRowCheckboxBySearchQuery(searchQuery)}}" stepKey="checkCheckBox"/>
    </actionGroup>

    <!-- Delete search term -->
    <actionGroup name="deleteSearchTerm">
        <annotations>
            <description>Deletes the Search Terms in the Admin Search Term grid.</description>
        </annotations>

        <selectOption selector="{{AdminCatalogSearchTermIndexSection.massActions}}" userInput="delete" stepKey="selectDeleteOption"/>
        <click selector="{{AdminCatalogSearchTermIndexSection.submit}}" stepKey="clickSubmitButton"/>
        <click selector="{{AdminCatalogSearchTermIndexSection.okButton}}" stepKey="clickOkButton"/>
        <waitForElementVisible selector="{{AdminCatalogSearchTermMessagesSection.successMessage}}" stepKey="waitForSuccessMessage"/>
    </actionGroup>

    <!-- Delete all existing search terms -->
    <actionGroup name="DeleteAllSearchTerms">
        <selectOption userInput="selectAll" selector="{{AdminCatalogSearchTermIndexSection.selectMassActionCheckbox}}" stepKey="checkAllSearchTerms"/>
        <selectOption selector="{{AdminCatalogSearchTermIndexSection.massActions}}" userInput="delete" stepKey="selectDeleteOption"/>
        <click selector="{{AdminCatalogSearchTermIndexSection.submit}}" stepKey="clickSubmitButton"/>
        <click selector="{{AdminCatalogSearchTermIndexSection.okButton}}" stepKey="clickOkButton"/>
    </actionGroup>
</actionGroups>
