<?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">
    <actionGroup name="setColorPickerByHex">
        <arguments>
            <argument name="nthColorPicker" type="string" defaultValue="1"/>
            <argument name="hexColor" type="string" defaultValue="e74c3c"/>
        </arguments>
        <!-- This 6x backspace stuff is some magic that is necessary to interact with this field correctly -->
        <pressKey selector="{{AdminColorPickerSection.hexByIndex(nthColorPicker)}}" parameterArray="[\Facebook\WebDriver\WebDriverKeys::BACKSPACE,\Facebook\WebDriver\WebDriverKeys::BACKSPACE,\Facebook\WebDriver\WebDriverKeys::BACKSPACE,\Facebook\WebDriver\WebDriverKeys::BACKSPACE,\Facebook\WebDriver\WebDriverKeys::BACKSPACE,\Facebook\WebDriver\WebDriverKeys::BACKSPACE,'{{hexColor}}']" stepKey="fillHex1"/>
        <click selector="{{AdminColorPickerSection.submitByIndex(nthColorPicker)}}" stepKey="submitColor1"/>
    </actionGroup>
    <actionGroup name="assertSwatchColor">
        <arguments>
            <argument name="nthSwatch" type="string" defaultValue="1"/>
            <argument name="expectedStyle" type="string" defaultValue="background: rgb(0, 0, 0);"/>
        </arguments>
        <grabAttributeFrom selector="{{AdminManageSwatchSection.nthSwatch(nthSwatch)}}" userInput="style" stepKey="grabStyle1"/>
        <assertEquals stepKey="assertStyle1">
            <actualResult type="string">{$grabStyle1}</actualResult>
            <expectedResult type="string">{{expectedStyle}}</expectedResult>
        </assertEquals>
    </actionGroup>
    <actionGroup name="assertStorefrontSwatchColor">
        <arguments>
            <argument name="nthSwatch" type="string" defaultValue="1"/>
            <argument name="expectedRgb" type="string" defaultValue="rgb(231, 77, 60)"/>
        </arguments>
        <grabAttributeFrom selector="{{StorefrontProductInfoMainSection.nthSwatchOption(nthSwatch)}}" userInput="style" stepKey="grabStyle1"/>
        <assertEquals stepKey="assertStyle1">
            <actualResult type="string">{$grabStyle1}</actualResult>
            <expectedResult type="string">background: center center no-repeat {{expectedRgb}};</expectedResult>
        </assertEquals>
    </actionGroup>
    <actionGroup name="openSwatchMenuByIndex">
        <arguments>
            <argument name="index" type="string" defaultValue="0"/>
        </arguments>
        <!-- I had to use executeJS to perform the click to get around the use of CSS ::before and ::after -->
        <executeJS function="jQuery('#swatch_window_option_option_{{index}}').click()" stepKey="clickSwatch1"/>
    </actionGroup>
</actionGroups>