/*******************************
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

/**
 * Selects the element whose [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types) and accessible [name](https://russmaxdesign.github.io/html-elements-names/) are specified <br />⚠ remember to deselect the element with <b>[I reset context](#i-reset-context)</b> if you're no longer acting on it
 * */
When(`within a structure named {string}`, async function(name: string) {
  return await withinRoleAndName(this, "structure", name);
});

/**
 * Checks that an Html element exists with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types) and [name](https://russmaxdesign.github.io/html-elements-names/)
 * */
Then(`I should see a structure named {string}`, async function(name: string) {
  await findWithRoleAndName(this, "structure", name);
});

/**
 * Checks that an Html element does not exists with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types) and [name](https://russmaxdesign.github.io/html-elements-names/)
 * */
Then(
 `I should not see a structure named {string}`,
 async function(name: string) {
   await notFoundWithRoleAndName(this, "structure", name);
 }
);

// End of General Section

// Begin of Type Section

/**
 * Writes the sentence given as a parameter inside the specified field (useful for example to fill in a form field)
 * */
When(`I type the sentence {string} in the structure named {string}`, async function(textToType: string, name: string) {
  await type(this, "structure", name, textToType);
});

/**
 * Writes the sentence given as a parameter inside the specified field (useful for example to fill in a form field)
 * */
When(`I enter the value {string} in the structure named {string}`, async function(textToType: string, name: string) {
    await type(this, "structure", name, textToType);
});

/**
 * key.then.element.withRoleAndNameAndValue
 * */
When(`I should see a structure named {string} with value {string}`, async function(name: string, expectedValue: string) {
    await findWithRoleAndNameAndValue(this, "structure", name, expectedValue);
    await deleteCookieByName(this, COOKIE_NAME.SELECTED_ELEMENT);
});

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

/**
 * Checks that an Html element exists with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types), [name](https://russmaxdesign.github.io/html-elements-names/) and content
 * */
Then(
 `I should see a structure named {string} and containing {string}`,
 async function(name: string, expectedTextContent: string) {
   await findWithRoleAndNameAndContent(this, "structure", name, expectedTextContent);
 }
);

/**
 * Checks that an Html element exists with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types), [name](https://russmaxdesign.github.io/html-elements-names/) and content, and with the disabled attribute set to true
 * */
Then(
 `I should see a structure named {string} and containing {string} disabled`,
 async function(name: string, expectedTextContent: string) {
   await findWithRoleAndNameAndContentDisabled(this, "structure", name, expectedTextContent);
 }
);

/**
 * Checks that an Html element exists with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types), [name](https://russmaxdesign.github.io/html-elements-names/), and with the disabled attribute set to true
 * */
Then(
    `I should see a structure named {string} disabled`,
    async function(name: string) {
        await findWithRoleAndNameDisabled(this, "structure", name);
    }
);

/**
 * Checks that an Html element exists with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types), [name](https://russmaxdesign.github.io/html-elements-names/) and content, and with the disabled attribute set to false
 * */
Then(
 `I should see a structure named {string} and containing {string} enabled`,
 async function(name: string, expectedTextContent: string) {
   await findWithRoleAndNameAndContentEnabled(this, "structure", name, expectedTextContent);
 }
);

/**
 * Checks that an Html element exists with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types), [name](https://russmaxdesign.github.io/html-elements-names/), and with the disabled attribute set to false
 * */
Then(
    `I should see a structure named {string} enabled`,
    async function(name: string) {
        await findWithRoleAndNameEnabled(this, "structure", name);
    }
);

// End of Content Section




