<?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="AdminBulkUnAssignSourcesToBulkSimpleProductsActionGroup">
        <annotations>
            <description>Admin bulk un-assign Sources to a bulk of simple products</description>
        </annotations>
        <arguments>
            <argument name="product1Sku" type="string"/>
            <argument name="product4Sku" type="string"/>
            <argument name="source1_code"/>
            <argument name="source2_code"/>
            <argument name="source3_code"/>
            <argument name="source4_code"/>
        </arguments>
        <amOnPage url="{{AdminProductIndexPage.url}}" stepKey="visitAdminProductPage"/>
        <waitForPageLoad stepKey="waitForProductIndexPageToLoad"/>
        <conditionalClick selector="{{AdminProductGridFilterSection.clearFilters}}" dependentSelector="{{AdminProductGridFilterSection.clearFilters}}" visible="true" stepKey="clickClearFilters"/>
        <click selector="{{AdminProductGridFilterSection.filters}}" stepKey="openProductFilters"/>
        <fillField selector="{{AdminProductGridFilterSection.skuFilter}}" userInput="{{product1Sku}}" stepKey="fillProduct1SkuFilter"/>
        <click selector="{{AdminProductGridFilterSection.applyFilters}}" stepKey="clickApplyFilters"/>
        <waitForElementNotVisible selector="{{AdminProductGridSection.loadingMask}}" stepKey="waitForFilteredGridLoad" time="30"/>
        <grabTextFrom selector="{{AdminProductGridSection.productRowByID('product1Sku')}}" stepKey="grabProd1Id"/>
        <conditionalClick selector="{{AdminProductGridFilterSection.clearFilters}}" dependentSelector="{{AdminProductGridFilterSection.clearFilters}}" visible="true" stepKey="clickClearFiltersForSecondProduct"/>
        <click selector="{{AdminProductGridFilterSection.filters}}" stepKey="openProductFiltersAgain"/>
        <clearField selector="{{AdminProductGridFilterSection.skuFilter}}" stepKey="clearFilterFieldBySKU"/>
        <fillField selector="{{AdminProductGridFilterSection.skuFilter}}" userInput="{{product4Sku}}" stepKey="fillProduct4SkuFilter"/>
        <click selector="{{AdminProductGridFilterSection.applyFilters}}" stepKey="clickApplyFiltersForProd4"/>
        <waitForElementNotVisible selector="{{AdminProductGridSection.loadingMask}}" stepKey="waitForFilteredGridLoadForProd4" time="30"/>
        <grabTextFrom selector="{{AdminProductGridSection.productRowByID('product4Sku')}}" stepKey="grabProd4Id"/>

        <!-- Select the  range of IDs and apply filter -->
        <conditionalClick selector="{{AdminProductGridFilterSection.clearFilters}}" dependentSelector="{{AdminProductGridFilterSection.clearFilters}}" visible="true" stepKey="clickClearFiltersForSettingTheRange"/>
        <click selector="{{AdminProductGridFilterSection.filters}}" stepKey="openProductFiltersForRange"/>
        <fillField selector="{{AdminProductGridSection.productIdFrom}}" userInput="{$grabProd1Id}" stepKey="fillProduct1IdInFrom"/>
        <fillField selector="{{AdminProductGridSection.productIdTo}}" userInput="{$grabProd4Id}" stepKey="fillProduct1IdInTo"/>
        <click selector="{{AdminProductGridFilterSection.applyFilters}}" stepKey="clickApplyFiltersById"/>
        <waitForElementNotVisible selector="{{AdminProductGridSection.loadingMask}}" stepKey="waitForFilteredGridLoadPostFilterById" time="30"/>

        <!-- Select all the products in bulk -->
        <click selector="{{AdminProductGridSection.bulkProductSelect}}" stepKey="clickSelectAllProduct"/>
        <click selector="{{ProductsPageSection.actions}}" stepKey="clickOnActions"/>
        <click selector="{{AdminProductGridSection.selectBulkActions('Unassign Inventory Source')}}" stepKey="clickUnassignInventorySource"/>
        <waitForElementVisible selector="{{AdminProductGridSection.textMassSourceAssignmentHeader('Unassign Inventory Source')}}" stepKey="waitForPopUpVisible"/>
        <seeElement selector="{{AdminProductGridSection.textMassSourceAssignmentHeader('Unassign Inventory Source')}}" stepKey="assertsTheBulkSourceAssignmentTitlePopUp"/>
        <seeElement selector="{{AdminProductGridSection.textMassSourceAssignmentBody('Are you sure you want to unassign one or more sources from the selected items?')}}" stepKey="assertsTheBulkSourceAssignmentBodyPopUp"/>
        <click selector="{{AdminProductGridSection.acceptOKPopup}}" stepKey="clickOK"/>

        <!-- Select all the 4 sources in bulk an un-assign-->
        <waitForPageLoad stepKey="waitForBulkSourceAssignmentPageToLoad"/>
        <seeElement selector="{{AdminBulkSourceAssignmentSection.bulkSourceUnAssignmentTitle}}" stepKey="assertsTheBulkSourceAssignmentTitle"/>
        <checkOption selector="{{AdminBulkSourceAssignmentSection.selectTestSource(source1_code)}}" stepKey="checkSource1"/>
        <checkOption selector="{{AdminBulkSourceAssignmentSection.selectTestSource(source2_code)}}" stepKey="checkSource2"/>
        <checkOption selector="{{AdminBulkSourceAssignmentSection.selectTestSource(source3_code)}}" stepKey="checkSource3"/>
        <checkOption selector="{{AdminBulkSourceAssignmentSection.selectTestSource(source4_code)}}" stepKey="checkSource4"/>
        <click selector="{{AdminBulkSourceAssignmentSection.buttonUnAssignSources}}" stepKey="clickOnButtonUnassignSources"/>
        <seeElement selector="{{AdminBulkSourceAssignmentSection.msgBulkAssignmentSuccessful('Bulk operation was successful: 16 unassignments.')}}" stepKey="assertsSuccessfulAssignmentOfSourcesToProducts"/>
        <waitForPageLoad stepKey="waitForProductGridPagePostAssignmentToLoad"/>
    </actionGroup>
</actionGroups>
