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

describe('eUI - <eui-input-group> Component Object ', async () => {
  let page = new EuiInputGroupPage();
  let testFolder = './/v14x//eui-input-group//';
  let pageName = 'euiInputGroup'
  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.14x.eui"] });
    await page.open(Routing.getEUIDirectivesUrl('eui-input-group'));
    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-input-group> on page ', async () => {
    browser.addTestMeta({ zephyrStep: "453979" });
    let sectionId = 'Default';
    await BaseActions.verifySection(sectionId, pageName);
    let index = 1;
    let inputGroupByIndex1 = await (await page.inputGroupByIndex(index).element());
    await expect(inputGroupByIndex1).toExist({ message: 'Select by index ' + index + ' is not existing on page' });
    await chaiExpect(await page.inputGroupByIndex(index).defaultComponentsCount()).equal(107, 'There should be 107 <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';
    await BaseActions.verifySection(sectionId, pageName);

    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';
    await BaseActions.verifySection(sectionId, pageName);

    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';
    await BaseActions.verifySection(sectionId, pageName);

    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';
    await BaseActions.verifySection(sectionId, pageName);

    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';
    await BaseActions.verifySection(sectionId, pageName);

    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';
    await BaseActions.verifySection(sectionId, pageName);

    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');
    }
  })
});
