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

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
    <!-- Add Product to Compare from the category page and check message -->
    <actionGroup name="StorefrontAddCategoryProductToCompareActionGroup">
        <arguments>
            <argument name="productVar"/>
        </arguments>
        <moveMouseOver selector="{{StorefrontCategoryProductSection.ProductInfoByName(productVar.name)}}" stepKey="moveMouseOverProduct" />
        <click selector="{{StorefrontCategoryProductSection.ProductAddToCompareByName(productVar.name)}}" stepKey="clickAddProductToCompare"/>
        <waitForElement selector="{{StorefrontMessagesSection.success}}" time="30" stepKey="waitForAddCategoryProductToCompareSuccessMessage"/>
        <see selector="{{StorefrontMessagesSection.success}}" userInput="You added product {{productVar.name}} to the comparison list." stepKey="assertAddCategoryProductToCompareSuccessMessage"/>
    </actionGroup>

    <!-- Add Product to Compare from the product page and check message -->
    <actionGroup name="StorefrontAddProductToCompareActionGroup">
        <arguments>
            <argument name="productVar"/>
        </arguments>
        <click selector="{{StorefrontProductInfoMainSection.productAddToCompare}}" stepKey="clickAddToCompare" />
        <waitForElement selector="{{StorefrontMessagesSection.success}}" time="30" stepKey="waitForAddProductToCompareSuccessMessage"/>
        <see selector="{{StorefrontMessagesSection.success}}" userInput="You added product {{productVar.name}} to the comparison list." stepKey="assertAddProductToCompareSuccessMessage"/>
    </actionGroup>

    <!-- Check the product in compare sidebar -->
    <actionGroup name="StorefrontCheckCompareSidebarProductActionGroup">
        <arguments>
            <argument name="productVar"/>
        </arguments>
        <waitForElement selector="{{StorefrontComparisonSidebarSection.ProductTitleByName(productVar.name)}}" stepKey="waitForProduct"/>
    </actionGroup>

    <!-- Open and check comparison page -->
    <actionGroup name="StorefrontOpenAndCheckComparisionActionGroup">
        <click selector="{{StorefrontComparisonSidebarSection.Compare}}" stepKey="clickCompare"/>
        <waitForLoadingMaskToDisappear stepKey="waitForComparePageloaded" />
        <seeInCurrentUrl url="{{StorefrontProductComparePage.url}}" stepKey="checkUrl"/>
        <seeInTitle userInput="Products Comparison List" stepKey="assertPageNameInTitle"/>
        <see userInput="Compare Products" selector="{{StorefrontProductCompareMainSection.PageName}}" stepKey="assertPageName"/>
    </actionGroup>

    <!-- Check the simple product in comparison page -->
    <actionGroup name="StorefrontCheckCompareSimpleProductActionGroup">
        <arguments>
            <argument name="productVar"/>
        </arguments>
        <seeElement selector="{{StorefrontProductCompareMainSection.ProductLinkByName(productVar.name)}}" stepKey="assertProductName"/>
        <see userInput="${{productVar.price}}.00" selector="{{StorefrontProductCompareMainSection.ProductPriceByName(productVar.name)}}" stepKey="assertProductPrice1"/>
        <see userInput="{{productVar.sku}}" selector="{{StorefrontProductCompareMainSection.ProductAttributeByCodeAndProductName('SKU', productVar.name)}}" stepKey="assertProductPrice2"/>
        <!-- @TODO: MAGETWO-80272 Move to Magento_Checkout -->
        <seeElement selector="{{StorefrontProductCompareMainSection.ProductAddToCartByName(productVar.name)}}" stepKey="assertProductAddToCart"/>
    </actionGroup>

    <!-- Clear the compare list -->
    <actionGroup name="StorefrontClearCompareActionGroup">
        <waitForElementVisible selector="{{StorefrontComparisonSidebarSection.ClearAll}}" time="30" stepKey="waitForClearAll"/>
        <click selector="{{StorefrontComparisonSidebarSection.ClearAll}}" stepKey="clickClearAll"/>
        <waitForElementVisible selector="{{ModalConfirmationSection.OkButton}}" time="30" stepKey="waitForClearOk"/>
        <scrollTo selector="{{ModalConfirmationSection.OkButton}}" stepKey="scrollToClearOk"/>
        <click selector="{{ModalConfirmationSection.OkButton}}" stepKey="clickClearOk"/>
        <waitForElement selector="{{StorefrontMessagesSection.message('You cleared the comparison list.')}}" time="30" stepKey="AssertMessageCleared"/>
        <waitForElement selector="{{StorefrontComparisonSidebarSection.NoItemsMessage}}" time="30" stepKey="assertNoItems"/>
    </actionGroup>
</actionGroups>