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

describe('eUI - <eui-input-radio> Component Object ',async () => {
  let page = new EuiInputRadioPage();
  let testFolder = './/eui-input-radio//';
  it('should navigate to <eui-input-radio> demo page',async () => {
    browser.addTestMeta({uuid:"39878096-3005-11ec-8d3d-0242ac130003", zephyrKey: "CCQA-1754", zephyrStep: "438233", reportGroups: ["eUI.10x.eui"]});
    await page.open(Routing.getEUIDirectivesUrl('eui-input-radio'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    await pgTitle.scrollIntoView();
    await expect(await $(pgTitle)).toBeDisplayedInViewport({message:'<euiInputRadio> page title is not displayed on page'});
    await expect(await $(page.appDocPageById('euiInputRadio'))).toExist({message:'Page Id is not existing on page'});
    await chaiExpect(await pgTitle.getText()).equal('euiInputRadio', '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-radio> on page ',async () => {
    browser.addTestMeta({zephyrStep: "438234"});
    let sectionId= 'Default';
    let index = 1;
    let inputRadioByIndex1 = await (await page.inputRadioByIndex(index).element());
    await expect(await $(page.sectionById(sectionId))).toBeDisplayed({message:'<Default> section -> is not displayed on page'});
    await expect(inputRadioByIndex1).toExist({message:'inputRadio by index '+ index +' is not existing on page'});
    await chaiExpect(await page.inputRadioByIndex(index).defaultComponentsCount()).equal(44, 'There should be 44 <eui-input-radio> components on the page.');
    if(browser.config.useWdioImageComparison) {
      await inputRadioByIndex1.scrollIntoView();
      if (browser.config.env.endsWith('DEV')){
      await chaiExpect(await browser.checkElement(inputRadioByIndex1, testFolder+'img_inputRadioByIndex1Dev', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for inputRadioByIndex1');
      }
      else{
      await chaiExpect(await browser.checkElement(inputRadioByIndex1, testFolder+'img_inputRadioByIndex1', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for inputRadioByIndex1');
      }
    }
  });
  it('should verify the <eui-input-radio> without label ',async () => {
    browser.addTestMeta({zephyrStep: "438235"});
    let sectionId = 'Default';
    let sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();

    let inputRadioWithLabel = await (await page.inputRadioFromSectionByIndex(sectionId, 17).element());
    let inputRadioNoLabel = await (await page.inputRadioFromSectionByIndex(sectionId, 4).element());

    await expect(inputRadioWithLabel).toExist({message:'inputRadioWithLabel is not existing on page'});
    await chaiExpect(await page.inputRadioFromSectionByIndex(sectionId, 17).hasNoLabel()).equal(false, 'inputRadioWithLabel has no label');
    await expect(inputRadioNoLabel).toExist({message:'inputRadioNoLabel is not existing on page'});
    await chaiExpect(await page.inputRadioFromSectionByIndex(sectionId, 4).hasNoLabel()).equal(true, 'inputRadioNoLabel has label');
  });

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

    let inputRadioInvalid = await (await page.inputRadioFromSectionByIndex(sectionId, 1).element());

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

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

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

    let inputRadioDisabled = await (await page.inputRadioFromSectionByIndex(sectionId, 3).element());

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

    if(browser.config.useWdioImageComparison) {
      await inputRadioDisabled.scrollIntoView();
      if (browser.config.env.endsWith('DEV')){
      await chaiExpect(await browser.checkElement(inputRadioDisabled, testFolder+'img_inputRadioDisabledDev', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for inputRadioDisabled');
      }
      else{
      await chaiExpect(await browser.checkElement(inputRadioDisabled, testFolder+'img_inputRadioDisabled', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for inputRadioDisabled');
      }
    }
    await (await $(page.buttonComponentByTextContains('Toggle Disabled state').currentPath)).click();
    let inputRadioNotDisabled = await (await page.inputRadioFromSectionByIndex(sectionId, 3).element());

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

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

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

    await (await $(page.buttonComponentByTextContains('Toggle ReadOnly state').currentPath)).click();
    let inputRadioNotReadOnly = await (await page.inputRadioFromSectionByIndex(sectionId, 1).element());

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

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

});
