import Routing from '../../../../pages/eui/10x/routing-10x.js'
import EuiInputCheckboxPage from '../../../../pages/eui/10x/eui/eui-input-checkbox-10x.po.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'

describe('eUI - <eui-input-checkbox> Component Object ',async () => {
  let page = new EuiInputCheckboxPage();
  let testFolder = './/eui-input-checkbox//';
  it('should navigate to <eui-input-checkbox> demo page',async () => {
    browser.addTestMeta({uuid:"5f1e8320-2da5-11ec-8d3d-0242ac130003", zephyrKey: "CCQA-1751", zephyrStep: "438168", reportGroups: ["eUI.10x.eui"]});
    await page.open(Routing.getEUIDirectivesUrl('eui-input-checkbox'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    await pgTitle.scrollIntoView();
    await expect(await $(pgTitle)).toBeDisplayedInViewport({message:'<euiInputCheckBox> page title is not displayed on page'});
    await expect(await $(page.appDocPageById('euiInputCheckBox'))).toExist({message:'Page Id is not existing on page'});
    await chaiExpect(await pgTitle.getText()).equal('euiInputCheckBox', 'Page title text is not as expected');
    await expect(await $(page.navigationList)).toBeDisplayed({message:'Navigation List -> is not displayed on page'});
  });
 it('should verify the presence and number of component objects <eui-input-checkbox> on page ',async () => {
    browser.addTestMeta({zephyrStep: "438169"});
    let sectionId = 'Default';
    let index = 1;
    let inputCheckboxByIndex1 = await (await page.inputCheckboxByIndex(index).element());
    await expect(await $(page.sectionById(sectionId))).toBeDisplayed({message:'<Default> section -> is not displayed on page'});
    await expect(inputCheckboxByIndex1).toExist({message:'inputCheckbox by index '+ index +' is not existing on page'});
    await chaiExpect(await page.inputCheckboxByIndex(index).defaultComponentsCount()).equal(40, 'There should be 40 <eui-input-checkbox> components on the page.');
    if(browser.config.useWdioImageComparison) {
      await inputCheckboxByIndex1.scrollIntoView();
      await chaiExpect(await browser.checkElement(inputCheckboxByIndex1, testFolder+'img_inputCheckboxByIndex1', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for inputCheckboxByIndex1');
    }
  });

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

    let inputCheckboxWithLabel = await (await page.inputCheckboxFromSectionByIndex(sectionId, 2).element());
    let inputCheckboxNoLabel = await (await page.inputCheckboxFromSectionByIndex(sectionId, 3).element());

    await expect(inputCheckboxWithLabel).toExist({message:'inputCheckboxWithLabel is not existing on page'});
    await chaiExpect(await page.inputCheckboxFromSectionByIndex(sectionId, 2).hasNoLabel()).equal(false, 'inputCheckboxWithLabel has no label');
    await expect(inputCheckboxNoLabel).toExist({message:'inputCheckboxNoLabel is not existing on page'});
    await chaiExpect(await page.inputCheckboxFromSectionByIndex(sectionId, 3).hasNoLabel()).equal(true, 'inputCheckboxNoLabel has label');
  });

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

    let inputCheckboxInvalid = await (await page.inputCheckboxFromSectionByIndex(sectionId, 1).element());

    await expect(inputCheckboxInvalid).toExist({message:'inputCheckboxInvalid is not existing on page'});
    await chaiExpect(await page.inputCheckboxFromSectionByIndex(sectionId, 1).isInvalid()).equal(true, 'inputCheckboxInvalid is not invalid');
    if(browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(inputCheckboxInvalid, testFolder+'img_inputCheckboxInvalid', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for inputCheckboxInvalid');
    }
    await (await $(page.buttonComponentByTextContains('Dynamically remove invalid state').currentPath)).click();
    await browser.deductedWait(1000);
    let inputCheckboxValid = await (await page.inputCheckboxFromSectionByIndex(sectionId, 1).element());
    await expect(inputCheckboxValid).toExist({message:'inputCheckboxValid is not existing on page'});
    await chaiExpect(await page.inputCheckboxFromSectionByIndex(sectionId, 1).isInvalid()).equal(false, 'inputCheckboxValid after click on button is invalid');
    if(browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(inputCheckboxValid, testFolder+ 'img_inputCheckboxValid', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for inputCheckboxValid');
    }
  });

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

    let inputCheckboxDisabled = await (await page.inputCheckboxFromSectionByIndex(sectionId, 1).element());

    await expect(inputCheckboxDisabled).toExist({message:'inputCheckboxDisabled is not existing on page'});
    await chaiExpect(await page.inputCheckboxFromSectionByIndex(sectionId, 1).isDisabled()).equal(true, 'inputCheckboxDisabled is not disabled');

    if(browser.config.useWdioImageComparison) {
      await inputCheckboxDisabled.scrollIntoView();
      if (browser.config.env.endsWith('DEV')){
      await chaiExpect(await browser.checkElement(inputCheckboxDisabled, testFolder+'img_inputCheckboxDisabledDev', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for inputCheckboxDisabled');
      }
      else {
        await chaiExpect(await browser.checkElement(inputCheckboxDisabled, testFolder+'img_inputCheckboxDisabled', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for inputCheckboxDisabled');
      }
    }

    await (await $(page.buttonComponentByTextContains('Dynamically remove disabled state').currentPath)).click();

    let inputCheckboxNotDisabled = await (await page.inputCheckboxFromSectionByIndex(sectionId, 1).element());

    await expect(inputCheckboxNotDisabled).toExist({message:'inputCheckboxNotDisabled is not existing on page'});
    await chaiExpect(await page.inputCheckboxFromSectionByIndex(sectionId, 1).isDisabled()).equal(false, 'inputCheckboxNotDisabled after click on button is disabled');

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

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

    let inputCheckboxReadOnly = await (await page.inputCheckboxFromSectionByIndex(sectionId, 1).element());

    await expect(inputCheckboxReadOnly).toExist({message:'inputCheckboxReadOnly is not existing on page'});
    await chaiExpect(await page.inputCheckboxFromSectionByIndex(sectionId, 1).isReadOnly()).equal(true, 'inputCheckboxReadOnly is not readonly');

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

    await (await $(page.buttonComponentByTextContains('Remove ReadOnly').currentPath)).click();

    let inputCheckboxNotReadOnly = await (await page.inputCheckboxFromSectionByIndex(sectionId, 1).element());

    await expect(inputCheckboxNotReadOnly).toExist({message:'inputCheckboxNotReadOnly is not existing on page'});
    await chaiExpect(await page.inputCheckboxFromSectionByIndex(sectionId, 1).isReadOnly()).equal(false, 'inputCheckboxNotReadOnly after click on button is readonly');

    if(browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(inputCheckboxNotReadOnly, testFolder+ 'img_inputCheckboxNotReadOnly',   {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for inputCheckboxNotReadOnly');
    }
  });
  it('should verify the <eui-input-checkbox> is checked ',async () => {
    browser.addTestMeta({zephyrStep: "456194"});
    let sectionId = 'Default';
    let sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();

    let inputCheckboxNotChecked = await (await page.inputCheckboxFromSectionByIndex(sectionId, 1).element());
    let inputCheckboxChecked = await (await page.inputCheckboxFromSectionByIndex(sectionId, 2).element());

    await expect(inputCheckboxNotChecked).toExist({message:'inputCheckboxNotChecked is not existing on page'});
    await chaiExpect(await page.inputCheckboxFromSectionByIndex(sectionId, 1).isChecked()).equal(false, 'inputCheckboxNotChecked is checked');
    await expect(inputCheckboxChecked).toExist({message:'inputCheckboxChecked is not existing on page'});
    await chaiExpect(await page.inputCheckboxFromSectionByIndex(sectionId, 2).isChecked()).equal(true, 'inputCheckboxChecked is not checked');
    if(browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(inputCheckboxNotChecked, testFolder+'img_inputCheckboxNotChecked', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for inputCheckboxNotChecked');
      await chaiExpect(await browser.checkElement(inputCheckboxChecked, testFolder+'img_inputCheckboxChecked', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for inputCheckboxChecked');
    }
  });
});
