<?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="AssignAttributeToGroup">
        <arguments>
            <argument name="group" type="string"/>
            <argument name="attribute" type="string"/>
        </arguments>
        <conditionalClick selector="{{AdminProductAttributeSetEditSection.attributeGroupExtender(group)}}" dependentSelector="{{AdminProductAttributeSetEditSection.attributeGroupCollapsed(group)}}" visible="true" stepKey="extendGroup"/>
        <waitForPageLoad stepKey="waitForPageLoad1"/>
        <dragAndDrop selector1="{{AdminProductAttributeSetEditSection.unassignedAttribute(attribute)}}" selector2="{{AdminProductAttributeSetEditSection.xThLineItemAttributeGroup(group, '1')}}" stepKey="dragAndDropToGroupProductDetails"/>
        <waitForPageLoad stepKey="waitForPageLoad2"/>
        <see userInput="{{attribute}}" selector="{{AdminProductAttributeSetEditSection.groupTree}}" stepKey="seeAttributeInGroup"/>
    </actionGroup>
    <actionGroup name="UnassignAttributeFromGroup">
        <arguments>
            <argument name="group" type="string"/>
            <argument name="attribute" type="string"/>
        </arguments>
        <conditionalClick selector="{{AdminProductAttributeSetEditSection.attributeGroupExtender(group)}}" dependentSelector="{{AdminProductAttributeSetEditSection.attributeGroupCollapsed(group)}}" visible="true" stepKey="extendGroup"/>
        <waitForPageLoad stepKey="waitForPageLoad1"/>
        <dragAndDrop selector1="{{AdminProductAttributeSetEditSection.assignedAttribute(attribute)}}" selector2="{{AdminProductAttributeSetEditSection.xThLineItemUnassignedAttribute('1')}}" stepKey="dragAndDropToUnassigned"/>
        <waitForPageLoad stepKey="waitForPageLoad2"/>
        <see userInput="{{attribute}}" selector="{{AdminProductAttributeSetEditSection.unassignedAttributesTree}}" stepKey="seeAttributeInUnassigned"/>
    </actionGroup>
    <actionGroup name="SaveAttributeSet">
        <click selector="{{AdminProductAttributeSetActionSection.save}}" stepKey="clickSave"/>
        <see userInput="You saved the attribute set" selector="{{AdminMessagesSection.success}}" stepKey="successMessage"/>
    </actionGroup>
    <actionGroup name="CreateDefaultAttributeSet">
        <!--Generic atrribute set creation-->
        <arguments>
            <argument name="label" type="string"/>
        </arguments>
        <amOnPage url="{{AdminProductAttributeSetGridPage.url}}" stepKey="goToAttributeSets"/>
        <waitForPageLoad stepKey="wait1"/>
        <click selector="{{AdminProductAttributeSetGridSection.addAttributeSetBtn}}" stepKey="clickAddAttributeSet"/>
        <fillField selector="{{AdminProductAttributeSetSection.name}}" userInput="{{label}}" stepKey="fillName"/>
        <click selector="{{AdminProductAttributeSetSection.saveBtn}}" stepKey="clickSave1"/>
    </actionGroup>
    <actionGroup name="goToAttributeGridPage">
        <amOnPage url="{{AdminProductAttributeSetGridPage.url}}" stepKey="goToAttributeSets"/>
    </actionGroup>
    <actionGroup name="goToAttributeSetByName">
        <arguments>
            <argument name="name" type="string"/>
        </arguments>
        <click selector="{{AdminProductAttributeSetGridSection.resetFilter}}" stepKey="clickResetButton"/>
        <fillField selector="{{AdminProductAttributeSetGridSection.filter}}" userInput="{{name}}" stepKey="filterByName"/>
        <click selector="{{AdminProductAttributeSetGridSection.searchBtn}}" stepKey="clickSearch"/>
        <click selector="{{AdminProductAttributeSetGridSection.nthRow('1')}}" stepKey="clickFirstRow"/>
        <waitForPageLoad stepKey="waitForPageLoad"/>
    </actionGroup>
    <!-- Filter By Attribute Label -->
    <actionGroup name="filterProductAttributeByAttributeLabel">
        <arguments>
            <argument name="productAttributeLabel" type="string"/>
        </arguments>
        <fillField selector="{{AdminProductAttributeGridSection.attributeLabelFilter}}" userInput="{{productAttributeLabel}}" stepKey="setAttributeLabel"/>
        <waitForPageLoad stepKey="waitForUserInput"/>
        <click selector="{{AdminProductAttributeGridSection.Search}}" stepKey="searchForAttributeFromTheGrid"/>
    </actionGroup>
    <actionGroup name="FilterProductAttributeSetGridByAttributeSetName">
        <arguments>
            <argument name="name" type="string"/>
        </arguments>
        <click selector="{{AdminProductAttributeSetGridSection.resetFilter}}" stepKey="clickResetButton"/>
        <fillField selector="{{AdminProductAttributeSetGridSection.filter}}" userInput="{{name}}" stepKey="filterByName"/>
        <click selector="{{AdminProductAttributeSetGridSection.searchBtn}}" stepKey="clickSearch"/>
        <click selector="{{AdminProductAttributeSetGridSection.nthRow('1')}}" stepKey="clickFirstRow"/>
        <waitForPageLoad time="30" stepKey="waitForPageLoad1"/>
    </actionGroup>

    <!-- Delete attribute set -->
    <actionGroup name="deleteAttributeSetByLabel">
        <arguments>
            <argument name="label" type="string"/>
        </arguments>
        <amOnPage url="{{AdminProductAttributeSetGridPage.url}}" stepKey="goToAttributeSets"/>
        <waitForPageLoad stepKey="waitForAttributeSetPageLoad"/>
        <fillField selector="{{AdminProductAttributeSetGridSection.filter}}" userInput="{{label}}" stepKey="filterByName"/>
        <click selector="{{AdminProductAttributeSetGridSection.searchBtn}}" stepKey="clickSearch"/>
        <click selector="{{AdminProductAttributeSetGridSection.nthRow('1')}}" stepKey="clickFirstRow"/>
        <waitForPageLoad stepKey="waitForClick"/>
        <click selector="{{AdminProductAttributeSetSection.deleteBtn}}" stepKey="clickDelete"/>
        <click selector="{{AdminProductAttributeSetSection.modalOk}}" stepKey="confirmDelete"/>
        <waitForPageLoad stepKey="waitForDeleteToFinish"/>
        <see selector="{{AdminCategoryMessagesSection.SuccessMessage}}" userInput="The attribute set has been removed." stepKey="seeDeleteMessage"/>
    </actionGroup>
</actionGroups>
