<?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="DeleteDownloadableProductFromShoppingCartTest">
        <annotations>
            <features value="Checkout"/>
            <stories value="Delete Products from Shopping Cart"/>
            <title value="Delete downloadable product from shopping cart test"/>
            <description value="Delete downloadable product from shopping cart"/>
            <severity value="CRITICAL"/>
            <testCaseId value="MC-14693"/>
            <group value="checkout"/>
            <group value="mtf_migrated"/>
        </annotations>
        <before>
            <magentoCLI stepKey="addDownloadableDomain" command="downloadable:domains:add static.magento.com"/>
            <!-- Create downloadable product -->
            <createData entity="ApiDownloadableProduct" stepKey="createDownloadableProduct"/>
            <createData entity="ApiDownloadableLink" stepKey="addDownloadableLink">
                <requiredEntity createDataKey="createDownloadableProduct"/>
            </createData>
            <createData entity="ApiDownloadableLink" stepKey="addDownloadableLink1">
                <requiredEntity createDataKey="createDownloadableProduct"/>
            </createData>
        </before>
        <after>
            <magentoCLI stepKey="removeDownloadableDomain" command="downloadable:domains:remove static.magento.com"/>
            <!-- Delete downloadable product -->
            <deleteData createDataKey="createDownloadableProduct" stepKey="deleteDownloadableProduct"/>
        </after>

        <!-- Add downloadable product to the cart -->
        <amOnPage url="{{StorefrontProductPage.url($$createDownloadableProduct.custom_attributes[url_key]$$)}}" stepKey="navigateToDownloadableProductPage"/>
        <waitForPageLoad stepKey="waitForDownloadableProductPageLoad"/>
        <actionGroup ref="AddToCartFromStorefrontProductPageActionGroup" stepKey="addToCartDownloadableProductFromStorefrontProductPage">
            <argument name="productName" value="$$createDownloadableProduct.name$$"/>
        </actionGroup>

        <!-- Remove product from cart -->
        <actionGroup ref="StorefrontCartPageOpenActionGroup" stepKey="goToCart"/>
        <actionGroup ref="DeleteProductFromShoppingCartActionGroup" stepKey="deleteProduct">
            <argument name="productName" value="$$createDownloadableProduct.name$$"/>
        </actionGroup>
    </test>
</tests>
