import Routing from '../../../pages/eui/14x/routing.js'
import * as CookieBannerActions from '../../../actions/cookieBanner.js'
import EuiTextareaPage from '../../../pages/eui/14x/eui-textarea.po.js'
import { elementAttributeContains } from '../../../core/utils.js';
import BaseActions from '../../../actions/V14/base-actions.js';

describe('eUI - <eui-textarea> Component Object ', async () => {
  let page = new EuiTextareaPage();
  let testFolder = './/v14x//eui-textarea//';
  let imageToCompare;
  let pageName = 'euiTextArea'
  it('should navigate to <eui-textarea> demo page', async () => {
    browser.addTestMeta({uuid:"4f90c788-cc51-11ec-9d64-0242ac120002", zephyrKey: "CCQA-2054", zephyrStep: "484622", reportGroups: ["eUI.14x.eui"]});
    await page.open(Routing.getEUIDirectivesUrl('eui-textarea'));
    await CookieBannerActions.cookieBanner(true);
    await BaseActions.verifyPageTitle(pageName);
    await expect(await $(page.navigationList)).toBeDisplayedInViewport({wait:1000, message:'Navigation List -> is not displayed on page'});
  });
 it('should verify the presence and number of component objects <eui-textarea> on page ', async () => {
    browser.addTestMeta({zephyrStep: "484623"});
    let sectionId= 'Default';
    await BaseActions.verifySection(sectionId, pageName);
    let index = 1;
    let text = 'It was a dark and stormy night...';
    let textareaByIndex1 = await (await page.textareaByIndex(index).element());
    let textareaByText = await (await page.textareaByTextContains(text).element());
    let textareaByTextAndIndex = await (await page.textareaByTextEqualsAndIndex(text, 1).element());
    await expect(textareaByIndex1).toBeDisplayed({wait:1000, message:'textarea by index '+ index +' is not displayed on page'});
    await expect(textareaByText).toBeDisplayed({wait:1000, message:'textarea by text  '+ text +' is not displayed on page'});
    await expect(textareaByTextAndIndex).toBeDisplayed({wait:1000, message:'textarea by index '+ index +' and text  '+ text +' is not displayed on page'});
    await chaiExpect(await page.textareaByIndex(index).defaultComponentsCount()).equal(12, 'There should be 12 <eui-textarea> components on the page.');
    if(browser.config.useWdioImageComparison) {
      await textareaByIndex1.scrollIntoView();
      imageToCompare =(browser.config.env.endsWith('DEV') ? 'img_textareaByIndex1Dev' : 'img_textareaByIndex1');
      await chaiExpect(await browser.checkElement(textareaByIndex1, testFolder+imageToCompare, {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for textareaByIndex1');
      await textareaByText.scrollIntoView();
      imageToCompare =(browser.config.env.endsWith('DEV') ? 'img_textareaByTextDev' : 'img_textareaByText');
      await chaiExpect(await browser.checkElement(textareaByText, testFolder+imageToCompare, {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for textareaByText');
      await textareaByTextAndIndex.scrollIntoView();
      imageToCompare =(browser.config.env.endsWith('DEV') ? 'img_textareaByTextAndIndexDev' : 'img_textareaByTextAndIndex');
      await chaiExpect(await browser.checkElement(textareaByTextAndIndex, testFolder+imageToCompare, {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for textareaByTextAndIndex');
    }
  });
  it('should verify the <eui-textarea> read-only ', async () => {
    browser.addTestMeta({zephyrStep: "484624"});
    let sectionId = 'readonly';
    await BaseActions.verifySection(sectionId, pageName);
    let textareaReadOnly = page.textareaFromSectionWithIdByIndex(sectionId, 1);
    await expect(await (await textareaReadOnly.element())).toExist({wait:1000,message:'textareaReadOnly is not existing on page'});
    await chaiExpect(await elementAttributeContains(textareaReadOnly.currentPath, 'readonly', 'false')).equal(false, 'textareaReadOnly is read-only');
  });

   it('should verify the <eui-textarea> disabled ', async () => {
    browser.addTestMeta({zephyrStep: "484625"});
    let sectionId = 'disabled';
    await BaseActions.verifySection(sectionId, pageName);
    let textareaDisabled = await (await page.textareaFromSectionWithIdByIndex(sectionId, 1).element());

    await expect(textareaDisabled).toBeDisplayed({wait:1000, message:'textareaDisabled is not displayed on page'});
    await expect(textareaDisabled).toHaveAttr('disabled');

    if(browser.config.useWdioImageComparison) {
      await textareaDisabled.scrollIntoView();
      imageToCompare =(browser.config.env.endsWith('DEV') ? 'img_textareaDisabledDev' : 'img_textareaDisabled');
      await chaiExpect(await browser.checkElement(textareaDisabled, testFolder+imageToCompare, {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for textareaDisabled');
    }
  });
  it('should verify the <eui-textarea> invalid', async () => {
    browser.addTestMeta({zephyrStep: "484626"});
    let sectionId = 'invalid';
    await BaseActions.verifySection(sectionId, pageName);

    let textareaInvalid = await (await page.textareaFromSectionWithIdByIndex(sectionId, 1).element());
    await expect(textareaInvalid).toBeDisplayed({wait:1000, message:'textareaInvalid is not displayed on page'});
    await chaiExpect(await elementAttributeContains(page.textareaFromSectionWithIdByIndex(sectionId, 1).currentPath, 'class', 'invalid')).equal(true, 'textareaInvalid is not invalid');
    if(browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(textareaInvalid, testFolder+'img_textareaInvalid', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for textareaInvalid');
    }
  });
  it('should verify the <eui-textarea> placeholder', async () => {
    browser.addTestMeta({zephyrStep: "484627"});
    let sectionId = 'placeholder';
    await BaseActions.verifySection(sectionId, pageName);

    let textareaPlaceholder = await (await page.textareaFromSectionWithIdByIndex(sectionId, 1).element());
    await expect(textareaPlaceholder).toBeDisplayed({wait:1000, message:'textareaPlaceholder is not displayed on page'});
    await expect(textareaPlaceholder).toHaveAttr('placeholder');
    if(browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(textareaPlaceholder, testFolder+'img_textareaPlaceholder', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for textareaPlaceholder');
    }
  });
  it('should verify the <eui-textarea> auto-resize ', async () => {
    browser.addTestMeta({zephyrStep: "484628"});
    let sectionId = 'auto-resize';
    await BaseActions.verifySection(sectionId, pageName);

    let textareaAutoresize = await (await page.textareaFromSectionWithIdByIndex(sectionId, 1).element());
    await expect(textareaAutoresize).toBeDisplayed({wait:1000, message:'textareaAutoresize is not displayed on page'});
    await expect(textareaAutoresize).toHaveAttr('autoresize');
    if(browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(textareaAutoresize, testFolder+'img_textareaAutoresize', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for textareaAutoresize');
    }
  });
});
