import Routing from '../../../../pages/eui/10x/routing-10x.js'
import EuiInputGroupPage from '../../../../pages/eui/10x/eui/eui-input-group-10x.po.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'
import CoEuiInputCheckbox from '../../../../components/10x/eui/eui-input-checkbox.js'
import CoEuiInputRadio from '../../../../components/10x/eui/eui-input-radio.js'
import CoEuiFeedbackMessage from '../../../../components/10x/eui/eui-feedback-message.js'
import CoEuiLabel from '../../../../components/10x/eui/eui-label.js'

describe('eUI - <eui-input-group> Component Object ',async () => {
  let page = new EuiInputGroupPage();
  let testFolder = './/eui-input-group//';
  it('should navigate to <eui-input-group> demo page',async () => {
    browser.addTestMeta({ uuid: "7793988e-7abf-11ec-90d6-0242ac120003", zephyrKey: "CCQA-1871", zephyrStep: "453978", reportGroups: ["eUI.10x.eui"] });
    await page.open(Routing.getEUIDirectivesUrl('eui-input-group'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    await pgTitle.scrollIntoView();
    await expect(await $(pgTitle)).toBeDisplayedInViewport({ message: '<euiSelect> page title is not displayed on page' });
    await expect(await $(page.appDocPageById('eui-input-group'))).toExist({message:'Page Id is not existing on page'});
    await chaiExpect(await pgTitle.getText()).equal('eui-input-group', 'Page title text is not as expected');
    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-input-group> on page ',async () => {
    browser.addTestMeta({ zephyrStep: "453979" });
    let sectionId = 'Default';
    let index = 1;
    let inputGroupByIndex1 = await (await page.inputGroupByIndex(index).element());
    await expect(await $(page.sectionById(sectionId))).toBeDisplayed({ message: '<Default> section -> is not displayed on page' });
    await expect(inputGroupByIndex1).toExist({ message: 'Select by index ' + index + ' is not existing on page' });
    await chaiExpect(await page.inputGroupByIndex(index).defaultComponentsCount()).equal(75, 'There should be 75 <eui-input-group> components on the page.');
    if (browser.config.useWdioImageComparison) {
      await inputGroupByIndex1.scrollIntoView();
      await chaiExpect(await browser.checkElement(inputGroupByIndex1, testFolder + 'img_inputGroupByIndex1', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for inputGroupByIndex1');
    }
  });
 it('should verify the <eui-input-group>  checkbox ',async () => {
    browser.addTestMeta({ zephyrStep: "453980" });
    let sectionId = 'Default';
    let sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();

    let inputGroupByIndex2 = page.inputGroupFromSectionByIndex(sectionId, 2);
    let checkbox = await (await new CoEuiInputCheckbox(inputGroupByIndex2.currentPath).element());
    await expect(checkbox).toExist({ message: 'checkbox is not existing on page' });
    if (browser.config.useWdioImageComparison) {
        await chaiExpect(await browser.checkElement(checkbox, testFolder + 'img_checkbox', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for checkbox');
    }
  });
  it('should verify the <eui-input-group>  radio ',async () => {
    browser.addTestMeta({ zephyrStep: "453981" });
    let sectionId = 'Default';
    let sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();

    let inputGroupByIndex3 = page.inputGroupFromSectionByIndex(sectionId, 3);
    let radio = await (await new CoEuiInputRadio(inputGroupByIndex3.currentPath).element());
    await expect(radio).toExist({ message: 'radio is not existing on page' });
    if (browser.config.useWdioImageComparison) {
        await chaiExpect(await browser.checkElement(radio, testFolder + 'img_radio', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for radio');
    }
  });
  it('should verify the <eui-input-group> feedback message ',async () => {
    browser.addTestMeta({ zephyrStep: "453982" });
    let sectionId = 'Default';
    let sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();

    let inputGroupByIndex4 = page.inputGroupFromSectionByIndex(sectionId, 4);
    let feedbackMessage = await (await new CoEuiFeedbackMessage(inputGroupByIndex4.currentPath).element());
    await expect(feedbackMessage).toExist({ message: 'feedbackMessage is not existing on page' });
    if (browser.config.useWdioImageComparison) {
        await chaiExpect(await browser.checkElement(feedbackMessage, testFolder + 'img_feedbackMessage', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for feedbackMessage');
    }
  });
  it('should verify the <eui-input-group> required ',async () => {
    browser.addTestMeta({ zephyrStep: "453983" });
    let sectionId = 'Required';
    let sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();

    let inputGroupByIndex1 = page.inputGroupFromSectionByIndex(sectionId, 1);
    let labelRequired = new CoEuiLabel(inputGroupByIndex1.currentPath)
    await expect(await (await labelRequired.element())).toExist({ message: 'labelRequired is not existing on page' });
    await chaiExpect(await labelRequired.isRequired()).equal(true, 'label is not required');
    if (browser.config.useWdioImageComparison) {
        await chaiExpect(await browser.checkElement(await (await labelRequired.element()), testFolder + 'img_labelRequired', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for labelRequired');
    }
  })
  it('should verify the <eui-input-group> vertical layout ',async () => {
    browser.addTestMeta({ zephyrStep: "453984" });
    let sectionId = 'Vertical';
    let sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();

    let inputGroupVertical = await (await page.inputGroupFromSectionByIndex(sectionId, 1).element());
    await expect(inputGroupVertical).toExist({ message: 'inputGroupVertical is not exist on page' });
    await expect(inputGroupVertical).not.toHaveAttrContaining('class', 'row');
    if (browser.config.useWdioImageComparison) {
        await chaiExpect(await browser.checkElement(inputGroupVertical, testFolder + 'img_inputGroupVertical', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for inputGroupVertical');
    }
  })

  it('should verify the <eui-input-group> horizontal layout ',async () => {
    browser.addTestMeta({ zephyrStep: "453985" });
    let sectionId = 'Horizontal';
    let sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();

    let inputGroupHorizontal = await (await page.inputGroupFromSectionByIndex(sectionId, 1).element());
    await expect(inputGroupHorizontal).toExist({ message: 'inputGroupHorizontal is not exist on page' });
    await expect(inputGroupHorizontal).toHaveAttrContaining('class', 'row');
    if (browser.config.useWdioImageComparison) {
        await chaiExpect(await browser.checkElement(inputGroupHorizontal, testFolder + 'img_inputGroupHorizontal', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for inputGroupHorizontal');
    }
  })
});
