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

describe('eUI - <eui-input-checkbox> Component Object ', async () => {
  let page = new EuiInputCheckboxPage();
  let testFolder = './/v14x//eui-input-checkbox//';
  let pageName = 'euiInputCheckBox'
  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.14x.eui"] });
    await page.open(Routing.getEUIDirectivesUrl('eui-input-checkbox'));
    await CookieBannerActions.cookieBanner(true);
    await BaseActions.verifyPageTitle(pageName);
    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';
    await BaseActions.verifySection(sectionId, pageName);
    let index = 1;
    let inputCheckboxByIndex1 = await (await page.inputCheckboxByIndex(index).element());
    await expect(inputCheckboxByIndex1).toExist({ message: 'inputCheckbox by index ' + index + ' is not existing on page' });
    await chaiExpect(await page.inputCheckboxByIndex(index).defaultComponentsCount()).equal(41, 'There should be 41 <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';
    await BaseActions.verifySection(sectionId, pageName);;

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

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

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

    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();
      await chaiExpect(await browser.checkElement(inputCheckboxDisabled, testFolder + 'img_inputCheckboxDisabled', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for inputCheckboxDisabled');
    }
  });

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

    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');
    }
  });
  it('should verify the <eui-input-checkbox> is checked ', async () => {
    browser.addTestMeta({ zephyrStep: "456194" });
    let sectionId = 'Default';
    await BaseActions.verifySection(sectionId, pageName);

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