<?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="AdminAddInStockProductToTheCartTest">
        <annotations>
            <stories value="Manage products"/>
            <title value="Add In Stock Product to Cart"/>
            <description value="Login as admin and add In Stock product to the cart"/>
            <severity value="CRITICAL"/>
            <testCaseId value="MC-11065"/>
            <group value="mtf_migrated"/>
        </annotations>
        <before>
            <!-- Login as admin -->
            <actionGroup ref="AdminLoginActionGroup" stepKey="login"/>
            <!--Create Category-->
            <createData entity="SimpleSubCategory" stepKey="createCategory"/>
            <!--Create Simple Product-->
            <createData entity="SimpleProduct" stepKey="createSimpleProduct">
                <requiredEntity createDataKey="createCategory"/>
            </createData>
        </before>
        <after>
             <!--Delete created entity -->
            <deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
            <deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
            <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
        </after>
        <!--Open Product Index Page and filter the product-->
        <actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="navigateToProductIndex"/>
        <actionGroup ref="FilterProductGridBySkuActionGroup" stepKey="filterProduct">
            <argument name="product" value="SimpleProduct"/>
        </actionGroup>
        <!-- Update product Advanced Inventory setting -->
        <click stepKey="openSelectedProduct" selector="{{AdminProductGridSection.productRowBySku($$createSimpleProduct.sku$$)}}"/>
        <waitForPageLoad stepKey="waitForProductToLoad"/>
        <actionGroup ref="AdminClickOnAdvancedInventoryLinkActionGroup" stepKey="clickOnAdvancedInventoryLink"/>
        <uncheckOption selector="{{AdminProductFormAdvancedInventorySection.useConfigSettings}}" stepKey="uncheckConfigSetting"/>
        <selectOption selector="{{AdminProductFormAdvancedInventorySection.manageStock}}"  userInput="Yes" stepKey="clickOnManageStock"/>
        <fillField selector="{{AdminProductFormAdvancedInventorySection.advancedInventoryQty}}" userInput="5" stepKey="fillProductQty"/>
        <uncheckOption selector="{{AdminProductFormAdvancedInventorySection.miniQtyConfigSetting}}" stepKey="uncheckMiniQtyCheckBox"/>
        <fillField selector="{{AdminProductFormAdvancedInventorySection.miniQtyAllowedInCart}}" userInput="1" stepKey="fillMiniAllowedQty"/>
        <uncheckOption selector="{{AdminProductFormAdvancedInventorySection.maxiQtyConfigSetting}}" stepKey="uncheckMaxQtyCheckBox"/>
        <fillField selector="{{AdminProductFormAdvancedInventorySection.maxiQtyAllowedInCart}}" userInput="10000" stepKey="fillMaxAllowedQty"/>
        <selectOption  selector="{{AdminProductFormAdvancedInventorySection.qtyUsesDecimals}}" userInput="Yes" stepKey="selectQuatityUsesDecimal"/>
        <uncheckOption selector="{{AdminProductFormAdvancedInventorySection.notifyBelowQtyConfigSetting}}" stepKey="uncheckNotifyBelowQtyheckBox"/>
        <fillField selector="{{AdminProductFormAdvancedInventorySection.notifyBelowQty}}" userInput="1" stepKey="fillNotifyBelowQty"/>
        <actionGroup ref="AdminSetStockStatusConfigActionGroup" stepKey="selectOutOfStock">
            <argument name="stockStatus" value="In Stock"/>
        </actionGroup>
        <actionGroup ref="AdminSubmitAdvancedInventoryFormActionGroup" stepKey="clickOnDoneButton"/>
        <actionGroup ref="AdminProductFormSaveActionGroup" stepKey="clickOnSaveButton"/>
        <see selector="{{AdminCategoryMessagesSection.SuccessMessage}}" userInput="You saved the product." stepKey="messageYouSavedTheProductIsShown"/>
        <!--Clear cache and reindex-->
        <actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex">
            <argument name="indices" value=""/>
        </actionGroup>
        <actionGroup ref="CliCacheFlushActionGroup" stepKey="flushCache">
            <argument name="tags" value=""/>
        </actionGroup>
        <!--Verify product is visible in category front page -->
        <amOnPage url="$$createCategory.name$$.html" stepKey="openCategoryStoreFrontPage"/>
        <waitForPageLoad stepKey="waitForCategoryPageToLoad"/>
        <seeElement selector="{{StorefrontHeaderSection.NavigationCategoryByName(SimpleSubCategory.name)}}" stepKey="seeCategoryInFrontPage"/>
        <click selector="{{StorefrontHeaderSection.NavigationCategoryByName(SimpleSubCategory.name)}}" stepKey="clickOnCategory"/>
        <see selector="{{StorefrontCategoryMainSection.productName}}" userInput="{{SimpleProduct.name}}" stepKey="seeProductNameInCategoryPage"/>
        <!--Verify Product In Store Front-->
        <amOnPage url="$$createSimpleProduct.name$$.html" stepKey="goToStorefrontPage"/>
        <waitForPageLoad stepKey="waitForProductFrontPageToLoad"/>
        <see selector="{{StorefrontProductInfoMainSection.productName}}" userInput="{{SimpleProduct.name}}" stepKey="seeProductNameInStoreFront"/>
        <see selector="{{StorefrontProductInfoMainSection.productPrice}}" userInput="{{SimpleProduct.price}}" stepKey="seeProductPriceInStoreFront"/>
        <actionGroup ref="StorefrontAssertProductSkuOnProductPageActionGroup" stepKey="seeProductSkuInStoreFront">
            <argument name="productSku" value="{{SimpleProduct.sku}}"/>
        </actionGroup>
        <see selector="{{StorefrontProductInfoMainSection.productStockStatus}}" userInput="In Stock" stepKey="seeProductStatusInStoreFront"/>
        <!--Add Product to the cart-->
        <fillField selector="{{StorefrontProductPageSection.qtyInput}}" userInput="1" stepKey="fillProductQuantity"/>
        <actionGroup ref="StorefrontClickAddToCartOnProductPageActionGroup" stepKey="addToCartFromStorefrontProductPage"/>
        <seeElement selector="{{StorefrontProductPageSection.successMsg}}" stepKey="seeSuccessSaveMessage"/>
        <seeElement selector="{{StorefrontMinicartSection.quantity(1)}}" stepKey="seeAddedProductQuantityInCart"/>
        <actionGroup ref="StorefrontClickOnMiniCartActionGroup" stepKey="clickOnMiniCart"/>
        <see selector="{{StorefrontMinicartSection.miniCartItemsText}}" userInput="{{SimpleProduct.name}}"  stepKey="seeProductNameInMiniCart"/>
        <see selector="{{StorefrontMinicartSection.miniCartItemsText}}" userInput="{{SimpleProduct.price}}" stepKey="seeProductPriceInMiniCart"/>
        <seeElement selector="{{StorefrontMinicartSection.goToCheckout}}" stepKey="seeCheckOutButtonInMiniCart"/>
    </test>
</tests>
