import Routing from '../../../pages/eui/14x/routing.js'
import EuiIconTogglePage from '../../../pages/eui/14x/eui-icon-toggle.po.js'
import * as CookieBannerActions from '../../../actions/cookieBanner.js';
import BaseActions from '../../../actions/V14/base-actions.js';

describe('eUI - <eui-icon-toggle> Component Object', async () => {
  let page = new EuiIconTogglePage();
  let testFolder = './/v14x/eui-icon-toggle//'
  let pageName = 'eui-icon-toggle'
  it('should navigate to <eui-icon-toggle> demo page ', async () => {
    browser.addTestMeta({ uuid: "d414fe04-332f-11ec-8d3d-0242ac130003", zephyrKey: "CCQA-1764", zephyrStep: "439126", reportGroups: ["eUI.14x.eui"] });
    await page.open(Routing.getEUIComponentUrl('eui-icon-toggle'));
    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 <eui-icon-toggle> identification methods', async () => {
    browser.addTestMeta({ zephyrStep: "439127" });
    let sectionId = 'Default';
    await BaseActions.verifySection(sectionId, pageName);
    let index = 1;
    let iconToggleByIndex1 = await (await page.iconToggleByIndex(index).element());
    await expect(iconToggleByIndex1).toBeDisplayed({ message: 'Icon toogle by index ' + index + ' is not displayed on page' });
    await chaiExpect(await page.iconToggleByIndex(index).defaultComponentsCount()).equal(8, 'There should be 8 <eui-icon-toggle> components on the page.');
    if (browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(iconToggleByIndex1, testFolder + 'img_iconToggleByIndex1', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for iconToggleByIndex1');
    }
  });
  it('should verify isChecked and isReadOnly', async () => {
    browser.addTestMeta({ zephyrStep: "439128" });
    let sectionId = 'isChecked = true';
    await BaseActions.verifySection(sectionId, pageName);
    let iconToggleFromIsCheckedSection = page.iconToggleFromSectionById(sectionId);
    let iconToggleIsChecked = await (await iconToggleFromIsCheckedSection.element());
    await chaiExpect(await iconToggleFromIsCheckedSection.isChecked()).equal(true, 'isChecked is not true');
    await chaiExpect(await iconToggleFromIsCheckedSection.isReadOnly()).equal(false, 'isReadOnly is not false');
    if (browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(iconToggleIsChecked, testFolder + 'img_iconToggleIsChecked', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for iconToggleIsChecked');
    }
    sectionId = 'isReadOnly = true';
    await BaseActions.verifySection(sectionId, pageName);
    let iconToggleFromIsReadOnlySection = page.iconToggleFromSectionById(sectionId);
    let iconToggleIsReadOnly = await (await iconToggleFromIsReadOnlySection.element());
    await chaiExpect(await iconToggleFromIsReadOnlySection.isChecked()).equal(false, 'isChecked is not false');
    await chaiExpect(await iconToggleFromIsReadOnlySection.isReadOnly()).equal(true, 'isReadOnly is not true');
    if (browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(iconToggleIsReadOnly, testFolder + 'img_iconToggleIsReadOnly', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for iconToggleIsReadOnly');
    }
  });
  it('should verify toggle and icon', async () => {
    browser.addTestMeta({ zephyrStep: "439129" });
    let sectionId = 'Default';
    await BaseActions.verifySection(sectionId, pageName);
    let index = 1;
    let iconToggleToggle = await $(page.iconToggleByIndex(index).toggle);
    let iconToggleIcon = await $(page.iconToggleByIndex(index).icon);
    await expect(iconToggleToggle).toBeDisplayed({ message: 'Icon toogle toggle is not displayed on page' });
    await expect(iconToggleIcon).toBeDisplayed({ message: 'Icon toogle icon is not displayed on page' });
    if (browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(iconToggleToggle, testFolder + 'img_iconToggleToggle', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for iconToggleToggle');
    }
  });

});
