import Routing from '../../../pages/eui/14x/routing.js'
import EuiInputTextPage from '../../../pages/eui/14x/eui-input-text.po.js'
import * as CookieBannerActions from '../../../actions/cookieBanner.js';
import BaseActions from '../../../actions/V14/base-actions.js';

describe('eUI - <eui-input-text> Component Object ', async () => {
  let page = new EuiInputTextPage();
  let testFolder = './/v14x//eui-input-text//';
  let pageName = 'euiInputText'
  it('should navigate to <eui-input-text> demo page', async () => {
    browser.addTestMeta({ uuid: "254ce09b-44a1-4a01-b869-3d07bd6a44f1", zephyrKey: "CCQA-1829", zephyrStep: "447056", reportGroups: ["eUI.14x.eui"] });
    await page.open(Routing.getEUIDirectivesUrl('eui-input-text'));
    await CookieBannerActions.cookieBanner(true);
    await BaseActions.verifyPageTitle(pageName);
    await expect(await $(page.navigationList)).toBeDisplayed({ wait: 2000, message: 'Navigation List -> is not displayed on page' });
  });
  it('should verify the presence and number of component objects <eui-input-text> on page ', async () => {
    browser.addTestMeta({ zephyrStep: "447057" });
    let sectionId = 'Default';
    await BaseActions.verifySection(sectionId, pageName);
    let inputText = page.inputTextFromSectionById(sectionId).byIndex(3);
    await expect(await (await inputText.element())).toExist({ message: 'inputText from default section is not existing on page' });
    await expect(await (await inputText.element())).toBeDisplayedInViewport({ wait: 2000, message: 'inputText from default section is not displayed on page' });

    await chaiExpect(await page.euiInputTextCo.defaultComponentsCount()).equal(18, 'There should be 18 <eui-input-text> components on the page.');

    if (browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(await (await page.euiInputTextCo.element()), testFolder + 'img_defaultInputText',
        { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for img_defaultInputText');
    }
  });
  it('should verify the <eui-input-text> Max Length ', async () => {
    browser.addTestMeta({ zephyrStep: "447058" });
    let sectionId = 'Default';
    await BaseActions.verifySection(sectionId, pageName);
    let inputText3 = page.inputTextFromSectionById(sectionId).byIndex(3);

    await expect(await (await inputText3.element())).toExist({ wait: 2000, message: '<eui-input-text> is not existing on page' });
    await expect(await (await inputText3.element())).toBeDisplayedInViewport({ wait: 2000, message: 'inputText from default section is not displayed on page' });

    await chaiExpect(await inputText3.hasMaxLenght()).equal(true, 'Input Text should have max lenght');

    await chaiExpect(await inputText3.maxLenght()).equal('50', 'Input Text max lenght is not as expected');
    await expect(await $(await inputText3.maxLenghtIndicator())).toHaveTextContaining('33', 'Characters remaining before the limit is reached should be 33');
    await (await inputText3.element()).click();
    await (await inputText3.element()).setValue('test');
    await expect(await $(await inputText3.maxLenghtIndicator())).toHaveTextContaining('46', 'Characters remaining before the limit is reached should be 46');

    if (browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(await (await page.euiInputTextCo.element()), testFolder + 'img_maxLengthInputText',
        { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for img_maxLengthInputText');
      await chaiExpect(await browser.checkElement(await $(await inputText3.maxLenghtIndicator()), testFolder + 'img_maxLength',
        { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for img_maxLength');
    }
  });
  it('should verify the <eui-input-text> readonly ', async () => {
    browser.addTestMeta({ zephyrStep: "447059" });
    let sectionId = 'readonly';
    await BaseActions.verifySection(sectionId, pageName);

    let inputText = page.inputTextFromSectionById(sectionId).byIndex(1);
    await expect(await (await inputText.element())).toExist({ wait: 2000, message: '<eui-input-text> is not existing on page' });
    await expect(await (await inputText.element())).toBeDisplayedInViewport({ wait: 2000, message: 'inputText from readonly section is not displayed on page' });
    await chaiExpect(await inputText.isReadOnly()).equal(true, 'Input text should be read only');

    if (browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(await (await page.euiInputTextCo.element()), testFolder + 'img_readOnlyInputText',
        { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for img_readOnlyInputText');
    }

    inputText = page.inputTextFromSectionById('Default').byIndex(1);
    await chaiExpect(await inputText.isReadOnly()).equal(false, 'Input text should NOT be read only');
  });
  it('should verify the <eui-input-text> disabled ', async () => {
    browser.addTestMeta({ zephyrStep: "447060" });
    let sectionId = 'disabled';
    await BaseActions.verifySection(sectionId, pageName);

    let inputText = page.inputTextFromSectionById(sectionId).byIndex(1);
    await expect(await (await inputText.element())).toExist({ wait: 2000, message: '<eui-input-text> is not existing on page' });
    await expect(await (await inputText.element())).toBeDisplayedInViewport({ wait: 2000, message: 'inputText from disabled section is not displayed on page' });
    await chaiExpect(await inputText.isDisabled()).equal(true, 'Input Text should be disabled');

    if (browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(await (await page.euiInputTextCo.element()), testFolder + 'img_disabledInputText',
        { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for img_disabledInputText');
    }
    inputText = page.inputTextFromSectionById('readonly').byIndex(1);
    await chaiExpect(await inputText.isDisabled()).equal(false, 'Input text should NOT be disabled');
  });
  it('should verify the <eui-input-text> invalid ', async () => {
    browser.addTestMeta({ zephyrStep: "447061" });
    let sectionId = 'invalid';
    await BaseActions.verifySection(sectionId, pageName);

    let inputText = page.inputTextFromSectionById(sectionId).byIndex(1);
    await expect(await (await inputText.element())).toExist({ wait: 2000, message: '<eui-input-text> is not existing on page' });
    await expect(await (await inputText.element())).toBeDisplayedInViewport({ wait: 2000, message: 'inputText from invalid section is not displayed on page' });
    await chaiExpect(await inputText.isInvalid()).equal(true, 'Input Text should be invalid');

    if (browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(await (await page.euiInputTextCo.element()), testFolder + 'img_invalidInputText',
        { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for img_invalidInputText');
    }
    inputText = page.inputTextFromSectionById('disabled').byIndex(1);
    await chaiExpect(await inputText.isInvalid()).equal(false, 'Input text should NOT be invalid');
  });
});
