<?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="AdminFillCredentialsActionGroup">
        <annotations>
            <description>Payments configuration page</description>
        </annotations>
        <magentoCLI command="config:set services_connector/services_connector_integration/sandbox_api_key ''" stepKey="clearPublicAPIKey" />
        <magentoCLI command="config:set services_connector/services_connector_integration/sandbox_private_key ''" stepKey="clearPrivateAPIKey" />
        <magentoCLI command="config:set services_connector/services_connector_integration/production_api_key ''" stepKey="clearProductionPublicAPIKey" />
        <magentoCLI command="config:set services_connector/services_connector_integration/production_private_key ''" stepKey="clearProductionPrivateAPIKey" />
        <magentoCLI command="config:set services_connector/services_id/project_id ''" stepKey="clearServicesIdProjectId" />
        <amOnPage url="{{AdminServicesConnectorSettingsPage.url}}" stepKey="navigateToServicesConnectorSettingsPage"/>
        <waitForPageLoad stepKey="waitForPagePageLoad"/>
        <conditionalClick selector="{{AdminServicesConnectorSettingsSection.setupStartButton}}" dependentSelector="{{AdminServicesConnectorSettingsSection.setupContainer}}" visible="true" stepKey="startSaasSetup" />
        <executeJS function='var el = document.createElement("input"); el.id = "test"; document.querySelector("{{AdminServicesConnectorSettingsSection.sandboxEnvironmentPrivateKey}}").after(el);' stepKey="createTmpFieldForSandboxPrivateKey" />
        <fillField selector="{{AdminServicesConnectorSettingsSection.sandboxEnvironmentApiKey}}" userInput="{{_CREDS.magento/magento_payments_sandbox_environment_api_key}}" stepKey="fillSandboxEnvironmentApiKey" />
        <fillField selector="#test" userInput="{{_CREDS.magento/magento_payments_sandbox_environment_private_key}}" stepKey="fillSandboxEnvironmentPrivateKeyForTMpField" />
        <executeJS function='return atob(document.querySelector("#test").value)' stepKey="fillSandboxEnvironmentPrivateKeyEncoded" />
        <fillField selector="{{AdminServicesConnectorSettingsSection.sandboxEnvironmentPrivateKey}}" userInput="{$fillSandboxEnvironmentPrivateKeyEncoded}" stepKey="fillSandboxEnvironmentPrivateKey" />
        <click selector="{{AdminServicesConnectorSettingsSection.sandboxSetupNextButton}}" stepKey="proceedToProductionSetup" />
        <waitForElementVisible selector="{{AdminServicesConnectorSettingsSection.productionEnvironmentPrivateKey}}" stepKey="waitForProductionSectionToLoad" />
        <executeJS function='var el = document.createElement("input"); el.id = "test"; document.querySelector("{{AdminServicesConnectorSettingsSection.productionEnvironmentPrivateKey}}").after(el);' stepKey="createTmpFieldForProductionPrivateKey" />
        <fillField selector="{{AdminServicesConnectorSettingsSection.productionEnvironmentApiKey}}" userInput="{{_CREDS.magento/magento_payments_production_environment_api_key}}" stepKey="fillProductionEnvironmentApiKey" />
        <fillField selector="#test" userInput="{{_CREDS.magento/magento_payments_production_environment_private_key}}" stepKey="fillProductionEnvironmentPrivateKeyForTMpField" />
        <executeJS function='return atob(document.querySelector("#test").value)' stepKey="fillProductionEnvironmentPrivateKeyEncoded" />
        <fillField selector="{{AdminServicesConnectorSettingsSection.productionEnvironmentPrivateKey}}" userInput="{$fillProductionEnvironmentPrivateKeyEncoded}" stepKey="fillProductionEnvironmentPrivateKey" />
        <click selector="{{AdminServicesConnectorSettingsSection.productionSetupNextButton}}" stepKey="proceedToSaasIdentifierSetup" />
        <waitForElementVisible selector="{{AdminServicesIdSettingsSection.saasDataSpace}}" stepKey="waitForDataSpaceToLoad" />
        <click selector="{{AdminServicesIdSettingsSection.saasDataSpace}}" stepKey="openDataSpaceOptions" />
        <conditionalClick selector="{{AdminServicesIdSettingsSection.saasDataSpaceValue}}" dependentSelector="{{AdminServicesIdSettingsSection.saasDataSpace}}" visible="true" stepKey="fillDataSpace" />
        <click selector="{{AdminServicesConnectorSettingsSection.productionSetupNextButton}}" stepKey="saveSaasSettings" />
        <waitForPageLoad stepKey="waitForPagePageLoad4"/>
    </actionGroup>
</actionGroups>
