import Routing from '../../../../pages/eui/10x/routing-10x.js'
import EuiIconPage from '../../../../pages/eui/10x/eui/eui-icon-10x.po.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'

describe('eUI - <eui-icon> Component Object',async () => {
  let page = new EuiIconPage();
  let testFolder = './/eui-icon//'
  it('should navigate to <eui-icon> demo page ',async () => {
    browser.addTestMeta({uuid:"c21e0282-d023-11eb-b8bc-0242ac130003", zephyrKey: "CCQA-1115", zephyrStep: "408318", reportGroups: ["eUI.10x.eui"]});
    await page.open(Routing.getEUIComponentUrl('eui-icon'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    await pgTitle.scrollIntoView();
    await expect(await $(pgTitle)).toBeDisplayedInViewport({message:'<eui-icon> page title is not displayed on page'});
    await expect(await $(page.appDocPageById('eui-icon'))).toBeDisplayed({message:'Page Id is not displayed on page'});
    await chaiExpect(await pgTitle.getText()).equal('eui-icon', '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 <eui-icon> identification methods',async () => {
    browser.addTestMeta({zephyrStep: "408319"});
    let sectionId = 'Default';
    let index = 2;
    let iconByIndex1 = await (await page.iconByIndex(index).element());
    await expect(await $(page.sectionById(sectionId))).toBeDisplayed({message:'<composition> section -> is not displayed on page'});
    await expect(iconByIndex1).toBeDisplayed({message:'Icon by index '+ index +' is not displayed on page'});
    await chaiExpect(await page.iconByIndex(index).defaultComponentsCount()).equal(92, 'There should be 92 <eui-icon> components on the page.');
    if(browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(iconByIndex1, testFolder+'img_iconByIndex1', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for iconByIndex1');
    }
  });
  it('should verify the method isLoading',async () => {
    browser.addTestMeta({zephyrStep: "408321"});
    let sectionId = 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let index = 3
    let icon = page.iconByIndex(index);
    await chaiExpect(await icon.isLoading()).equal(false, 'isLoading is not false');

    sectionId= 'is-loading';
    scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    index = 2
    icon = page.iconFromSectionWithIdByIndex(sectionId,index);
    await chaiExpect(await icon.isLoading()).equal(true, 'isLoading is not true');
  });


});
