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

describe('eUI - <eui-label> Component Object ', async () => {
  let page = new EuiLabelPage();
  let testFolder = './/eui-label//'
  it('should navigate to <eui-label> demo page', async () => {
    browser.addTestMeta({uuid:"a9412168-d4e7-11eb-b8bc-0242ac130003", zephyrKey: "CCQA-1133", zephyrStep: "411241", reportGroups: ["eUI.10x.eui"]});
    await page.open(Routing.getEUIComponentUrl('eui-label'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    await pgTitle.scrollIntoView();
    await expect(await $(pgTitle)).
      toBeDisplayedInViewport({message:'<eui-label> page title is not displayed on page'});
    await expect(await $(page.appDocPageById('eui-label'))).toExist({message:
       'Page Id is not existing on page'});
    await chaiExpect(await pgTitle.getText()).equal('eui-label', '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 presence and number of component objects <eui-label> on page ', async () => {
    browser.addTestMeta({zephyrStep: "411242"});
    let sectionId = 'Default';
    let index = 1;
    let text = 'Simple label';
    let labelByIndex1 = await (await page.labelByIndex(index).element());
    let labelByText = await (await page.labelByTextContains(text).element());
    let labelByTextAndIndex = await (await page.labelByTextEqualsAndIndex(text, index).element());
    await expect(await $(page.sectionById(sectionId))).toBeDisplayed({message:'<Default> section -> is not displayed on page'});
    await expect(labelByIndex1).toBeDisplayed({message:'Label by index '+ index +' is not displayed on page'});
    await expect(labelByText).toBeDisplayed({message:'Label by text '+ text +' is not displayed on page'});
    await expect(labelByTextAndIndex).toBeDisplayed({message:'Label by text '+ text +' and index '+ index +' is not displayed on page'});
    await chaiExpect(await page.labelByIndex(index).defaultComponentsCount()).equal(19, 'There should be 19 <eui-label> components on the page.');
    if(browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(labelByIndex1, testFolder+'img_labelByIndex1', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for labelByIndex1');
      await chaiExpect(await browser.checkElement(labelByText, testFolder+'img_labelByText', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for labelByText');
      await chaiExpect(await browser.checkElement(labelByTextAndIndex, testFolder+'img_labelByTextAndIndex', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for labelByTextAndIndex');
    }
  });

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

    let primaryLabel = await (await page.labelFromSectionWithIdByIndex(sectionId, 2).element());
    let secondaryLabel = await (await page.labelFromSectionWithIdByIndex(sectionId, 3).element());
    let successLabel = await (await page.labelFromSectionWithIdByIndex(sectionId, 4).element());
    let infoLabel = await (await page.labelFromSectionWithIdByIndex(sectionId, 5).element());
    let warningLabel = await (await page.labelFromSectionWithIdByIndex(sectionId, 6).element());
    let dangerLabel = await (await page.labelFromSectionWithIdByIndex(sectionId, 7).element());

    await expect(primaryLabel).toHaveAttrContaining('class','primary');
    await expect(secondaryLabel).toHaveAttrContaining('class','secondary');
    await expect(successLabel).toHaveAttrContaining('class','success');
    await expect(infoLabel).toHaveAttrContaining('class','info');
    await expect(warningLabel).toHaveAttrContaining('class','warning');
    await expect(dangerLabel).toHaveAttrContaining('class','danger');

    if(browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(primaryLabel, testFolder+'img_primaryLabel', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for primaryLabel');
      await chaiExpect(await browser.checkElement(secondaryLabel, testFolder+'img_secondaryLabel', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for secondaryLabel');
      await chaiExpect(await browser.checkElement(successLabel, testFolder+'img_successLabel', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for successLabel');
      await chaiExpect(await browser.checkElement(infoLabel, testFolder+'img_infoLabel', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for infoLabel');
      await chaiExpect(await browser.checkElement(warningLabel, testFolder+'img_warningLabel', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for warningLabel');
      await chaiExpect(await browser.checkElement(dangerLabel, testFolder+'img_dangerLabel', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for dangerLabel');
    }
  });

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

    let labelSize2xs = await (await page.labelFromSectionWithIdByIndex(sectionId, 2).element());
    let labelSizeXs = await (await page.labelFromSectionWithIdByIndex(sectionId, 3).element());
    let labelSizeS = await (await page.labelFromSectionWithIdByIndex(sectionId, 4).element());
    let labelSizeM = await (await page.labelFromSectionWithIdByIndex(sectionId, 5).element());
    let labelSizeL = await (await page.labelFromSectionWithIdByIndex(sectionId, 6).element());
    let labelSizeXl = await (await page.labelFromSectionWithIdByIndex(sectionId, 7).element());
    let labelSize2xl = await (await page.labelFromSectionWithIdByIndex(sectionId, 8).element());

    await expect(labelSize2xs).toHaveAttrContaining('class','size-2xs');
    await expect(labelSizeXs).toHaveAttrContaining('class','size-xs');
    await expect(labelSizeS).toHaveAttrContaining('class','size-s');
    await expect(labelSizeM).toHaveAttrContaining('class','size-m');
    await expect(labelSizeL).toHaveAttrContaining('class','size-l');
    await expect(labelSizeXl).toHaveAttrContaining('class','size-xl');
    await expect(labelSize2xl).toHaveAttrContaining('class','size-2xl');

    if(browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(labelSize2xs, testFolder+'img_labelSize2xs', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for labelSize2xs');
      await chaiExpect(await browser.checkElement(labelSizeXs, testFolder+'img_labelSizeXs', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for labelSizeXs');
      await chaiExpect(await browser.checkElement(labelSizeS, testFolder+'img_labelSizeS', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for labelSizeS');
      await chaiExpect(await browser.checkElement(labelSizeM, testFolder+'img_labelSizeM', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for labelSizeM');
      await chaiExpect(await browser.checkElement(labelSizeL, testFolder+'img_labelSizeL', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for labelSizeL');
      await chaiExpect(await browser.checkElement(labelSizeXl, testFolder+'img_labelSizeXl', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for labelSizeXl');
      await chaiExpect(await browser.checkElement(labelSize2xl, testFolder+'img_labelSize2xl', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for labelSize2xl');
    }

  });
});
