<?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="AdminUpdateSimpleProductWithRegularPriceInStockVisibleInSearchOnlyTest">
        <annotations>
            <stories value="Update Simple Product"/>
            <title value="Update Simple Product with Regular Price (In Stock) Visible in Search Only"/>
            <description value="Test log in to Update Simple Product and Update Simple Product with Regular Price (In Stock) Visible in Search Only"/>
            <testCaseId value="MC-10805"/>
            <severity value="CRITICAL"/>
            <group value="catalog"/>
            <group value="mtf_migrated"/>
        </annotations>
        <before>
            <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
            <createData entity="SimpleSubCategory" stepKey="initialCategoryEntity"/>
            <createData entity="defaultSimpleProduct" stepKey="initialSimpleProduct">
                <requiredEntity createDataKey="initialCategoryEntity"/>
            </createData>
            <createData entity="SimpleSubCategory" stepKey="categoryEntity"/>
            <magentoCron groups="index" stepKey="reindex"/>
        </before>
        <after>
            <deleteData stepKey="deleteSimpleSubCategory" createDataKey="initialCategoryEntity"/>
            <deleteData stepKey="deleteSimpleSubCategory2" createDataKey="categoryEntity"/>
            <actionGroup ref="DeleteProductBySkuActionGroup" stepKey="deleteCreatedProduct">
                <argument name="sku" value="{{simpleProductRegularPrice325InStock.sku}}"/>
            </actionGroup>
            <actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="clearFilters"/>
            <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
        </after>

        <!-- Search default simple product in the grid -->
        <actionGroup ref="AdminClearFiltersActionGroup" stepKey="openProductCatalogPage"/>
        <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="filterProductGrid"/>
        <actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="clickFirstRowToOpenDefaultSimpleProduct">
            <argument name="product" value="$$initialSimpleProduct$$"/>
        </actionGroup>
        <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="waitUntilProductIsOpened"/>

        <!-- Update simple product with regular price(in stock) -->
        <fillField selector="{{AdminProductFormSection.productName}}" userInput="{{simpleProductRegularPrice325InStock.name}}" stepKey="fillSimpleProductName"/>
        <fillField selector="{{AdminProductFormSection.productSku}}" userInput="{{simpleProductRegularPrice325InStock.sku}}" stepKey="fillSimpleProductSku"/>
        <fillField selector="{{AdminProductFormSection.productPrice}}" userInput="{{simpleProductRegularPrice325InStock.price}}" stepKey="fillSimpleProductPrice"/>
        <actionGroup ref="AdminFillProductQtyOnProductFormActionGroup" stepKey="fillSimpleProductQuantity">
            <argument name="productQty" value="{{simpleProductRegularPrice325InStock.quantity}}"/>
        </actionGroup>
        <selectOption selector="{{AdminProductFormSection.stockStatus}}" userInput="{{simpleProductRegularPrice325InStock.status}}" stepKey="selectStockStatusInStock"/>
        <fillField selector="{{AdminProductFormSection.productWeight}}" userInput="{{simpleProductRegularPrice325InStock.weight}}" stepKey="fillSimpleProductWeight"/>
        <click selector="{{AdminProductFormSection.categoriesDropdown}}" stepKey="clickCategoriesDropDown"/>
        <fillField selector="{{AdminProductFormSection.searchCategory}}" userInput="$$initialCategoryEntity.name$$" stepKey="fillSearchForInitialCategory"/>
        <waitForPageLoad stepKey="waitForCategory1"/>
        <click selector="{{AdminProductFormSection.selectCategory($$initialCategoryEntity.name$$)}}" stepKey="unselectInitialCategory"/>
        <fillField selector="{{AdminProductFormSection.searchCategory}}" userInput="$$categoryEntity.name$$" stepKey="fillSearchCategory"/>
        <waitForPageLoad stepKey="waitForCategory2"/>
        <click selector="{{AdminProductFormSection.selectCategory($$categoryEntity.name$$)}}" stepKey="clickOnCategory"/>
        <actionGroup ref="AdminSubmitCategoriesPopupActionGroup" stepKey="clickOnDoneAdvancedCategorySelect"/>
        <selectOption selector="{{AdminProductFormSection.visibility}}" userInput="{{simpleProductRegularPrice325InStock.visibility}}" stepKey="selectVisibility"/>
        <click selector="{{AdminProductSEOSection.sectionHeader}}" stepKey="clickAdminProductSEOSection"/>
        <fillField selector="{{AdminProductSEOSection.urlKeyInput}}" userInput="{{simpleProductRegularPrice325InStock.urlKey}}" stepKey="fillUrlKey"/>
        <scrollToTopOfPage stepKey="scrollToTopOfAdminProductFormSection"/>
        <actionGroup ref="AdminProductFormSaveButtonClickActionGroup" stepKey="clickSaveButton"/>

        <!-- Verify customer see success message -->
        <see selector="{{AdminProductFormSection.successMessage}}" userInput="You saved the product." stepKey="seeAssertSimpleProductSaveSuccessMessage"/>

        <!-- Search updated simple product(from above step) in the grid page -->
        <actionGroup ref="AdminProductCatalogPageOpenActionGroup" stepKey="openProductCatalogPageToSearchUpdatedSimpleProduct"/>
        <conditionalClick selector="{{AdminProductGridFilterSection.clearAll}}" dependentSelector="{{AdminProductGridFilterSection.clearAll}}" visible="true" stepKey="clickClearAll"/>
        <click selector="{{AdminProductGridFilterSection.filters}}" stepKey="clickFiltersButton"/>
        <fillField selector="{{AdminProductGridFilterSection.nameFilter}}" userInput="{{simpleProductRegularPrice325InStock.name}}" stepKey="fillSimpleProductNameInNameFilter"/>
        <fillField selector="{{AdminProductGridFilterSection.skuFilter}}" userInput="{{simpleProductRegularPrice325InStock.sku}}" stepKey="fillProductSku"/>
        <click selector="{{AdminProductGridFilterSection.applyFilters}}" stepKey="clickApplyFiltersButton"/>
        <click selector="{{AdminProductGridFilterSection.nthRow('1')}}" stepKey="clickFirstRowToVerifyUpdatedSimpleProductVisibleInGrid"/>
        <waitForPageLoad stepKey="waitUntilSimpleProductPageIsOpened"/>

        <!-- Verify customer see updated simple product in the product form page -->
        <seeInField selector="{{AdminProductFormSection.productName}}" userInput="{{simpleProductRegularPrice325InStock.name}}" stepKey="seeSimpleProductName"/>
        <seeInField selector="{{AdminProductFormSection.productSku}}" userInput="{{simpleProductRegularPrice325InStock.sku}}" stepKey="seeSimpleProductSku"/>
        <seeInField selector="{{AdminProductFormSection.productPrice}}" userInput="{{simpleProductRegularPrice325InStock.price}}" stepKey="seeSimpleProductPrice"/>
        <seeInField selector="{{AdminProductFormSection.productQuantity}}" userInput="{{simpleProductRegularPrice325InStock.quantity}}" stepKey="seeSimpleProductQuantity"/>
        <seeInField selector="{{AdminProductFormSection.productStockStatus}}" userInput="{{simpleProductRegularPrice325InStock.status}}" stepKey="seeSimpleProductStockStatus"/>
        <seeInField selector="{{AdminProductFormSection.productWeight}}" userInput="{{simpleProductRegularPrice325InStock.weight}}" stepKey="seeSimpleProductWeight"/>

        <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="clickCategoriesDropDownToVerify"/>
        <actionGroup ref="AssertAdminProductIsAssignedToCategoryActionGroup" stepKey="selectedCategories">
            <argument name="categoryName" value="$$categoryEntity.name$$"/>
        </actionGroup>
        <seeInField selector="{{AdminProductFormSection.visibility}}" userInput="{{simpleProductRegularPrice325InStock.visibility}}" stepKey="seeVisibility"/>
        <scrollTo selector="{{AdminProductSEOSection.sectionHeader}}" x="0" y="-80" stepKey="scrollToAdminProductSEOSection1"/>
        <click selector="{{AdminProductSEOSection.sectionHeader}}" stepKey="clickAdminProductSEOSection1"/>
        <seeInField selector="{{AdminProductSEOSection.urlKeyInput}}" userInput="{{simpleProductRegularPrice325InStock.urlKey}}" stepKey="seeUrlKey"/>

        <!--Verify customer don't see updated simple product link on category page -->
        <amOnPage url="{{StorefrontCategoryPage.url($$categoryEntity.custom_attributes[url_key]$$)}}" stepKey="openCategoryPage"/>
        <waitForPageLoad stepKey="waitForCategoryPageLoad"/>
        <dontSee selector="{{StorefrontCategoryMainSection.productLink}}" userInput="{{simpleProductRegularPrice325InStock.name}}" stepKey="dontSeeSimpleProductNameOnCategoryPage"/>

        <!-- Verify customer see updated simple product (from the above step) on the storefront page -->
        <actionGroup ref="OpenStoreFrontProductPageActionGroup" stepKey="goToProductPage">
            <argument name="productUrlKey" value="{{simpleProductRegularPrice325InStock.urlKey}}"/>
        </actionGroup>
        <comment userInput="Comment is added to preserve the step key for backward compatibilityr" stepKey="waitForStorefrontProductPageLoad"/>

        <actionGroup ref="StorefrontAssertProductNameOnProductPageActionGroup" stepKey="seeSimpleProductNameOnStoreFrontPage">
            <argument name="productName" value="{{simpleProductRegularPrice325InStock.name}}"/>
        </actionGroup>

        <actionGroup ref="StorefrontAssertProductPriceOnProductPageActionGroup" stepKey="seeSimpleProductPriceOnStoreFrontPage">
            <argument name="productPrice" value="{{simpleProductRegularPrice325InStock.price}}"/>
        </actionGroup>

        <actionGroup ref="StorefrontAssertProductSkuOnProductPageActionGroup" stepKey="seeProductSku">
            <argument name="productSku" value="{{simpleProductRegularPrice325InStock.sku}}"/>
        </actionGroup>

        <comment userInput="Comment is added to preserve the step key for backward compatibilityr" stepKey="productStockAvailableStatus"/>
        <actionGroup ref="AssertStorefrontProductStockStatusOnProductPageActionGroup" stepKey="assertStockAvailableOnProductPage">
            <argument name="productStockStatus" value="{{simpleProductRegularPrice325InStock.storefrontStatus}}"/>
        </actionGroup>
        <comment userInput="Comment is added to preserve the step key for backward compatibilityr" stepKey="productPriceAmount"/>
        <comment userInput="Comment is added to preserve the step key for backward compatibilityr" stepKey="assertOldPriceTextOnProductPage"/>

        <!--Verify customer see updated simple product link on magento storefront page and is searchable by sku -->
        <amOnPage url="{{StorefrontProductPage.url(simpleProductRegularPrice325InStock.urlKey)}}" stepKey="goToMagentoStorefrontPage"/>
        <waitForPageLoad stepKey="waitForStoreFrontProductPageLoad"/>
        <actionGroup ref="StorefrontCheckQuickSearchStringActionGroup" stepKey="fillSimpleProductSkuInSearchTextBox">
            <argument name="phrase" value="{{simpleProductRegularPrice325InStock.sku}}"/>
        </actionGroup>
        <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="waitForSearchTextBox"/>
        <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="clickSearchTextBoxButton"/>
        <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="waitForSearch"/>
        <actionGroup ref="StorefrontAssertProductNameOnProductMainPageActionGroup" stepKey="seeProductName">
            <argument name="productName" value="{{simpleProductRegularPrice325InStock.name}}"/>
        </actionGroup>
    </test>
</tests>
