/*******************************
NE PAS MODIFIER, FICHIER GENERE
*******************************/

/**
 * Software Name : UUV
 *
 * SPDX-License-Identifier: MIT
 *
 * This software is distributed under the MIT License,
 * see the "LICENSE" file for more details
 *
 * Authors: NJAKO MOLOM Louis Fredice & SERVICAL Stanley
 * Software description: Make test writing fast, understandable by any human
 * understanding English or French.
 */

import { Then, When, } from "@badeball/cypress-cucumber-preprocessor";
import "../../../../../../cypress/commands";
import {
    click,
    findWithRoleAndName,
    findWithRoleAndNameAndAttribute,
    findWithRoleAndNameAndContent,
    findWithRoleAndNameAndContentDisabled,
    findWithRoleAndNameAndContentEnabled,
    findWithRoleAndNameDisabled,
    findWithRoleAndNameEnabled,
    findWithRoleAndNameFocused,
    notFoundWithRoleAndName,
    withinRoleAndName
} from "../../../core-engine";

import { pressKey } from "../../../_.common";

// Begin of General Section

/**
 * Sélectionne l'élément ayant le rôle command et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) sont spécifiés <br />⚠ pensez à déselectionner l'élement avec <b>[je reinitialise le contexte](#je-reinitialise-le-contexte)</b> si vous n'agissez plus dessus
 * */
When(`je vais à l'intérieur de la commande nommée {string}`, function(name: string) {
    withinRoleAndName("command", name);
});

/**
 * Vérifie l'existence d'un élément Html ayant le rôle command et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) spécifiés
 * */
Then(`je dois voir une commande nommée {string}`, function(name: string) {
    findWithRoleAndName("command", name);
});

/**
 * Vérifie l'inexistence d'un élément Html ayant le rôle command et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) spécifiés
 * */
Then(
    `je ne dois pas voir une commande nommée {string}`,
    function(name: string) {
        notFoundWithRoleAndName("command", name);
    }
);

// End of General Section

// Begin of Type Section

/**
 * Saisie de la phrase passée en paramètre dans le champ spécifié (utile par exemple pour remplir un champ de formulaire).
 * */
When(`je saisie le(s) mot(s) {string} dans la commande nommée {string}`, function(textToType: string, name: string) {
    cy.uuvFindByRole("command", { name: name }).uuvFoundedElement().type(textToType);
});

/**
 * Saisie de la phrase passée en paramètre dans le champ spécifié (utile par exemple pour remplir un champ de formulaire).
 * */
When(`j'entre la valeur {string} dans la commande nommée {string}`, function(textToType: string, name: string) {
    cy.uuvFindByRole("command", { name: name }).uuvFoundedElement().type(textToType);
});

/**
 * Vérifie l'existence d'un élément de formulaire (input) ayant le rôle command, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) et la valeur spécifiée
 * */
Then(
    `je dois voir une commande nommée {string} avec la valeur {string}`,
    function(name: string, expectedValue: string) {
        cy.uuvFindByRole("command", { name: name })
            .uuvFoundedElement()
            .should("exist")
            .should("have.value", expectedValue);
    }
);

// End of Type Section
// Begin of Content Section

/**
 * Vérifie l'existence d'un élément Html ayant le rôle command, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) et le contenu spécifiés
 * */
Then(
    `je dois voir une commande nommée {string} et contenant {string}`,
    function(name: string, expectedTextContent: string) {
        findWithRoleAndNameAndContent("command", name, expectedTextContent);
    }
);

/**
 * Vérifie l'existence d'un élément Html ayant le rôle command, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/), le contenu spécifiés et avec l'attribut disabled à false
 * */
Then(
    `je dois voir une commande nommée {string} et contenant {string} désactivé`,
    function(name: string, expectedTextContent: string) {
        findWithRoleAndNameAndContentDisabled("command", name, expectedTextContent);
    }
);

/**
 * Vérifie l'existence d'un élément Html ayant le rôle command, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/), le contenu spécifiés et avec l'attribut disabled à true
 * */
Then(
    `je dois voir une commande nommée {string} et contenant {string} activé`,
    function(name: string, expectedTextContent: string) {
        findWithRoleAndNameAndContentEnabled("command", name, expectedTextContent);
    }
);

/**
 * Vérifie l'existence d'un élément Html ayant le rôle command, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) et avec l'attribut disabled à false
 * */
Then(
    `je dois voir une commande nommée {string} désactivé`,
    function(name: string) {
        findWithRoleAndNameDisabled("command", name);
    }
);

/**
 * Vérifie l'existence d'un élément Html ayant le rôle command, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) et avec l'attribut disabled à true
 * */
Then(
    `je dois voir une commande nommée {string} activé`,
    function(name: string) {
        findWithRoleAndNameEnabled("command", name);
    }
);

// End of Content Section




