/*******************************
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 {
    click,
    COOKIE_NAME,
    deleteCookieByName,
    findWithRoleAndName,
    findWithRoleAndNameAndChecked,
    findWithRoleAndNameAndContent,
    findWithRoleAndNameAndContentDisabled,
    findWithRoleAndNameAndContentEnabled,
    findWithRoleAndNameAndUnchecked,
    findWithRoleAndNameDisabled,
    findWithRoleAndNameEnabled,
    findWithRoleAndNameFocused,
    notFoundWithRoleAndName,
    withinRoleAndName,
    type,
    findWithRoleAndNameAndValue
} from "../../../core-engine";
import { Then, When } from "../../../../../preprocessor/run/world";

// Begin of General Section

/**
 * Sélectionne l'élément ayant le rôle term 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 du terme nommé {string}`, async function(name: string) {
  return await withinRoleAndName(this, "term", name);
});

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

/**
 * Vérifie l'inexistence d'un élément Html ayant le rôle term et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) spécifiés
 * */
Then(
 `je ne dois pas voir un terme nommé {string}`,
 async function(name: string) {
   await notFoundWithRoleAndName(this, "term", 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 le terme nommé {string}`, async function(textToType: string, name: string) {
  await type(this, "term", name, 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 le terme nommé {string}`, async function(textToType: string, name: string) {
    await type(this, "term", name, textToType);
});

/**
 * key.then.element.withRoleAndNameAndValue
 * */
When(`je dois voir un terme nommé {string} avec la valeur {string}`, async function(name: string, expectedValue: string) {
    await findWithRoleAndNameAndValue(this, "term", name, expectedValue);
    await deleteCookieByName(this, COOKIE_NAME.SELECTED_ELEMENT);
});

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

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

/**
 * Vérifie l'existence d'un élément Html ayant le rôle term, 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 un terme nommé {string} et contenant {string} désactivé`,
 async function(name: string, expectedTextContent: string) {
   await findWithRoleAndNameAndContentDisabled(this, "term", name, expectedTextContent);
 }
);

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

/**
 * Vérifie l'existence d'un élément Html ayant le rôle term, 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 un terme nommé {string} et contenant {string} activé`,
 async function(name: string, expectedTextContent: string) {
   await findWithRoleAndNameAndContentEnabled(this, "term", name, expectedTextContent);
 }
);

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

// End of Content Section




