/*******************************
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,
  findWithRoleAndNameAndContentDisable,
  findWithRoleAndNameAndContentEnable,
  findWithRoleAndNameAndUnchecked,
  findWithRoleAndNameFocused,
  getPageOrElement,
  getTimeout,
  notFoundWithRoleAndName,
  withinRoleAndName
} from "../../../core-engine";
import { Then, When } from "../../../../../preprocessor/run/world";
import { expect } from "@playwright/test";

// Begin of General Section

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

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

/**
 * Vérifie l'inexistence d'un élément Html ayant le rôle complementary et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) spécifiés
 * */
Then(
 `je ne dois pas voir un complémentaire nommé {string}`,
 async function(name: string) {
   await notFoundWithRoleAndName(this, "complementary", 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 complémentaire nommé {string}`, async function(textToType: string, name: string) {
  await getPageOrElement(this).then(async (element) => {
    const byRole = await element.getByRole("complementary", { name: name, exact: true });
    await expect(byRole).toHaveCount(1, { timeout: await getTimeout(this) });
    await byRole.type(textToType);
    await deleteCookieByName(this, COOKIE_NAME.SELECTED_ELEMENT);
  });
});

/**
 * 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 complémentaire nommé {string}`, async function(textToType: string, name: string) {
    await getPageOrElement(this).then(async (element) => {
        const byRole = await element.getByRole("complementary", { name: name, exact: true });
        await expect(byRole).toHaveCount(1);
        await byRole.type(textToType);
        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 complementary, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) et le contenu spécifiés
 * */
Then(
 `je dois voir un complémentaire nommé {string} et contenant {string}`,
 async function(name: string, expectedTextContent: string) {
   await findWithRoleAndNameAndContent(this, "complementary", name, expectedTextContent);
 }
);

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

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

// End of Content Section




