<?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="StorefrontProductNameMinicartOnCheckoutPageDifferentStoreViewsTest">
        <annotations>
            <features value="Checkout"/>
            <stories value="Minicart"/>
            <title value="Checking Product name in Minicart and on Checkout page with different store views"/>
            <description value="Checking Product name in Minicart and on Checkout page with different store views"/>
            <severity value="MAJOR"/>
            <testCaseId value="MC-28566"/>
            <useCaseId value="MAGETWO-96421"/>
            <group value="checkout"/>
        </annotations>
        <before>
            <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>

            <!--Create a product-->
            <createData entity="SimpleProduct2" stepKey="createProduct"/>
        </before>
        <after>
            <!--Delete created data-->
            <deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
            <actionGroup ref="AdminDeleteStoreViewActionGroup" stepKey="deleteStoreView">
                <argument name="customStore" value="customStore"/>
            </actionGroup>
            <actionGroup ref="ClearFiltersAdminDataGridActionGroup" stepKey="clearGridFilter"/>
            <magentoCron groups="index" stepKey="reindex"/>

            <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
        </after>

        <!-- Create store view -->
        <actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createStoreView">
            <argument name="customStore" value="customStore"/>
        </actionGroup>
        <magentoCron groups="index" stepKey="reindex"/>

        <!--Go to created product page-->
        <actionGroup ref="AdminProductPageOpenByIdActionGroup" stepKey="goToEditPage">
            <argument name="productId" value="$$createProduct.id$$"/>
        </actionGroup>
        <waitForPageLoad stepKey="waitForProductPage"/>

        <!--Switch to second store view and change the product name-->
        <actionGroup ref="SwitchToTheNewStoreViewActionGroup" stepKey="switchToCustomStoreView">
            <argument name="storeViewName" value="{{customStore.name}}"/>
        </actionGroup>
        <waitForPageLoad stepKey="waitForPageLoad"/>
        <click selector="{{AdminProductFormSection.productNameUseDefault}}" stepKey="uncheckUseDefault"/>
        <fillField selector="{{AdminProductFormSection.productName}}" userInput="$$createProduct.name$$-new" stepKey="fillProductName"/>
        <actionGroup ref="AdminProductFormSaveActionGroup" stepKey="saveProduct"/>

        <!--Add product to cart-->
        <amOnPage url="{{StorefrontProductPage.url($$createProduct.custom_attributes[url_key]$$)}}" stepKey="amOnSimpleProductPage"/>
        <waitForPageLoad stepKey="waitForProductPageLoad"/>
        <actionGroup ref="AddToCartFromStorefrontProductPageActionGroup" stepKey="addToCartFromStorefrontProductPage">
            <argument name="productName" value="$createProduct.name$$"/>
        </actionGroup>

        <!--Switch to second store view-->
        <actionGroup ref="StorefrontSwitchStoreViewActionGroup" stepKey="switchStoreView">
            <argument name="storeView" value="customStore"/>
        </actionGroup>
        <waitForPageLoad stepKey="waitForStoreView"/>

        <!--Check product name in Minicart-->
        <actionGroup ref="StorefrontClickOnMiniCartActionGroup" stepKey="clickCart"/>
        <grabTextFrom selector="{{StorefrontMinicartSection.productName}}" stepKey="grabProductNameMinicart"/>
        <assertStringContainsString stepKey="assertProductNameMinicart">
			<actualResult type="const">$grabProductNameMinicart</actualResult>
			<expectedResult type="const">$$createProduct.name$$</expectedResult>
        </assertStringContainsString>
        <assertStringContainsString stepKey="assertProductNameMinicart1">
			<actualResult type="const">$grabProductNameMinicart</actualResult>
			<expectedResult type="string">-new</expectedResult>
        </assertStringContainsString>

        <!--Check product name in Shopping Cart page-->
        <comment userInput="BIC workaround" stepKey="clickViewAndEdit"/>
        <actionGroup ref="StorefrontCartPageOpenActionGroup" stepKey="openCart"/>
        <waitForPageLoad stepKey="waitForShoppingCartPageLoad"/>
        <grabTextFrom selector="{{CheckoutCartProductSection.productName}}" stepKey="grabProductNameCart"/>
        <assertStringContainsString stepKey="assertProductNameCart">
			<actualResult type="const">$grabProductNameCart</actualResult>
			<expectedResult type="const">$$createProduct.name$$</expectedResult>
        </assertStringContainsString>
        <assertStringContainsString stepKey="assertProductNameCart1">
			<actualResult type="const">$grabProductNameCart</actualResult>
			<expectedResult type="string">-new</expectedResult>
        </assertStringContainsString>

        <!--Proceed to checkout and check product name in Order Summary area-->
        <actionGroup ref="StorefrontClickProceedToCheckoutActionGroup" stepKey="proceedToCheckout"/>
        <waitForElementVisible selector="{{CheckoutShippingSection.email}}" stepKey="waitForShippingPageLoad"/>
        <conditionalClick selector="{{CheckoutShippingGuestInfoSection.itemInCart}}" dependentSelector="{{CheckoutShippingGuestInfoSection.itemInCartActive}}" visible="false" stepKey="clickItemInCart"/>
        <grabTextFrom selector="{{CheckoutShippingGuestInfoSection.productName}}" stepKey="grabProductNameShipping"/>
        <assertStringContainsString stepKey="assertProductNameShipping">
			<actualResult type="const">$grabProductNameShipping</actualResult>
			<expectedResult type="const">$$createProduct.name$$</expectedResult>
        </assertStringContainsString>
        <assertStringContainsString stepKey="assertProductNameShipping1">
			<actualResult type="const">$grabProductNameShipping</actualResult>
			<expectedResult type="string">-new</expectedResult>
        </assertStringContainsString>
    </test>
</tests>
