<?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">
    <!--Fill main fields in create product form-->
    <actionGroup name="fillMainBundleProductForm">
        <annotations>
            <description>Fills the Name, SKU and Stock Status fields.</description>
        </annotations>
        <arguments>
            <argument name="product" defaultValue="BundleProduct"/>
        </arguments>

        <fillField selector="{{AdminProductFormSection.productName}}" userInput="{{product.name}}" stepKey="fillProductSku"/>
        <fillField selector="{{AdminProductFormSection.productSku}}" userInput="{{product.sku}}" stepKey="fillProductName"/>
        <selectOption selector="{{AdminProductFormSection.productStockStatus}}" userInput="{{product.status}}" stepKey="selectStockStatus"/>
    </actionGroup>

    <!--Check that required fields are actually required-->
    <actionGroup name="checkRequiredFieldsInBundleProductForm">
        <annotations>
            <description>Clears the Name and SKU fields when adding a Product and then verifies that they are required after attempting to Save.</description>
        </annotations>

        <clearField selector="{{AdminProductFormSection.productName}}" stepKey="clearProductSku"/>
        <clearField selector="{{AdminProductFormSection.productSku}}" stepKey="clearProductName"/>
        <click selector="{{AdminProductFormActionSection.saveButton}}" stepKey="clickSaveButton"/>
        <see selector="{{AdminHeaderSection.pageTitle}}" userInput="New Product" stepKey="seeStillOnEditPage"/>
        <see selector="{{AdminProductFormSection.fieldError('name')}}" userInput="This is a required field." stepKey="seeNameRequired"/>
        <see selector="{{AdminProductFormSection.fieldError('sku')}}" userInput="This is a required field." stepKey="seeSkuRequired"/>
    </actionGroup>

    <!--Filter product grid and see expected product-->
    <actionGroup name="viewBundleProductInAdminGrid">
        <annotations>
            <description>Clears the Grid Filters on the Catalog Grid page and applies Filter by Name and Sku. Then checks to see if the Product exists in the 1st row. Then clears the Grid Filters again for future Tests.</description>
        </annotations>
        <arguments>
            <argument name="product" defaultValue="BundleProduct"/>
            <argument name="thumbnail" defaultValue="ProductPlaceholderImage"/>
        </arguments>

        <amOnPage url="{{AdminProductIndexPage.url}}" stepKey="visitAdminProductPage"/>
        <waitForPageLoad stepKey="waitForPageLoadInitial"/>
        <conditionalClick selector="{{AdminProductGridFilterSection.clearFilters}}" dependentSelector="{{AdminProductGridFilterSection.clearFilters}}" visible="true" stepKey="clickClearFiltersInitial"/>
        <click selector="{{AdminProductGridFilterSection.filters}}" stepKey="openProductFilters"/>
        <fillField selector="{{AdminProductGridFilterSection.nameFilter}}" userInput="{{product.name}}" stepKey="fillProductNameFilter"/>
        <fillField selector="{{AdminProductGridFilterSection.skuFilter}}" userInput="{{product.sku}}" stepKey="fillProductSkuFilter"/>
        <selectOption selector="{{AdminProductGridFilterSection.typeFilter}}" userInput="{{product.type_id}}" stepKey="selectionProductType"/>
        <click selector="{{AdminProductGridFilterSection.applyFilters}}" stepKey="clickApplyFilters"/>
        <see selector="{{AdminProductGridSection.firstProductRow}}" userInput="{{product.name}}"  stepKey="seeProductNameInGrid"/>
        <click selector="{{AdminProductGridFilterSection.clearFilters}}" stepKey="clickClearFiltersAfter"/>
    </actionGroup>
</actionGroups>
