<?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="AdminCancelOrderWithBundleProductDefaultStockTest" extends="AdminCreateOrderWithBundleProductDefaultStockTest">
        <annotations>
            <stories value="Bundle product Default Stock."/>
            <title value="Cancel order with bundle product on default stock."/>
            <description value="Verify admin able to cancel order with bundle product on default stock from admin area."/>
            <testCaseId value="https://app.hiptest.com/projects/69435/test-plan/folders/735226/scenarios/1698409"/>
            <severity value="CRITICAL"/>
            <group value="msi"/>
            <group value="multi_mode"/>
        </annotations>

        <!--Get order Id.-->
        <grabTextFrom selector="|Order # (\d+)|" stepKey="orderId" after="clickSubmitOrder" />
        <!--Cancel order.-->
        <actionGroup ref="OpenOrderByIdActionGroup" stepKey="openOrder" after="checkSimpleProductSalableQtyAfterPlaceOrder">
            <argument name="orderId" value="{$orderId}"/>
        </actionGroup>
        <click selector="{{AdminOrderDetailsMainActionsSection.cancel}}" stepKey="clickCancelOrder"/>
        <waitForElement selector="{{AdminConfirmationModalSection.message}}" stepKey="waitForCancelConfirmation"/>
        <see selector="{{AdminConfirmationModalSection.message}}" userInput="Are you sure you want to cancel this order?" stepKey="seeConfirmationMessage"/>
        <click selector="{{AdminConfirmationModalSection.ok}}" stepKey="confirmOrderCancel"/>
        <see selector="{{AdminMessagesSection.success}}" userInput="You canceled the order." stepKey="seeCancelSuccessMessage"/>
        <!--Verify product quantity after order cancellation.-->
        <amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductGrid"/>
        <actionGroup ref="AdminGridFilterSearchResultsByInput" stepKey="findProduct">
            <argument name="selector" value="AdminProductGridFilterSection.skuFilter"/>
            <argument name="value" value="$$simpleProduct.sku$$"/>
        </actionGroup>
        <see selector="{{AdminProductGridSection.productQtyPerSource('1',_defaultSource.name)}}" userInput="1000" stepKey="verifySourceQuantity"/>
        <see selector="{{AdminProductGridSection.productSalableQty('1',_defaultStock.name)}}" userInput="1000" stepKey="verifyStockQuantity"/>
    </test>
</tests>
