<?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 Bundle Product to Cart from the category page with specified quantity to cart -->
    <actionGroup name="StorefrontAddCategoryBundleProductToCartActionGroup">
        <arguments>
            <argument name="product"/>
            <argument name="quantity" defaultValue="1" type="string"/>
        </arguments>
        <moveMouseOver selector="{{StorefrontCategoryProductSection.ProductInfoByName(product.name)}}" stepKey="moveMouseOverProduct" />
        <click selector="{{StorefrontCategoryProductSection.ProductAddToCartByName(product.name)}}" stepKey="clickAddToCart" />
        <waitForPageLoad time="30" stepKey="waitForPageLoad1"/>
        <click selector="{{StorefrontBundleProductActionSection.customizeAndAddToCartButton}}" stepKey="clickCustomizeAndAddToCart"/>
        <waitForPageLoad time="30" stepKey="waitForPageLoad2"/>
        <fillField selector="{{StorefrontBundleProductActionSection.quantityField}}" userInput="{{quantity}}" stepKey="fillBundleProductQuantity"/>
        <click selector="{{StorefrontBundleProductActionSection.addToCartButton}}" stepKey="clickAddBundleProductToCart"/>
        <waitForPageLoad time="30" stepKey="waitForPageLoad3"/>
        <waitForText userInput="{{quantity}}" selector="{{StorefrontMinicartSection.productCount}}" time="30" stepKey="assertProductCount"/>
    </actionGroup>

    <!-- Add Bundle Product to Cart from the category page -->
    <actionGroup name="StorefrontAddBundleProductFromCategoryToCartActionGroup">
        <arguments>
            <argument name="productName" type="string"/>
        </arguments>
        <moveMouseOver selector="{{StorefrontCategoryProductSection.ProductTitleByName(productName)}}" stepKey="moveMouseOverProduct"/>
        <click selector="{{StorefrontCategoryProductSection.ProductTitleByName(productName)}}" stepKey="openProductPage"/>
        <waitForPageLoad time="30" stepKey="waitForBundleProductPageLoad"/>
        <click selector="{{StorefrontBundledSection.addToCart}}" stepKey="clickCustomizeAndAddToCart"/>
        <click selector="{{StorefrontBundledSection.addToCartConfigured}}" stepKey="clickAddBundleProductToCart"/>
        <waitForElementVisible selector="{{StorefrontMinicartSection.productCount}}" stepKey="waitProductCount"/>
        <see userInput="You added {{productName}} to your shopping cart." selector="{{StorefrontMessagesSection.success}}" stepKey="seeSuccessMessage"/>
    </actionGroup>

    <!-- Add Bundle Product to Cart from product Page-->
    <actionGroup name="StorefrontAddBundleProductFromProductToCartActionGroup">
        <arguments>
            <argument name="productName" type="string"/>
        </arguments>
        <click selector="{{StorefrontBundledSection.addToCart}}" stepKey="clickCustomizeAndAddToCart"/>
        <click selector="{{StorefrontBundledSection.addToCartConfigured}}" stepKey="clickAddBundleProductToCart"/>
        <waitForElementVisible selector="{{StorefrontMinicartSection.productCount}}" stepKey="waitProductCount"/>
        <see userInput="You added {{productName}} to your shopping cart." selector="{{StorefrontMessagesSection.success}}" stepKey="seeSuccessMessage"/>
    </actionGroup>

    <!-- Add Bundled Product to Cart with selected multiselect option-->
    <actionGroup name="StorefrontAddBundleProductFromProductToCartWithMultiOption" extends="StorefrontAddBundleProductFromProductToCartActionGroup">
        <arguments>
            <argument name="optionName" type="string"/>
            <argument name="value" type="string"/>
        </arguments>
        <selectOption selector="{{StorefrontBundledSection.multiselectOptionFourProducts(optionName)}}" userInput="{{value}}" stepKey="selectValue" before="clickAddBundleProductToCart"/>
    </actionGroup>
</actionGroups>
