<?xml version="1.0" encoding="UTF-8"?>
<!--
 /**
  * Copyright © Magento, Inc. All rights reserved.
  * See COPYING.txt for license details.
  */
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
    <test name="EnableDisableBundleProductStatusTest">
        <annotations>
            <features value="Bundle"/>
            <stories value="Admin list bundle products"/>
            <title value="Admin should be able to change a bundle product status to Enabled/Disabled"/>
            <description value="Admin should be able to change a bundle product status to Enabled/Disabled"/>
            <severity value="CRITICAL"/>
            <testCaseId value="MC-215"/>
            <group value="Bundle"/>
            <group value="cloud"/>
        </annotations>
        <before>
            <!--Creating data-->
            <createData entity="_defaultCategory" stepKey="createPreReqCategory"/>
            <createData entity="SimpleProduct2" stepKey="simpleProduct1"/>
            <createData entity="SimpleProduct2" stepKey="simpleProduct2"/>
            <actionGroup ref="CliIndexerReindexActionGroup" stepKey="runCronIndex">
                <argument name="indices" value=""/>
            </actionGroup>

            <!--Admin login-->
            <actionGroup stepKey="loginToAdminPanel" ref="AdminLoginActionGroup"/>
        </before>
        <after>
            <deleteData createDataKey="createPreReqCategory" stepKey="deletePreReqCategory"/>
            <deleteData createDataKey="simpleProduct1" stepKey="deleteSimpleProduct1"/>
            <deleteData createDataKey="simpleProduct2" stepKey="deleteSimpleProduct2"/>
            <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
        </after>
        <!--Go to bundle product creation page-->
        <actionGroup ref="AdminOpenNewProductFormPageActionGroup" stepKey="goToBundleProductCreationPage">
            <argument name="attributeSetId" value="{{BundleProduct.set}}"/>
            <argument name="productType" value="{{BundleProduct.type}}"/>
        </actionGroup>
        <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="waitForBundleProductCreatePageToLoad"/>

        <!-- Add two bundle items -->

        <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="conditionallyOpenSectionBundleItems"/>
        <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="clickAddOption3"/>
        <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="waitForBundleOptions"/>
        <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="fillOptionTitle"/>
        <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="selectInputType"/>
        <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="clickAddProductsToOption"/>
        <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="filterBundleProductOptions"/>
        <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="selectFirstGridRow"/>
        <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="filterBundleProductOptions2"/>
        <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="selectFirstGridRow2"/>
        <actionGroup ref="AddBundleOptionWithTwoProductsActionGroup" stepKey="clickAddSelectedBundleProducts">
            <argument name="x" value="0"/>
            <argument name="n" value="1"/>
            <argument name="prodOneSku" value="$$simpleProduct1.sku$$"/>
            <argument name="prodTwoSku" value="$$simpleProduct2.sku$$"/>
            <argument name="optionTitle" value="{{BundleProduct.optionTitle1}}"/>
            <argument name="inputType" value="{{BundleProduct.optionInputType1}}"/>
        </actionGroup>
        <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="fillProductDefaultQty1"/>
        <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="fillProductDefaultQty2"/>

        <!--Fill out ancillary data on bundle product-->
        <actionGroup ref="AncillaryPrepBundleProductActionGroup" stepKey="createBundledProductForTwoSimpleProducts">
            <argument name="bundleProduct" value="BundleProduct"/>
        </actionGroup>

        <!--Save the product-->
        <actionGroup ref="AdminProductFormSaveActionGroup" stepKey="clickSaveButton"/>
        <actionGroup ref="AssertMessageInAdminPanelActionGroup" stepKey="messageYouSavedTheProductIsShown">
            <argument name="message" value="You saved the product."/>
        </actionGroup>

        <!--Testing enabled view-->
        <!--Product enabled by default-->
        <!--Go to page-->
        <actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="GoToProductPage">
            <argument name="productUrl" value="{{BundleProduct.urlKey}}"/>
        </actionGroup>
        <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="waitForBundleProductPageToLoad"/>
        <actionGroup ref="StorefrontAssertProductNameOnProductPageActionGroup" stepKey="LookingForNameOfProduct">
            <argument name="productName" value="{{BundleProduct.name}}"/>
        </actionGroup>

        <!--Testing disabled view-->
        <actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="GoToProductCatalog"/>
        <actionGroup ref="FilterProductGridBySkuActionGroup" stepKey="FindProductEditPage">
            <argument name="product" value="BundleProduct"/>
        </actionGroup>
        <click selector="{{AdminDataGridTableSection.rowViewAction('1')}}" stepKey="ClickProductInGrid"/>
        <click stepKey="ClickOnEnableDisableToggle" selector="{{AdminProductFormBundleSection.enableDisableToggle}}"/>
        <actionGroup ref="AdminProductFormSaveActionGroup" stepKey="clickSaveButtonAgain"/>
        <actionGroup ref="AssertMessageInAdminPanelActionGroup" stepKey="messageYouSavedTheProductIsShownAgain">
            <argument name="message" value="You saved the product."/>
        </actionGroup>
        <actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="GoToProductPageAgain">
            <argument name="productUrl" value="{{BundleProduct.urlKey}}"/>
        </actionGroup>
        <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="WaitForProductPageToLoadToShowElement"/>
        <actionGroup ref="StorefrontAssertProductNameIsNotShownOnProductPageActionGroup" stepKey="LookingForNameOfProductTwo">
            <argument name="productName" value="{{BundleProduct.name}}"/>
        </actionGroup>
    </test>
</tests>
