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

describe('eUI - <eui-label> Component Object ', async () => {
  let page = new EuiLabelPage();
  let testFolder = './/v14x//eui-label//';
  let pageName = '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.14x.eui"] });
    await page.open(Routing.getEUIComponentUrl('eui-label'));
    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-label> on page ', async () => {
    browser.addTestMeta({ zephyrStep: "411242" });
    let sectionId = 'Default';
    await BaseActions.verifySection(sectionId, pageName);
    let index = 1;
    let text = 'Sample 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 labelByIndex1.scrollIntoView();
    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(37, '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';
    await BaseActions.verifySection(sectionId, pageName);

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

    let labelSizeM = await (await page.labelFromSectionWithIdByIndex(sectionId, 2).element());
    let labelSizeS = await (await page.labelFromSectionWithIdByIndex(sectionId, 3).element());

    await expect(labelSizeM).toHaveAttrContaining('class', 'size-m');
    await expect(labelSizeS).toHaveAttrContaining('class', 'size-s');

    if (browser.config.useWdioImageComparison) {
      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');
    }

  });
  it('should verify the <eui-label> with sublabel ', async () => {
    browser.addTestMeta({ zephyrStep: "504991" });
    let sectionId = 'sublabel';
    await BaseActions.verifySection(sectionId, pageName);

    let subLabel = page.labelFromSectionWithIdByIndex(sectionId, 3);
    await expect(await subLabel.element()).toExist({ message: 'SubLabel is not existing on page' });
    await expect(await subLabel.element()).toBeDisplayed({ message: 'SubLabel is not displayed on page' });
    await chaiExpect(await subLabel.isSubLabel()).equal(true, 'isSubLabel is not true');

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

  });
});
