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

describe('eUI - <eui-input-radio> Component Object ', async () => {
  let page = new EuiInputRadioPage();
  let testFolder = './/v14x//eui-input-radio//';
  let pageName = 'euiInputRadio'
  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.14x.eui"] });
    await page.open(Routing.getEUIDirectivesUrl('eui-input-radio'));
    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-radio> on page ', async () => {
    browser.addTestMeta({ zephyrStep: "438234" });
    let sectionId = 'Default';
    await BaseActions.verifySection(sectionId, pageName);
    let index = 1;
    let inputRadioByIndex1 = await (await page.inputRadioByIndex(index).element());
    await expect(inputRadioByIndex1).toExist({ message: 'inputRadio by index ' + index + ' is not existing on page' });
    await chaiExpect(await page.inputRadioByIndex(index).defaultComponentsCount()).equal(39, 'There should be 39 <eui-input-radio> components on the page.');
    if (browser.config.useWdioImageComparison) {
      await inputRadioByIndex1.scrollIntoView();
      await chaiExpect(await browser.checkElement(inputRadioByIndex1, testFolder + 'img_inputRadioByIndex1Dev', { 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';
    await BaseActions.verifySection(sectionId, pageName);

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

    let inputRadioInvalidUnchecked = await (await page.inputRadioFromSectionByIndex(sectionId, 1).element());
    await expect(inputRadioInvalidUnchecked).toExist({ message: 'inputRadioInvalidUnchecked is not existing on page' });
    await chaiExpect(await page.inputRadioFromSectionByIndex(sectionId, 1).isInvalid()).equal(true, 'inputRadioInvalidUnchecked is not invalid');
    await chaiExpect(await page.inputRadioFromSectionByIndex(sectionId, 1).isChecked()).equal(false, 'inputRadioInvalidUnchecked is checked');
    if (browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(inputRadioInvalidUnchecked, testFolder + 'img_inputRadioInvalidDevUnchecked', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for inputRadioInvalidUnchecked');
    }

    let inputRadioInvalidChecked = await (await page.inputRadioFromSectionByIndex(sectionId, 2).element());
    await expect(inputRadioInvalidChecked).toExist({ message: 'inputRadioInvalidChecked is not existing on page' });
    await chaiExpect(await page.inputRadioFromSectionByIndex(sectionId, 2).isInvalid()).equal(true, 'inputRadioInvalidChecked is not invalid');
    await chaiExpect(await page.inputRadioFromSectionByIndex(sectionId, 2).isChecked()).equal(true, 'inputRadioInvalidChecked is not checked');
    if (browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(inputRadioInvalidChecked, testFolder + 'img_inputRadioInvalidDevChecked', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for inputRadioInvalidChecked');
    }
  });

  it('should verify the <eui-input-radio> disabled ', async () => {
    browser.addTestMeta({ zephyrStep: "438237" });
    let sectionId = 'disabled';
    await BaseActions.verifySection(sectionId, pageName);

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

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

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

  it('should verify the <eui-input-radio> readonly ', async () => {
    browser.addTestMeta({ zephyrStep: "438238" });
    let sectionId = 'readonly';
    await BaseActions.verifySection(sectionId, pageName);

    let inputRadioReadOnlyUnchecked = await (await page.inputRadioFromSectionByIndex(sectionId, 1).element());
    await expect(inputRadioReadOnlyUnchecked).toExist({ message: 'inputRadioReadOnlyUnchecked is not existing on page' });
    await chaiExpect(await page.inputRadioFromSectionByIndex(sectionId, 1).isReadOnly()).equal(true, 'inputRadioReadOnlyUnchecked is not readonly');
    await chaiExpect(await page.inputRadioFromSectionByIndex(sectionId, 1).isChecked()).equal(false, 'inputRadioReadOnlyUnchecked is checked');

    let inputRadioReadOnlyChecked = await (await page.inputRadioFromSectionByIndex(sectionId, 3).element());
    await expect(inputRadioReadOnlyChecked).toExist({ message: 'inputRadioReadOnlyChecked is not existing on page' });
    await chaiExpect(await page.inputRadioFromSectionByIndex(sectionId, 3).isReadOnly()).equal(true, 'inputRadioReadOnlyChecked is not readonly');
    await chaiExpect(await page.inputRadioFromSectionByIndex(sectionId, 3).isChecked()).equal(true, 'inputRadioReadOnlyUnchecked is not checked');
  });

});
