import Routing from '../../../../pages/eui/10x/routing-10x.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'
import PopoverPage from '../../../../pages/eui/10x/ux/ux-popover-10x.po.js'

describe('eUI - <ux-popover> Component Object', async () => {
  let poopoverPage = new PopoverPage();
  it('should navigate to <ux-popover> component', async () => {
    browser.addTestMeta({uuid:"ed6ea178-b703-11eb-8529-0242ac130003", zephyrKey: "CCQA-772", zephyrStep: "366707", reportGroups: ["eUI.10x.ux"]});
    await poopoverPage.open(Routing.getUxComponentUrl('ux-popover'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(poopoverPage.pageTitle);
    let appDocPageId = await $(poopoverPage.appDocPageById('ux-popover'));
    let navigationList = await $(poopoverPage.navigationList);

    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-popover> page title is not visible on page'});
    await expect(pgTitle).toHaveText('ux-popover', {wait: 1000, message: 'Page title text is not as expected'});
    await expect(appDocPageId).toExist({wait:1000, message:'Page Id is not present in page'});
    await expect(navigationList).toBeDisplayed({wait:1000, message:'Navigation List -> is not visible on page'});
  });
  it('should identify <ux-popover>  with methods:  popoverByIndex, popoverByTextContains, popoverByTextEqualsAndIndex ', async () => {
    browser.addTestMeta({zephyrStep: "366708"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(poopoverPage.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let icon = await $("//eui-showcase-doc-sample[@id='"+sectionId+"']//i");
    await expect(icon).toBeDisplayedInViewport({message:'Icon is not visible on page'});
    await icon.click();
    let popover = poopoverPage.popoverByIndex(1);
    await expect(await $(popover.currentPath)).toBeDisplayedInViewport({message:'Popover by index 1 is not visible on page'});
    await expect(await $(poopoverPage.popoverByTextContains('This is popover title').currentPath)).
      toBeDisplayedInViewport({message:'Popover by text "This is popover title" is not visible on page'});
    await expect(await $(poopoverPage.popoverByTextEqualsAndIndex('This is popover title', 1).currentPath)).
     toBeDisplayedInViewport({message:'Popover by text "This is popover title" and index 1 is not visible on page'});
    await expect(await $$(popover.byDefault().currentPath)).toBeElementsArrayOfSize(8);
    await icon.click();
  });
  it('should verify the popover CO -  properties', async () => {
    browser.addTestMeta({zephyrStep: "366709"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(poopoverPage.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let icon = await $("//eui-showcase-doc-sample[@id='"+sectionId+"']//i");
    await expect(icon).toBeDisplayedInViewport({message:'Icon is not visible on page'});
    await icon.click();
    let popover = poopoverPage.popoverByIndex(1);
    await expect(await $(popover.currentPath)).toBeDisplayedInViewport({message:'Popover by index 1 is not visible on page'});
    await expect(await $(popover.popoverArrow)).toBeDisplayedInViewport({message:'Popover popoverArrow from Default section is not visible on page'});
    await expect(await $(popover.popoverArrowInner)).toBeDisplayedInViewport({message:'Popover popoverArrowInner from Default section is not visible on page'});
    await expect(await $(popover.popoverHeader)).toBeDisplayedInViewport({message:'Popover popoverHeader from Default section is not visible on page'});
    await expect(await $(popover.popoverHeaderTitle)).
      toBeDisplayedInViewport({message:'Popover popoverHeaderTitle from Default section is not visible on page'});
    await expect(await $(popover.popoverHeaderTitle)).
      toHaveTextContaining('THIS IS POPOVER TITLE',{message:'Popover popoverHeaderTitle does not have text THIS IS POPOVER TITLE '});
    await expect(await popover.isShownCloseIcon()).toBe(true,'isShownCloseIcon should be true');
    await expect(await $(popover.popoverClose)).
     toBeDisplayedInViewport({message:'Popover popoverClose from Default section is not visible on page'});
    await expect(await $(popover.popoverCloseIcon)).
     toBeDisplayedInViewport({message:'Popover popoverCloseIcon from Default section is not visible on page'});
    await expect(await $(popover.popoverContent)).
     toBeDisplayedInViewport({message:'Popover popoverContent from Default section is not visible on page'});
    await expect(await $(popover.popoverContent)).
     toHaveTextContaining('You can close popover using its close icon in top right corner' ,
     {message:'Popover popoverContent does not have text You can close popover using its close icon in top right corner'});
    await expect(await popover.hasNoContentPadding()).toBe(false,'hasNoContentPadding should be false');
     await (await $(popover.popoverCloseIcon)).click();
  });
  it('should verify the methods isVisible,hasTitle ', async () => {
    browser.addTestMeta({zephyrStep: "367043"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(poopoverPage.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let popover = poopoverPage.popoverByIndex(1);
    await expect(await popover.isVisible()).toBe(false,'isVisible should be false');
    let icon = await $("//eui-showcase-doc-sample[@id='"+sectionId+"']//i");
    await expect(icon).toBeDisplayedInViewport({message:'Icon is not visible on page'});
    await icon.click();
    await expect(await $(popover.currentPath)).toBeDisplayedInViewport({message:'Popover by index 1 is not visible on page'});
    await expect(await popover.isVisible()).toBe(true,'isVisible should be true');
    await expect(await popover.hasTitle()).toBe(true,'hasTitle should be true');
    await icon.click();
  });
  it('should verify mouse over the icon ', async () => {
    browser.addTestMeta({zephyrStep: "366712"});
    let sectionId= 'positions';
    let scrollIntoSection = await $(poopoverPage.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let icon = await $("//eui-showcase-doc-sample[@id='"+sectionId+"']//i");
    await expect(icon).toBeDisplayedInViewport({message:'Icon is not visible on page'});
    await icon.moveTo();
    let popover = poopoverPage.popoverByIndex(6);
    await expect(await $(popover.currentPath)).toBeDisplayedInViewport({message:'Popover from section positions is not visible on page'});
    await expect(await popover.isVisible()).toBe(true);
  });
});
