<?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 video in Admin Product page -->
    <actionGroup name="addProductVideo">
        <annotations>
            <description>Expands the 'Images And Videos' section on the Admin Product creation/edit page. Adds the provided Video to the Product. Clicks on Save.</description>
        </annotations>
        <arguments>
            <argument name="video" defaultValue="mftfTestProductVideo"/>
        </arguments>

        <scrollTo selector="{{AdminProductImagesSection.productImagesToggle}}" x="0" y="-100" stepKey="scrollToArea"/>
        <conditionalClick selector="{{AdminProductImagesSection.productImagesToggle}}" dependentSelector="{{AdminProductImagesSection.imageUploadButton}}" visible="false" stepKey="openProductVideoSection"/>
        <waitForElementVisible selector="{{AdminProductImagesSection.addVideoButton}}" stepKey="waitForAddVideoButtonVisible" time="30"/>
        <click selector="{{AdminProductImagesSection.addVideoButton}}" stepKey="addVideo"/>
        <waitForElementVisible selector=".modal-slide.mage-new-video-dialog.form-inline._show" stepKey="waitForUrlElementVisibleslide" time="30"/>
        <waitForElementVisible selector="{{AdminProductNewVideoSection.videoUrlTextField}}" stepKey="waitForUrlElementVisible" time="60"/>
        <fillField selector="{{AdminProductNewVideoSection.videoUrlTextField}}" userInput="{{video.videoUrl}}" stepKey="fillFieldVideoUrl"/>
        <fillField selector="{{AdminProductNewVideoSection.videoTitleTextField}}" userInput="{{video.videoTitle}}" stepKey="fillFieldVideoTitle"/>
        <waitForPageLoad stepKey="waitForPageLoad"/>
        <waitForElementNotVisible selector="{{AdminProductNewVideoSection.saveButtonDisabled}}" stepKey="waitForSaveButtonVisible" time="30"/>
        <click selector="{{AdminProductNewVideoSection.saveButton}}" stepKey="saveVideo"/>
        <waitForLoadingMaskToDisappear stepKey="waitForLoadingMaskToDisappear"/>
    </actionGroup>

    <!-- Remove video in Admin Product page -->
    <actionGroup name="removeProductVideo">
        <annotations>
            <description>Expands the 'Images And Videos' section on the Admin Product creation/edit page. Clicks on the Remove Video button.</description>
        </annotations>

        <scrollTo selector="{{AdminProductImagesSection.productImagesToggle}}" x="0" y="-100" stepKey="scrollToArea"/>
        <conditionalClick selector="{{AdminProductImagesSection.productImagesToggle}}" dependentSelector="{{AdminProductImagesSection.imageUploadButton}}" visible="false" stepKey="openProductVideoSection"/>
        <waitForElementVisible selector="{{AdminProductImagesSection.addVideoButton}}" stepKey="waitForAddVideoButtonVisible" time="30"/>
        <click selector="{{AdminProductImagesSection.removeVideoButton}}" stepKey="removeVideo"/>
    </actionGroup>

    <!-- Assert product video in Admin Product page -->
    <actionGroup name="assertProductVideoAdminProductPage">
        <annotations>
            <description>Validates that the provided Video is present on the Admin Product creation/edit page.</description>
        </annotations>
        <arguments>
            <argument name="video" defaultValue="mftfTestProductVideo"/>
        </arguments>

        <scrollTo selector="{{AdminProductImagesSection.productImagesToggle}}" x="0" y="-100" stepKey="scrollToArea"/>
        <conditionalClick selector="{{AdminProductImagesSection.productImagesToggle}}" dependentSelector="{{AdminProductImagesSection.imageUploadButton}}" visible="false" stepKey="openProductVideoSection"/>
        <waitForPageLoad stepKey="waitForPageLoad"/>
        <seeElement selector="{{AdminProductImagesSection.videoTitleText(video.videoShortTitle)}}" stepKey="seeVideoTitle"/>
        <seeElementInDOM selector="{{AdminProductImagesSection.videoUrlHiddenField(video.videoUrl)}}" stepKey="seeVideoItem"/>
    </actionGroup>

    <!-- Assert product video not in Admin Product page -->
    <actionGroup name="assertProductVideoNotInAdminProductPage">
        <annotations>
            <description>Validates that the provided Video is NOT present on the Admin Product creation/edit page.</description>
        </annotations>
        <arguments>
            <argument name="video" defaultValue="mftfTestProductVideo"/>
        </arguments>

        <scrollTo selector="{{AdminProductImagesSection.productImagesToggle}}" x="0" y="-100" stepKey="scrollToArea"/>
        <conditionalClick selector="{{AdminProductImagesSection.productImagesToggle}}" dependentSelector="{{AdminProductImagesSection.imageUploadButton}}" visible="false" stepKey="openProductVideoSection"/>
        <waitForPageLoad stepKey="waitForPageLoad"/>
        <dontSeeElement selector="{{AdminProductImagesSection.videoTitleText(video.videoShortTitle)}}" stepKey="seeVideoTitle"/>
        <dontSeeElementInDOM selector="{{AdminProductImagesSection.videoUrlHiddenField(video.videoUrl)}}" stepKey="seeVideoItem"/>
    </actionGroup>
</actionGroups>
