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

describe('eUI - <eui-tabs> Component Object ',async () => {
  let page = new EuiTabsPage();
  let testFolder = './/v14x//eui-tabs//';
  let pageName = 'eui-tabs'
  it('should navigate to <eui-tabs> demo page',async () => {
    browser.addTestMeta({uuid:"eb8e3d66-ee1a-11eb-9a03-0242ac130003", zephyrKey: "CCQA-1462", zephyrStep: "417033", reportGroups: ["eUI.14x.eui"]});
    await page.open(Routing.getEUIComponentUrl('eui-tabs'));
    await CookieBannerActions.cookieBanner(true);
    await BaseActions.verifyPageTitle(pageName);
    await expect(await $(page.navigationList)).toBeDisplayedInViewport({wait:3000,message:'Navigation List -> is not displayed on page'});
  });
  it('should verify the presence and number of component objects <eui-tabs> on page ',async () => {
    browser.addTestMeta({zephyrStep: "417034"});
    let sectionId= 'Default';
    await BaseActions.verifySection(sectionId, pageName);
    let tabs = page.euiTabsCO.byIndex(1);
    await expect(await $(tabs.currentPath)).toBeDisplayedInViewport({wait:3000,message:'Tabs by index "1" is not displayed on page'});
    await expect(await $(page.euiTabsCO.byTextContains('Tab 1').currentPath)).toBeDisplayedInViewport({wait:3000,message:'Tabs by text "Tab 1" is not displayed on page'});
    await expect(await $(page.euiTabsCO.byTextEqualsAndIndex('Tab 1', 1).currentPath)).
      toBeDisplayedInViewport({wait:3000,message:'Tabs by text "Tab 1" and index 1 is not displayed on page'});
  });

  it('should verify <eui-tabs> methods : dataE2E, items, wrapper ',async () => {
    browser.addTestMeta({zephyrStep: "417035"});
    let sectionId= 'Default';
    await BaseActions.verifySection(sectionId, pageName);
    let imageComparisonTabs =await (await page.tabsFromSectionWithIdByIndex(sectionId, 1).element());
    if(browser.config.useWdioImageComparison) {
      await imageComparisonTabs.scrollIntoView();
      await chaiExpect(await browser.checkElement(imageComparisonTabs, testFolder+'img_tabsByIndex1',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_tabsByIndex1');
    }
    let tabs = page.euiTabsCO.byIndex(2);
    await expect(await $(tabs.dataE2E)).toBeDisplayedInViewport({wait:3000,message:'dataE2E is not displayed on page'});
    await expect(await $(tabs.items)).toBeDisplayedInViewport({wait:3000,message:'items is not displayed on page'});
    await expect(await $(tabs.wrapper)).toBeDisplayedInViewport({wait:3000,message:'wrapper is not displayed on page'});
  });

  it('should verify <eui-tabs> methods : isMainNavigation, isVerticalTabs, hasScrolling ',async () => {
    browser.addTestMeta({zephyrStep: "417036"});
    let sectionId= 'isMainNavigation';
    await BaseActions.verifySection(sectionId, pageName);
    let tabs = page.tabsFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(tabs.items)).toBeDisplayedInViewport({wait:3000,message:'items is not displayed on page'});
    await chaiExpect(await tabs.isMainNavigation()).equal(true, 'tabs should have Main Navigation');
    sectionId= 'vertical-tabs';
    sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();
    tabs = page.tabsFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(tabs.items)).toBeDisplayedInViewport({wait:3000,message:'items is not displayed on page'});
    await chaiExpect(await tabs.isVerticalTabs()).equal(true, 'Tabs CO should have vertical tabs');
    sectionId= 'card';
    sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();
    tabs = page.tabsFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(tabs.items)).toBeDisplayedInViewport({wait:3000,message:'items is not displayed on page'});
    await chaiExpect(await tabs.hasScrolling()).equal(false, 'Tabs CO should not have scrolling');
    tabs = page.tabsFromSectionWithIdByIndex(sectionId,2);
    await expect(await $(tabs.items)).toBeDisplayedInViewport({wait:3000,message:'items is not displayed on page'});
    await chaiExpect(await tabs.hasScrolling()).equal(true, 'Tabs CO should have scrolling');
  });

  it('should verify <eui-tabs> methods : rightContent',async () => {
    browser.addTestMeta({zephyrStep: "417037"});
    let sectionId= 'content-euiTabsRightContent';
    await BaseActions.verifySection(sectionId, pageName);
    let tabs = page.tabsFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(tabs.rightContent)).toBeExisting({wait:3000,message:'rightContent doesn\'t exist on page'});
  });

  it('should verify <eui-tabs> methods : navigation, navigationLeftItem, navigationRightItem, angleRightIcon, angleLeftIcon ',async () => {
    browser.addTestMeta({zephyrStep: "417038"});
    let sectionId= 'isMainNavigation';
    await BaseActions.verifySection(sectionId, pageName);
    let tabs = page.tabsFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(tabs.navigation)).toExist({message:'navigation is not existing on page'});
    sectionId= 'card';
    sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();
    tabs = page.tabsFromSectionWithIdByIndex(sectionId,2);
    await expect(await $(tabs.navigationLeftItem)).toBeDisplayedInViewport({wait:3000,message:'navigationLeftItem is not displayed on page'});
    await expect(await $(tabs.navigationRightItem)).toBeDisplayedInViewport({wait:3000,message:'navigationRightItem is not displayed on page'});
    await (await $(tabs.angleRightIcon)).click();
    await (await $(tabs.angleLeftIcon)).click();
  });

  it('should verify <eui-tabs> and <eui-tabb-item> methods : euiTabItemCO, isClosable, isActive, isDisabled ',async () => {
    browser.addTestMeta({zephyrStep: "417039"});
    let sectionId = 'Default';
    await BaseActions.verifySection(sectionId, pageName);
    let tabs = page.tabsFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(tabs.euiTabItemCO.currentPath)).toBeDisplayedInViewport({wait:3000,message:'euiTabItemCO currentPath is not displayed on page'});
    sectionId= 'isClosable';
    sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();
    tabs = page.tabsFromSectionWithIdByIndex(sectionId,1);
    await chaiExpect(await tabs.euiTabItemCO.byIndex(1).isClosable()).equal(true, 'Tabs CO should be closable');
    await chaiExpect(await tabs.euiTabItemCO.byIndex(1).isActive()).equal(true, 'Tabs CO should be active');
    await chaiExpect(await tabs.euiTabItemCO.byIndex(1).isDisabled()).equal(false, 'Tabs CO should not be disabled');
    sectionId= 'isDisabled';
    sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();
    tabs = page.tabsFromSectionWithIdByIndex(sectionId,1);
    await chaiExpect(await tabs.euiTabItemCO.byIndex(2).isDisabled()).equal(true, 'Tabs CO should be disabled');
    await chaiExpect(await tabs.euiTabItemCO.byIndex(2).isActive()).equal(false, 'Tabs CO should not be active');
  });

  it('should verify <eui-tab-item> methods : hasBackgroundFilled, severity',async () => {
    browser.addTestMeta({zephyrStep: "417040"});
    let sectionId= 'hasBackgroundFilled';
    await BaseActions.verifySection(sectionId, pageName);
    let imageComparisonTabs = await (await page.tabsFromSectionWithIdByIndex(sectionId, 1).element());
    if(browser.config.useWdioImageComparison) {
      await imageComparisonTabs.scrollIntoView();
      await chaiExpect(await browser.checkElement(imageComparisonTabs, testFolder+'img_tabs_hasBackground_ByIndex1',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_tabs_hasBackground_ByIndex1');
    }
    let tabs = page.tabsFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(tabs.euiTabItemCO.currentPath)).
      toBeDisplayedInViewport({wait:3000,message:'euiTabItemCO currentPath is not displayed on page'});
    await chaiExpect(await tabs.euiTabItemCO.byIndex(2).severity()).equal('secondary', 'Tab severity should be secondary.');
    await chaiExpect(await tabs.euiTabItemCO.byIndex(1).severity()).equal('primary', 'Tab severity should be primary.');
    await chaiExpect(await tabs.euiTabItemCO.byIndex(3).severity()).equal('info', 'Tab severity should be info.');
    await chaiExpect(await tabs.euiTabItemCO.byIndex(4).severity()).equal('success', 'Tab severity should be success.');
    await chaiExpect(await tabs.euiTabItemCO.byIndex(5).severity()).equal('warning', 'Tab severity should be warning.');
    await chaiExpect(await tabs.euiTabItemCO.byIndex(6).severity()).equal('danger', 'Tab severity should be danger.');
    await chaiExpect(await tabs.euiTabItemCO.byIndex(7).severity()).equal('accent', 'Tab severity should be accent.');
    await chaiExpect(await tabs.euiTabItemCO.byIndex(1).hasBackgroundFilled()).equal(true, 'Tab should have background filled.');
  });

  it('should verify <eui-tab-item> methods : label, closeIcon, hasCloseIcon',async () => {
    browser.addTestMeta({zephyrStep: "417041"});
    let sectionId= 'isClosable';
    await BaseActions.verifySection(sectionId, pageName);
    let imageComparisonTabs = await (await page.tabsFromSectionWithIdByIndex(sectionId, 1).element());
    if(browser.config.useWdioImageComparison) {
      await imageComparisonTabs.scrollIntoView();
      await chaiExpect(await browser.checkElement(imageComparisonTabs, testFolder+'img_tabs_isClosable_ByIndex1',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_tabs_isClosable_ByIndex1');
    }
    let sectionElement = await $(page.sectionById(sectionId));
    await sectionElement.scrollIntoView();
    let tabs = page.tabsFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(tabs.euiTabItemCO.label)).
      toBeDisplayedInViewport({wait:3000,message:'euiTabItemCO label is not displayed on page'});
    await expect(await $(tabs.euiTabItemCO.label)).toHaveText('Tab 1');
    await expect(await $(tabs.euiTabItemCO.byIndex(3).closeIcon)).
      toBeDisplayedInViewport({wait:3000,message:'euiTabItemCO closeIcon is not displayed on page'});
    await chaiExpect(await tabs.euiTabItemCO.byIndex(3).hasCloseIcon()).equal(true, 'Tab should have close icon.');
    await (await $(tabs.euiTabItemCO.byIndex(3).closeIcon)).click();
    await expect(await $(tabs.euiTabItemCO.byIndex(3).closeIcon)).not.
      toBeDisplayedInViewport({wait:3000,message:'euiTabItemCO closeIcon is displayed on page'});
    await chaiExpect(await tabs.euiTabItemCO.byIndex(3).hasCloseIcon()).equal(false, 'Tab should not have close icon.');
  });

  it('should verify <eui-tab-content>',async () => {
    browser.addTestMeta({zephyrStep: "417042"});
    let sectionId= 'Default';
    await BaseActions.verifySection(sectionId, pageName);
    let tabs = page.tabsFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(tabs.euiTabContentCO.currentPath)).
      toBeDisplayedInViewport({wait:3000,message:'euiTabItemCO currentPath is not displayed on page'});
  });

  it('should verify action add tab',async () => {
    browser.addTestMeta({zephyrStep: "417043"});
    let sectionId= 'tabs-interaction';
    await BaseActions.verifySection(sectionId, pageName);
    let tabs = page.tabsFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(tabs.euiTabItemCO.byIndex(3).currentPath)).
      toBeDisplayedInViewport({wait:3000,message:'euiTabItemCO.byIndex(3) currentPath is not displayed on page'});
    await expect(await $(tabs.euiTabItemCO.byIndex(4).currentPath)).not.
      toBeDisplayedInViewport({wait:3000,message:'euiTabItemCO.byIndex(4) currentPath is displayed on page'});
    await (await $(page.buttonComponentByTextContains('Add tab').currentPath)).click();
    await expect(await $(tabs.euiTabItemCO.byIndex(4).currentPath)).
      toBeDisplayedInViewport({wait:3000,message:'euiTabItemCO.byIndex(4) currentPath is not displayed on page'});
    tabs = page.tabsFromSectionWithIdByIndex(sectionId,2);
    await expect(await $(tabs.euiTabItemCO.byIndex(4).currentPath)).not.
      toBeDisplayedInViewport({wait:3000,message:'euiTabItemCO.byIndex(4) currentPath is displayed on page'});
    await (await $(page.buttonComponentByTextContains('Insert tab').currentPath)).click();
    await expect(await $(tabs.euiTabItemCO.byIndex(4).currentPath)).
      toBeDisplayedInViewport({wait:3000,message:'euiTabItemCO.byIndex(4) currentPath is not displayed on page'});
    await expect(await $(tabs.euiTabItemCO.byIndex(5).currentPath)).not.
      toBeDisplayedInViewport({wait:3000,message:'euiTabItemCO.byIndex(5) currentPath is displayed on page'});
  });

  it('should verify eui-tabs with chips',async () => {
    browser.addTestMeta({zephyrStep: "417044"});
    let sectionId= 'with-chip';
    let sectionElement = await $(page.sectionById(sectionId));
    let imageComparisonTabs = await (await page.tabsFromSectionWithIdByIndex(sectionId, 1).element());
    if(browser.config.useWdioImageComparison) {
      await imageComparisonTabs.scrollIntoView();
      await chaiExpect(await browser.checkElement(imageComparisonTabs, testFolder+'img_tabs_withChip_ByIndex1',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_tabs_withChip_ByIndex1');
    }
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();
    let tabs = page.tabsFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(new CoEuiChip(tabs.euiTabItemCO.byIndex(1).label).currentPath)).
      toBeDisplayedInViewport({wait:3000,message:'euiChipCO currentPath is not displayed on page'});
    await expect(await $(new CoEuiChip(tabs.euiTabItemCO.byIndex(1).label).container)).
      toBeDisplayedInViewport({wait:3000,message:'euiChipCO container is not displayed on page'});
    imageComparisonTabs = await (await page.tabsFromSectionWithIdByIndex('vertical-tabs', 1).element());
    if(browser.config.useWdioImageComparison) {
      await imageComparisonTabs.scrollIntoView();
      await chaiExpect(await browser.checkElement(imageComparisonTabs, testFolder+'img_tabs_vertical_ByIndex1',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_tabs_vertical_ByIndex1');
    }
  });
});
