import Routing from '../../../../pages/eui/10x/routing-10x.js'
import EuiTooltipPage from '../../../../pages/eui/10x/eui/eui-tooltip-10x.po.js'
import EuiSlideTogglePage from '../../../../pages/eui/10x/eui/eui-slide-toggle-10x.po.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'

describe('eUI - <eui-tooltip> Component Object ', async () => {
  let page = new EuiTooltipPage();
  let slideToggle = new EuiSlideTogglePage();
  it('should navigate to <eui-tooltip> demo page', async () => {
    browser.addTestMeta({uuid:"399f5dcc-e3d1-11eb-ba80-0242ac130004", zephyrKey: "CCQA-1380", zephyrStep: "414540", reportGroups: ["eUI.10x.eui"]});
    await page.open(Routing.getEUIDirectivesUrl('eui-tooltip'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    await pgTitle.scrollIntoView();
    await expect(await $(pgTitle)).toBeDisplayedInViewport({message:'<eui-tooltip> page title is not visible on page'});
    await expect(await $(page.appDocPageById('eui-tooltip'))).toExist({message:'Page Id is not existing on page'});
    await expect(await pgTitle.getText()).toBe('eui-tooltip');
    await expect(await $(page.navigationList)).toBeDisplayedInViewport({message:'Navigation List -> is not visible on page'});
  });
  it('should verify the presence and number of component objects <eui-tooltip> on page ', async () => {
    browser.addTestMeta({zephyrStep: "414541"});
    let tooltip = page.tooltipByIndex(1);
    await (await $(page.buttonComponentByTextContains('Action').currentPath)).click();
    let tooltip1 = await $(tooltip.currentPath);
    await tooltip1.scrollIntoView();
    await expect(tooltip1).toBeDisplayedInViewport({message:'Tooltip by index "1" is not visible on page'});
    await expect(await $(page.tooltipByTextContains('Show').currentPath)).toBeDisplayedInViewport({message:'Tooltip by text "Show" is not visible on page'});
    await expect(await $(page.tooltipByTextEqualsAndIndex('Show', 1).currentPath)).
      toBeDisplayedInViewport({message:'Tooltip by text "Show" and index 1 is not visible on page'});
  });

  it('should verify <eui-tooltip> from Default section', async () => {
    browser.addTestMeta({zephyrStep: "414542"});
    let sectionId = 'Default';
    let sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();
    let tooltip1 = page.tooltipFromSectionWithIdByIndex(sectionId,1);
    await (await $(tooltip1.currentPath)).click();
    await expect(await $(tooltip1.currentPath)).toBeDisplayedInViewport({message:'Tooltip is not visible on page'});
    await expect(await tooltip1.hasArrows()).toBe(true);
    await expect(await tooltip1.hasContent()).toBe(true);
  });

  it('should verify <eui-tooltip> color states', async () => {
    browser.addTestMeta({zephyrStep: "414543"});
    let sectionId = 'typeclass';
    let sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();
    let tooltip1 = page.tooltipFromSectionWithIdByIndex(sectionId,1);
    await (await $(tooltip1.currentPath)).click();
    await expect(await $(tooltip1.currentPath)).toBeDisplayedInViewport({message:'Tooltip 1 from color states section is not visible on page'});
    tooltip1 = page.tooltipFromSectionWithIdByIndex(sectionId,2);
    await (await $(tooltip1.currentPath)).click();
    await expect(await $(tooltip1.currentPath)).toBeDisplayedInViewport({message:'Tooltip 2 from color states section is not visible on page'});
    await expect(await tooltip1.isPrimary()).toBe(true);
    tooltip1 = page.tooltipFromSectionWithIdByIndex(sectionId,3);
    await (await $(tooltip1.currentPath)).click();
    await expect(await $(tooltip1.currentPath)).toBeDisplayedInViewport({message:'Tooltip 3 from color states section is not visible on page'});
    await expect(await tooltip1.isSecondary()).toBe(true);
    tooltip1 = page.tooltipFromSectionWithIdByIndex(sectionId,4);
    await (await $(tooltip1.currentPath)).click();
    await expect(await $(tooltip1.currentPath)).toBeDisplayedInViewport({message:'Tooltip 4 from color states section is not visible on page'});
    await expect(await tooltip1.hasInfo()).toBe(true);
    tooltip1 = page.tooltipFromSectionWithIdByIndex(sectionId,5);
    await (await $(tooltip1.currentPath)).click();
    await expect(await $(tooltip1.currentPath)).toBeDisplayedInViewport({message:'Tooltip 5 from color states section is not visible on page'});
    await expect(await tooltip1.hasSuccess()).toBe(true);
    tooltip1 = page.tooltipFromSectionWithIdByIndex(sectionId,6);
    await (await $(tooltip1.currentPath)).click();
    await expect(await $(tooltip1.currentPath)).toBeDisplayedInViewport({message:'Tooltip 6 from color states section is not visible on page'});
    await expect(await tooltip1.hasWarning()).toBe(true);
    tooltip1 = page.tooltipFromSectionWithIdByIndex(sectionId,7);
    await (await $(tooltip1.currentPath)).click();
    await expect(await $(tooltip1.currentPath)).toBeDisplayedInViewport({message:'Tooltip 7 from color states section is not visible on page'});
    await expect(await tooltip1.hasDanger()).toBe(true);
    tooltip1 = page.tooltipFromSectionWithIdByIndex(sectionId,8);
    await (await $(tooltip1.currentPath)).click();
    await expect(await $(tooltip1.currentPath)).toBeDisplayedInViewport({message:'Tooltip 8 from color states section is not visible on page'});
    await expect(await tooltip1.hasAccent()).toBe(true);
  });

  it('should verify <eui-tooltip> content alignment', async () => {
    browser.addTestMeta({zephyrStep: "414544"});
    let sectionId = 'content-align';
    let sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();
    let tooltip1 = page.tooltipFromSectionWithIdByIndex(sectionId,1);
    await (await $(tooltip1.currentPath)).click();
    await expect(await $(tooltip1.currentPath)).toBeDisplayedInViewport({message:'Tooltip 1 from content align section is not visible on page'});
    await expect(await tooltip1.hasContentLeft()).toBe(true);
    tooltip1 = page.tooltipFromSectionWithIdByIndex(sectionId,2);
    await (await $(tooltip1.currentPath)).click();
    await expect(await $(tooltip1.currentPath)).toBeDisplayedInViewport({message:'Tooltip 2 from content align section is not visible on page'});
    await expect(await tooltip1.hasContentRight()).toBe(true);
    tooltip1 = page.tooltipFromSectionWithIdByIndex(sectionId,3);
    await (await $(tooltip1.currentPath)).click();
    await expect(await $(tooltip1.currentPath)).toBeDisplayedInViewport({message:'Tooltip 3 from content align section is not visible on page'});
    await expect(await tooltip1.hasContentCenter()).toBe(true);
    tooltip1 = page.tooltipFromSectionWithIdByIndex(sectionId,4);
    await (await $(tooltip1.currentPath)).click();
    await expect(await $(tooltip1.currentPath)).toBeDisplayedInViewport({message:'Tooltip 4 from content align section is not visible on page'});
    await expect(await tooltip1.hasContentJustify()).toBe(true);
  });

  it('should verify <eui-tooltip> show / hide & delay', async () => {
    browser.addTestMeta({zephyrStep: "414545"});
    let sectionId = 'delay';
    let sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();
    let tooltip = page.tooltipFromSectionWithIdByIndex(sectionId,3);
    await (await $(page.buttonComponentByTextAndIndex('Show',2).currentPath)).click();
    await expect(await $(tooltip.currentPath)).toBeDisplayedInViewport({message:'Tooltip from delay section is not visible on page'});
  });

  it('should verify <eui-tooltip> Styling', async () => {
    browser.addTestMeta({zephyrStep: "414546"});
    let sectionId = 'styling';
    let sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();
    let tooltip1 = page.tooltipFromSectionWithIdByIndex(sectionId,1);
    await (await $(tooltip1.currentPath)).click();
    await expect(await $(tooltip1.currentPath)).toBeDisplayedInViewport({message:'Tooltip 1 from styling section is not visible on page'});
    await expect(await tooltip1.hasRounded()).toBe(true);
    await (await $(slideToggle.slideToggleFromSectionById(sectionId).currentPath)).click();
    await (await $(tooltip1.currentPath)).click();
    await expect(await tooltip1.hasRounded()).toBe(false);
  });

  it('should verify <eui-tooltip> Tooltip disabled', async () => {
    browser.addTestMeta({zephyrStep: "414547"});
    let sectionId = 'disabled';
    let sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();
    let tooltip1 = page.tooltipFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(tooltip1.currentPath)).toBeDisplayedInViewport({message:'Tooltip from disabled section is not visible on page'});
    await expect(await tooltip1.isDisabled()).toBe(true);
    await (await $(slideToggle.slideToggleFromSectionById(sectionId).currentPath)).click();
    await (await $(tooltip1.currentPath)).click();
    await expect(await tooltip1.isDisabled()).toBe(false);
  });

  it('should verify <eui-tooltip> Tooltip position', async () => {
    browser.addTestMeta({zephyrStep: "414548"});
    let sectionId = 'position';
    let sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();
    let tooltip1 = page.tooltipFromSectionWithIdByIndex(sectionId,1);
    await (await $(tooltip1.currentPath)).click();
    await expect(await $(tooltip1.currentPath)).toBeDisplayedInViewport({message:'Tooltip from position section is not visible on page'});
    await expect(await tooltip1.hasPositionAbove()).toBe(true);
    tooltip1 = page.tooltipFromSectionWithIdByIndex(sectionId,2);
    await (await $(tooltip1.currentPath)).click();
    await expect(await $(tooltip1.currentPath)).toBeDisplayedInViewport({message:'Tooltip from position section is not visible on page'});
    await expect(await tooltip1.hasPositionLeft()).toBe(true);
    tooltip1 = page.tooltipFromSectionWithIdByIndex(sectionId,3);
    await (await $(tooltip1.currentPath)).click();
    await expect(await $(tooltip1.currentPath)). toBeDisplayedInViewport({message:'Tooltip from position section is not visible on page'});
    await expect(await tooltip1.hasPositionBefore()).toBe(true);
    tooltip1 = page.tooltipFromSectionWithIdByIndex(sectionId,4);
    await (await $(tooltip1.currentPath)).click();
    await expect(await $(tooltip1.currentPath)).toBeDisplayedInViewport({message:'Tooltip from position section is not visible on page'});
    await expect(await tooltip1.hasPositionRight()).toBe(true);
    tooltip1 = page.tooltipFromSectionWithIdByIndex(sectionId,5);
    await (await $(tooltip1.currentPath)).click();
    await expect(await $(tooltip1.currentPath)).toBeDisplayedInViewport({message:'Tooltip from position section is not visible on page'});
    await expect(await tooltip1.hasPositionAfter()).toBe(true);
    tooltip1 = page.tooltipFromSectionWithIdByIndex(sectionId,6);
    await (await $(tooltip1.currentPath)).click();
    await expect(await $(tooltip1.currentPath)).toBeDisplayedInViewport({message:'Tooltip from position section is not visible on page'});
    await expect(await tooltip1.hasPositionBelow()).toBe(true);
  });

});
