/*******************************
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 spinbutton 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 bouton rotatif nommé {string}`, async function(name: string) {
  return await withinRoleAndName(this, "spinbutton", name);
});

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

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

/**
 * key.then.element.withRoleAndNameAndValue
 * */
When(`je dois voir un bouton rotatif nommé {string} avec la valeur {string}`, async function(name: string, expectedValue: string) {
    await findWithRoleAndNameAndValue(this, "spinbutton", 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 spinbutton, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) et le contenu spécifiés
 * */
Then(
 `je dois voir un bouton rotatif nommé {string} et contenant {string}`,
 async function(name: string, expectedTextContent: string) {
   await findWithRoleAndNameAndContent(this, "spinbutton", name, expectedTextContent);
 }
);

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

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

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

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

// End of Content Section

// Begin of Keyboard Section

/**
 * Vérifie que l'élément Html avec le [rôle accessible](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types) et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) a le focus clavier<br/><a target='_blank' href='https://github.com/e2e-test-quest/uuv/blob/main/example/fr-keyboard.feature'>Exemples</a>
 * */
Then(
 `je dois voir un bouton rotatif nommé {string} avoir le focus clavier`,
 async function(name: string) {
   await findWithRoleAndNameFocused(this, "spinbutton", name);
 }
);

/**
 * Se déplace au précédent élément HTML atteignable avec la tabulation et vérifie que l'élément Html avec le [rôle accessible](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types) et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) a le focus clavier<br/><a target='_blank' href='https://github.com/e2e-test-quest/uuv/blob/main/example/fr-keyboard.feature'>Exemples</a>
 * */
Then(
 `le précédent élément avec le focus clavier doit être un bouton rotatif nommé {string}`,
 async function(name: string) {
   await this.page.keyboard.press("ShiftLeft+Tab");
   await findWithRoleAndNameFocused(this, "spinbutton", name);
 }
);

/**
 * Se déplace au prochain élément HTML atteignable avec la tabulation et vérifie que l'élément Html avec le [rôle accessible](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types) et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) a le focus clavier<br/><a target='_blank' href='https://github.com/e2e-test-quest/uuv/blob/main/example/fr-keyboard.feature'>Exemples</a>
 * */
Then(
 `le prochain élément avec le focus clavier doit être un bouton rotatif nommé {string}`,
 async function(name: string) {
   await this.page.keyboard.press("Tab");
   await findWithRoleAndNameFocused(this, "spinbutton", name);
 }
);
// End of Keyboard Section


