import Routing from '../../../../pages/eui/10x/routing-10x.js'
import EuiPage from '../../../../pages/eui/10x/eui/eui-page-10x.po.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'

describe('eUI - <eui-page> Component Object ', async () => {
  let page = new EuiPage();
  let testFolder = './/eui-page//';
  it('should navigate to <eui-page> demo page', async () => {
    browser.addTestMeta({uuid:"ffb27eb4-e641-11eb-ba80-0242ac130004", zephyrKey: "CCQA-1426", zephyrStep: "415937", reportGroups: ["eUI.10x.eui"]});
    await page.open(Routing.getEUILayoutComponentUrl('eui-page'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    await pgTitle.scrollIntoView();
    await expect(await $(pgTitle)).toBeDisplayedInViewport({wait:3000,message:'<eui-page> page title is not displayed on page'});
    await expect(await $(page.appDocPageById('eui-page'))).not.toExist({message:'Page Id is existing on page'});
    await chaiExpect(await pgTitle.getText()).equal('eui-page', 'Page title text eui-page is not as expected');
    await expect(await $(page.navigationList)).not.toBeDisplayed({wait:3000,message:'Navigation List -> is displayed on page'});
  });
  it('should verify the presence and number of component objects <eui-page> on page ', async () => {
    browser.addTestMeta({zephyrStep: "415939"});
    let index = 1;
    let pageByIndex1 = await (await page.pageCO.byIndex(index).element());
    let text = 'This is the default';
    let pageByText = await (await page.pageCO.byTextContains(text).element());
    let pageByTextAndIndex = await (await page.pageCO.byTextEqualsAndIndex(text, index).element());
    await expect(pageByIndex1).toBeDisplayed({wait:3000,message:'page by index "'+ index +'" is not displayed on page'});
    await expect(pageByText).toBeDisplayed({wait:3000,message:'page by text "'+ text +'" is not displayed on page'});
    await expect(pageByTextAndIndex).toBeDisplayed({wait:3000,message:'page by text "'+ text +'" and index "'+ index +'" is not displayed on page'});
    await chaiExpect(await page.pageCO.defaultComponentsCount()).equal(1, 'There should be 1 <eui-page> components on the page.');
    if(browser.config.useWdioImageComparison) {
      await pageByIndex1.scrollIntoView();
      await chaiExpect(await browser.checkElement(pageByIndex1,  testFolder+'img_pageByIndex1', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for pageByIndex1');
      await chaiExpect(await browser.checkElement(pageByText,  testFolder+'img_pageByText', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for pageByText');
      await chaiExpect(await browser.checkElement(pageByTextAndIndex,  testFolder+'img_pageByTextAndIndex', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for pageByTextAndIndex');
    }
  });
  it('should verify the methods for components objects', async () => {
    browser.addTestMeta({zephyrStep: "415940"});
    let page1 = page.pageCO.byIndex(1);
    let pageHeader = await $(page1.euiPageHeaderCO.currentPath);
    let pageContent = await $(page1.euiPageContentCO.currentPath);
    await expect(pageHeader).toBeDisplayed({wait:3000,message:'pageHeader is not displayed on page'});
    await expect(await $(page1.euiPageHeroHeaderCO.currentPath)).not.
      toBeDisplayed({wait:3000,message:'pageHeroHeader is displayed on page'});
    await expect(pageContent).toBeDisplayed({wait:3000,message:'pageContent is not displayed on page'});
    await expect(await $(page1.euiPageColumnsCO.currentPath)).not.toBeDisplayed({wait:3000,message:'pageColumns is displayed on page'});
    if(browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(pageHeader,  testFolder+'img_pageHeader', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for euiPageHeader');
      await chaiExpect(await browser.checkElement(pageContent,  testFolder+'img_pageContent', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for euiPageContent');
    }
    let pageFooter = await $(page1.euiPageFooterCO.currentPath);
    await pageFooter.scrollIntoView();
    await expect(pageFooter).toBeDisplayed({wait:3000,message:'euiPageFooter is not displayed on page'});
    if(browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(pageFooter,  testFolder+'img_pageFooter', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for pageFooter');
      }
  });
});
