<?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="AdminMultipleWebsitesUseDefaultValuesTest">
        <annotations>
            <features value="Catalog"/>
            <stories value="Create websites"/>
            <title value="Use Default Value checkboxes should be checked for new website scope"/>
            <description value="Use Default Value checkboxes for product attribute should be checked for new website scope"/>
            <severity value="BLOCKER"/>
            <testCaseId value="MC-25783"/>
            <group value="Catalog"/>
        </annotations>

        <before>
            <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>

            <actionGroup ref="AdminCreateWebsiteActionGroup" stepKey="createAdditionalWebsite">
                <argument name="newWebsiteName" value="{{customWebsite.name}}"/>
                <argument name="websiteCode" value="{{customWebsite.code}}"/>
            </actionGroup>
            <actionGroup ref="AdminCreateNewStoreGroupActionGroup" stepKey="createNewStore">
                <argument name="website" value="{{customWebsite.name}}"/>
                <argument name="storeGroupName" value="{{customStoreGroup.name}}"/>
                <argument name="storeGroupCode" value="{{customStoreGroup.code}}"/>
            </actionGroup>
            <actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createNewStoreView">
                <argument name="StoreGroup" value="customStoreGroup"/>
                <argument name="customStore" value="customStore"/>
            </actionGroup>
            <magentoCron groups="index" stepKey="reindex"/>
        </before>

        <after>
            <actionGroup ref="AdminDeleteWebsiteActionGroup" stepKey="deleteSecondWebsite">
                <argument name="websiteName" value="{{customWebsite.name}}"/>
            </actionGroup>
            <magentoCron groups="index" stepKey="reindex"/>
            <actionGroup ref="AdminClearFiltersActionGroup" stepKey="clearFilters"/>
            <actionGroup ref="AdminLogoutActionGroup" stepKey="adminLogout"/>
        </after>

        <!--Create a Simple Product -->
        <actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="navigateToCatalogProductGrid"/>
        <comment userInput="Adding the comment to replace clickAddProductToggle action for preserving Backward Compatibility" stepKey="clickAddProductDropdown"/>
        <actionGroup ref="AdminClickAddProductToggleAndSelectProductTypeActionGroup" stepKey="clickAddSimpleProduct">
            <argument name="productType" value="simple"/>
        </actionGroup>
        <fillField userInput="{{_defaultProduct.name}}" selector="{{AdminProductFormSection.productName}}" stepKey="fillProductName"/>
        <fillField userInput="{{_defaultProduct.sku}}" selector="{{AdminProductFormSection.productSku}}" stepKey="fillProductSKU"/>
        <fillField userInput="{{_defaultProduct.price}}" selector="{{AdminProductFormSection.productPrice}}" stepKey="fillProductPrice"/>
        <actionGroup ref="AdminFillProductQtyOnProductFormActionGroup" stepKey="fillProductQuantity">
            <argument name="productQty" value="{{_defaultProduct.quantity}}"/>
        </actionGroup>

        <!-- Add product to second website and save the product -->
        <click selector="{{ProductInWebsitesSection.sectionHeader}}" stepKey="openProductInWebsites"/>
        <click selector="{{ProductInWebsitesSection.website(customWebsite.name)}}" stepKey="selectSecondWebsite"/>
        <click selector="{{AdminProductFormActionSection.saveButton}}" stepKey="clickSave"/>
        <waitForLoadingMaskToDisappear stepKey="waitForProductPageSave"/>
        <seeElement selector="{{AdminProductMessagesSection.successMessage}}" stepKey="seeSaveProductMessage"/>

        <!-- switch to the second store view -->
        <click selector="{{AdminProductFormActionSection.changeStoreButton}}" stepKey="clickStoreviewSwitcher"/>
        <click selector="{{AdminProductFormActionSection.selectStoreView(customStore.name)}}" stepKey="chooseStoreView"/>
        <click selector="{{AdminConfirmationModalSection.ok}}" stepKey="acceptStoreSwitchingMessage"/>
        <waitForPageLoad time="30" stepKey="waitForPageLoad9"/>
        <see userInput="{{customStore.name}}" selector="{{AdminMainActionsSection.storeSwitcher}}" stepKey="seeNewStoreViewName"/>

        <!-- Check if Use Default Value checkboxes are checked -->
        <seeCheckboxIsChecked selector="{{AdminProductFormSection.productStatusUseDefault}}" stepKey="seeProductStatusCheckboxChecked"/>
        <seeCheckboxIsChecked selector="{{AdminProductFormSection.productNameUseDefault}}" stepKey="seeProductNameCheckboxChecked"/>
        <seeCheckboxIsChecked selector="{{AdminProductFormSection.productTaxClassUseDefault}}" stepKey="seeTaxClassCheckboxChecked"/>
        <seeCheckboxIsChecked selector="{{AdminProductFormSection.visibilityUseDefault}}" stepKey="seeVisibilityCheckboxChecked"/>
    </test>
</tests>
