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

describe('eUI - <eui-chip> Component Object ', async () => {
  let page = new EuiChipPage();
  let testFolder = './/v14x//eui-chip//';
  let pageName = 'eui-chip'
  it('should navigate to <eui-chip> demo page', async () => {
    browser.addTestMeta({uuid:"28b8ade2-d292-11eb-b8bc-0242ac130003", zephyrKey: "CCQA-1121", zephyrStep: "410028", reportGroups: ["eUI.14x.eui"]});
    await page.open(Routing.getEUIComponentUrl('eui-chip'));
    await CookieBannerActions.cookieBanner(true);
    await BaseActions.verifyPageTitle(pageName);
    await expect(await $(page.navigationList)).toBeDisplayedInViewport({wait: 2000, message:'Navigation List -> is not displayed on page'});
  });
  it('should verify the presence and number of component objects <eui-chip> on page ', async () => {
    browser.addTestMeta({zephyrStep: "410029"});
    let sectionId= 'Default';
    await BaseActions.verifySection(sectionId, pageName);
    let chip = page.chipByIndex(1);
    await (await chip.element()).scrollIntoView();
    await expect(await $(chip.currentPath)).toBeDisplayed({wait: 2000, message:'Chip by index "1" is not displayed on page'});
    await expect(await $(page.chipByTextContains('Chip label').currentPath)).toBeDisplayed({wait: 2000, message:'Chip by text "Chip label" is not displayed on page'});
    await expect(await $(page.chipByTextEqualsAndIndex('Chip label', 1).currentPath)).toBeDisplayed({wait: 2000, message:'Chip by text "Chip label" and index 1 is not displayed on page'});
  });
  it('should verify the methods container, matChipCO, removeIcon, isChipRemovable ', async () => {
    browser.addTestMeta({zephyrStep: "410030"});
    let sectionId = 'Default';
    await BaseActions.verifySection(sectionId, pageName);
    let imageComparisonChip = await (await page.chipFromSectionById('Default').byIndex(1).element());
    if(browser.config.useWdioImageComparison) {
      await imageComparisonChip.scrollIntoView();
      await chaiExpect(await browser.checkElement(imageComparisonChip, testFolder+'img_chipByIndex1',
        {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_chipByIndex1');
    }
    let chip = page.chipFromSectionById(sectionId);
    await expect(await $(chip.wrapper)).toBeDisplayedInViewport({wait: 2000, message:'Chip wrapper currentPath is not displayed on page'});
    await expect(await $(chip.container)).toBeDisplayedInViewport({wait: 2000, message:'Chip container is not displayed on page'});

    sectionId = 'isChipRemovable';
    await BaseActions.verifySection(sectionId, pageName);
    chip = page.chipFromSectionById(sectionId);
    await expect(await $(chip.removeIcon.currentPath)).toBeDisplayedInViewport({wait: 2000, message:'Chip removeIcon is not displayed on page'});
    await chaiExpect(await chip.isChipRemovable()).equal(true, 'Chip should be removable.');
  });
  it('should verify color states ', async () => {
    browser.addTestMeta({zephyrStep: "413195"});
    let sectionId = 'color-states';
    await BaseActions.verifySection(sectionId, pageName);
    await expect(await $(page.chipFromSectionWithIdByIndex(sectionId, 1).currentPath)).toHaveAttrContaining('class', 'eui-chip--primary');
    await expect(await $(page.chipFromSectionWithIdByIndex(sectionId, 2).currentPath)).toHaveAttrContaining('class', 'eui-chip--secondary');
    await expect(await $(page.chipFromSectionWithIdByIndex(sectionId, 3).currentPath)).toHaveAttrContaining('class', 'eui-chip--info');
    await expect(await $(page.chipFromSectionWithIdByIndex(sectionId, 4).currentPath)).toHaveAttrContaining('class', 'eui-chip--success');
    await expect(await $(page.chipFromSectionWithIdByIndex(sectionId, 5).currentPath)).toHaveAttrContaining('class', 'eui-chip--warning');
    await expect(await $(page.chipFromSectionWithIdByIndex(sectionId, 6).currentPath)).toHaveAttrContaining('class', 'eui-chip--danger');
    await expect(await $(page.chipFromSectionWithIdByIndex(sectionId, 7).currentPath)).toHaveAttrContaining('class', 'eui-chip--accent');
  });
  it('should verify Event Handlers ', async () => {
    browser.addTestMeta({zephyrStep: "413197"});
    let sectionId = 'event-handlers';
    await BaseActions.verifySection(sectionId, pageName);
    await expect(await $(page.chipFromSectionWithIdByIndex(sectionId, 4).removeIcon.currentPath)).
      toBeDisplayedInViewport({wait: 2000, message:'Chip removeIcon by index 4 in <event-handlers> section is not displayed on page'});
    await chaiExpect(await page.chipFromSectionWithIdByIndex(sectionId, 4).isChipRemovable()).equal(true, 'Chip should be removable.');
    await (await $(page.chipFromSectionWithIdByIndex(sectionId, 4).removeIcon.currentPath)).click();
    await expect(await $('//pre')).toHaveTextContaining(' "id": 4');
  });
  //not valid for v14
  xit('should verify icon position of a chip', async () => {
    browser.addTestMeta({zephyrStep: "413198"});
    let sectionId = 'icons';
    await BaseActions.verifySection(sectionId, pageName);
    await expect(await $(page.chipFromSectionWithIdByIndex(sectionId, 1).currentPath)).toHaveAttrContaining('class', 'eui-chip--icon-before');
    await expect(await $(page.chipFromSectionWithIdByIndex(sectionId, 8).currentPath)).toHaveAttrContaining('class', 'eui-chip--icon-after');
  });
  it('should verify outline chip', async () => {
    browser.addTestMeta({zephyrStep: "413199"});
    let sectionId = 'outline';
    await BaseActions.verifySection(sectionId, pageName);
    let imageComparisonChipPrim = await (await page.chipFromSectionById(sectionId).byIndex(1).element());
    let imageComparisonChipSec = await (await page.chipFromSectionById(sectionId).byIndex(2).element());
    let imageComparisonChipInfo = await (await page.chipFromSectionById(sectionId).byIndex(3).element());
    let imageComparisonChipSucc = await (await page.chipFromSectionById(sectionId).byIndex(4).element());
    let imageComparisonChipWarn = await (await page.chipFromSectionById(sectionId).byIndex(5).element());
    let imageComparisonChipDang = await (await page.chipFromSectionById(sectionId).byIndex(6).element());
    let imageComparisonChipAcce = await (await page.chipFromSectionById(sectionId).byIndex(7).element());
    if(browser.config.useWdioImageComparison) {
      await imageComparisonChipPrim.scrollIntoView();
      await chaiExpect(await browser.checkElement(imageComparisonChipPrim, testFolder+'img_chipByIndex1_Out_Prim',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_chipByIndex1_Out_Prim');
      await chaiExpect(await browser.checkElement(imageComparisonChipSec, testFolder+'img_chipByIndex2_Out_Sec',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_chipByIndex2_Out_Sec');
      await chaiExpect(await browser.checkElement(imageComparisonChipInfo, testFolder+'img_chipByIndex3_Out_Info',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_chipByIndex3_Out_Info');
      await chaiExpect(await browser.checkElement(imageComparisonChipSucc, testFolder+'img_chipByIndex4_Out_Succ',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_chipByIndex4_Out_Succ');
      await chaiExpect(await browser.checkElement(imageComparisonChipWarn, testFolder+'img_chipByIndex5_Out_Warn',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_chipByIndex5_Out_Warn');
      await chaiExpect(await browser.checkElement(imageComparisonChipDang, testFolder+'img_chipByIndex6_Out_Dang',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_chipByIndex6_Out_Dang');
      await chaiExpect(await browser.checkElement(imageComparisonChipAcce, testFolder+'img_chipByIndex7_Out_Acce',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_chipByIndex7_Out_Acce');
    }
    await expect(await $(page.chipFromSectionWithIdByIndex(sectionId, 1).currentPath)).toHaveAttrContaining('class', 'eui-chip--outline');
  });
  it('should verify removable chip', async () => {
    browser.addTestMeta({zephyrStep: "413200"});
    let sectionId = 'isChipRemovable';
    await BaseActions.verifySection(sectionId, pageName);
    await chaiExpect(await page.chipFromSectionWithIdByIndex(sectionId, 1).isChipRemovable()).equal(true, 'Chip should be removable.');
    sectionId = 'Default';
    await BaseActions.verifySection(sectionId, pageName);
    await chaiExpect(await page.chipFromSectionWithIdByIndex(sectionId, 1).isChipRemovable()).equal(false, 'Chip should not be removable.');
  });
  it('should verify is-squared', async () => {
    browser.addTestMeta({zephyrStep: "413201"});
    let sectionId = 'is-squared';
    await BaseActions.verifySection(sectionId, pageName);
    let imageComparisonChipPrim = await (await page.chipFromSectionById(sectionId).byIndex(1).element());
    let imageComparisonChipSec = await (await page.chipFromSectionById(sectionId).byIndex(2).element());
    let imageComparisonChipInfo = await (await page.chipFromSectionById(sectionId).byIndex(3).element());
    let imageComparisonChipSucc = await (await page.chipFromSectionById(sectionId).byIndex(4).element());
    let imageComparisonChipWarn = await (await page.chipFromSectionById(sectionId).byIndex(5).element());
    let imageComparisonChipDang = await (await page.chipFromSectionById(sectionId).byIndex(6).element());
    let imageComparisonChipAcce = await (await page.chipFromSectionById(sectionId).byIndex(7).element());
    if(browser.config.useWdioImageComparison) {
      await imageComparisonChipPrim.scrollIntoView();
      await chaiExpect(await browser.checkElement(imageComparisonChipPrim, testFolder+'img_chipByIndex1_squared_Prim',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_chipByIndex1_squared_Prim');
      await chaiExpect(await browser.checkElement(imageComparisonChipSec, testFolder+'img_chipByIndex2_squared_Sec',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_chipByIndex2_squared_Sec');
      await chaiExpect(await browser.checkElement(imageComparisonChipInfo, testFolder+'img_chipByIndex3_squared_Info',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_chipByIndex3_squared_Info');
      await chaiExpect(await browser.checkElement(imageComparisonChipSucc, testFolder+'img_chipByIndex4_squared_Succ',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_chipByIndex4_squared_Succ');
      await chaiExpect(await browser.checkElement(imageComparisonChipWarn, testFolder+'img_chipByIndex5_squared_Warn',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_chipByIndex5_squared_Warn');
      await chaiExpect(await browser.checkElement(imageComparisonChipDang, testFolder+'img_chipByIndex6_squared_Dang',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_chipByIndex6_squared_Dang');
      await chaiExpect(await browser.checkElement(imageComparisonChipAcce, testFolder+'img_chipByIndex7_squared_Acce',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_chipByIndex7_squared_Acce');
    }
    await expect(await $(page.chipFromSectionWithIdByIndex(sectionId, 1).currentPath)).toHaveAttrContaining('class', 'eui-chip--squared');
  });
  it('should verify chip sizes', async () => {
    browser.addTestMeta({zephyrStep: "413202"});
    let sectionId = 'sizes';
    await BaseActions.verifySection(sectionId, pageName);
    await expect(await $(page.chipFromSectionWithIdByIndex(sectionId,1).currentPath)).toHaveAttrContaining('class', 'eui-chip--size-xs');
    await expect(await $(page.chipFromSectionWithIdByIndex(sectionId,36).currentPath)).toHaveAttrContaining('class', 'eui-chip--size-s');
    await expect(await $(page.chipFromSectionWithIdByIndex(sectionId,72).currentPath)).toHaveAttrContaining('class', 'eui-chip--size-m');
    await expect(await $(page.chipFromSectionWithIdByIndex(sectionId,108).currentPath)).toHaveAttrContaining('class', 'eui-chip--size-l');
  });
  it('should verify chip tooltip', async () => {
    browser.addTestMeta({zephyrStep: "413203"});
    let sectionId = 'tooltip';
    await BaseActions.verifySection(sectionId, pageName);
    await expect(await $(page.chipFromSectionWithIdByIndex(sectionId, 1).currentPath)).toHaveAttrContaining('class', 'eui-tooltip');
  });
});
