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

describe('eUI - <eui-select> Component Object ', async () => {
  let page = new EuiSelectPage();
  let testFolder = './/v14x//eui-select//';
  let pageName = 'eui-select'
  it('should navigate to <eui-select> demo page', async () => {
    browser.addTestMeta({ uuid: "d5a9e050-79fb-11ec-90d6-0242ac120003", zephyrKey: "CCQA-1869", zephyrStep: "453926", reportGroups: ["eUI.14x.eui"] });
    await page.open(Routing.getEUIDirectivesUrl('eui-select'));
    await CookieBannerActions.cookieBanner(true);
    await BaseActions.verifyPageTitle(pageName);
    await expect(await $(page.navigationList)).toBeDisplayedInViewport({ message: 'Navigation List -> is not displayed on page' });
  });
  it('should verify the presence and number of component objects <eui-select> on page ', async () => {
    browser.addTestMeta({ zephyrStep: "453927" });
    let sectionId = 'Default';
    await BaseActions.verifySection(sectionId, pageName);
    let index = 1;
    let selectByIndex1 = await (await page.selectByIndex(index).element());
    await expect(selectByIndex1).toExist({ message: 'Select by index ' + index + ' is not existing on page' });
    await chaiExpect(await page.selectByIndex(index).defaultComponentsCount()).equal(23, 'There should be 23 <eui-select> components on the page.');
    if (browser.config.useWdioImageComparison) {
      await selectByIndex1.scrollIntoView();
      await chaiExpect(await browser.checkElement(selectByIndex1, testFolder + 'img_selectByIndex1', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for selectByIndex1');
    }
  });
  it('should verify the <eui-select>  multiple ', async () => {
    browser.addTestMeta({ zephyrStep: "453928" });
    let sectionId = 'multiple';
    await BaseActions.verifySection(sectionId, pageName);

    let selectMultiple = await (await page.selectFromSectionByIndex(sectionId, 1).element());

    await expect(selectMultiple).toExist({ message: 'Multiple is not existing on page' });
    await chaiExpect(await page.selectFromSectionByIndex(sectionId, 1).isMultiple()).equal(true, 'Select is not multipled');
    if (browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(selectMultiple, testFolder + 'img_selectMultiple', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for selectMultiple');
    }
  });
  it('should verify the <eui-select>  size ', async () => {
    browser.addTestMeta({ zephyrStep: "453929" });
    let sectionId = 'size';
    await BaseActions.verifySection(sectionId, pageName);
    let selectSize1 = await $(page.selectFromSectionByIndex(sectionId, 1).currentPath);
    let selectSize3 = await $(page.selectFromSectionByIndex(sectionId, 2).currentPath);
    let selectSize5 = await $(page.selectFromSectionByIndex(sectionId, 3).currentPath);
    await expect(selectSize1).toHaveAttrContaining('size', '1');
    await expect(selectSize3).toHaveAttrContaining('size', '3');
    await expect(selectSize5).toHaveAttrContaining('size', '5');
    if(browser.config.useWdioImageComparison) {
      await selectSize1.scrollIntoView();
      await chaiExpect(await browser.checkElement(selectSize1, testFolder+'img_selectSize1', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for selectSize1');
      await selectSize3.scrollIntoView();
      await chaiExpect(await browser.checkElement(selectSize3, testFolder+'img_selectSize3', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for selectSize3');
      await selectSize5.scrollIntoView();
      await chaiExpect(await browser.checkElement(selectSize5, testFolder+'img_selectSize5', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for selectSize5');
    }
  });
  it('should verify the <eui-select>  disabled ', async () => {
    browser.addTestMeta({ zephyrStep: "453930" });
    let sectionId = 'disabled';
    await BaseActions.verifySection(sectionId, pageName);

    let selectDisabled = await (await page.selectFromSectionByIndex(sectionId, 1).element());
    let selectNotDisabled = await (await page.selectFromSectionByIndex(sectionId, 2).element());

    await expect(selectDisabled).toExist({ message: 'selectDisabled is not existing on page' });
    await expect(selectDisabled).toHaveAttr('disabled');
    await expect(selectNotDisabled).toExist({ message: 'selectNotDisabled is not existing on page' });
    if (browser.config.useWdioImageComparison) {
        await chaiExpect(await browser.checkElement(selectDisabled, testFolder + 'img_selectDisabled', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for selectDisabled');
        await chaiExpect(await browser.checkElement(selectNotDisabled, testFolder + 'img_selectNotDisabled', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for selectNotDisabled');
    }
  });
  it('should verify the <eui-select>  placeholder ', async () => {
    browser.addTestMeta({ zephyrStep: "453931" });
    let sectionId = 'placeholder';
    await BaseActions.verifySection(sectionId, pageName);

    let placeholder = await (await page.selectFromSectionByIndex(sectionId, 1).element());

    await expect(placeholder).toExist({ message: 'placeholder is not existing on page' });
    await expect(placeholder).toHaveAttr('placeholder');
    if (browser.config.useWdioImageComparison) {
        await chaiExpect(await browser.checkElement(placeholder, testFolder + 'img_placeholder', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for placeholder');
    }
  });
  // element is hidden
  xit('should verify the <eui-select>  readonly ', async () => {
    browser.addTestMeta({ zephyrStep: "453932" });
    let sectionId = 'readonly';
    await BaseActions.verifySection(sectionId, pageName);

    let selectReadonly = await (await page.selectFromSectionByIndex(sectionId, 1).element());

    await expect(selectReadonly).toExist({ message: 'selectReadonly is not existing on page' });
    await chaiExpect(await page.selectFromSectionByIndex(sectionId, 2).isReadonly()).equal(true, 'selectReadonly is not readonly');
    let removeReadOnlyButton = await (await page.euiButtonCOfromSectionWithIdByIndex(sectionId, 2).element());
    if(await removeReadOnlyButton.isExisting() && await removeReadOnlyButton.isDisplayed()) {
      await removeReadOnlyButton.click();
    }
    if (browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(selectReadonly, testFolder + 'img_selectReadonly', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for selectReadonly');
    }
  });
  it('should verify the <eui-select>  invalid ', async () => {
    browser.addTestMeta({ zephyrStep: "453933" });
    let sectionId = 'invalid';
    await BaseActions.verifySection(sectionId, pageName);

    let selectInvalid = await (await page.selectFromSectionByIndex(sectionId, 1).element());

    await expect(selectInvalid).toExist({ message: 'selectInvalid is not existing on page' });
    await chaiExpect(await page.selectFromSectionByIndex(sectionId, 1).isInvalid()).equal(true, 'selectInvalid is not invalid');
    if (browser.config.useWdioImageComparison) {
        await chaiExpect(await browser.checkElement(selectInvalid, testFolder + 'img_selectInvalid', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for selectInvalid');
    }
  });
});
