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

describe('eUI - <eui-page-header> Component Object ', async () => {
  let page = new EuiPageHeader();
  let testFolder = './/eui-page-header//';
  it('should navigate to <eui-page-header> demo page', async () => {
    browser.addTestMeta({uuid:"834f195a-eae6-11eb-9a03-0242ac130003", zephyrKey: "CCQA-1436", zephyrStep: "416008", reportGroups: ["eUI.10x.eui"]});
    await page.open(Routing.getEUILayoutComponentUrl('eui-page-header'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    await pgTitle.scrollIntoView();
    await expect(await $(pgTitle)).toBeDisplayedInViewport({wait:3000,message:'<eui-page-header> page title is not displayed on page'});
    await expect(await $(page.appDocPageById('eui-page-header'))).not.toExist({message:'Page Id is existing on page'});
    await chaiExpect(await pgTitle.getText()).equal('eui-page-header', 'Page title text eui-page-header 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-header> on page ', async () => {
    browser.addTestMeta({zephyrStep: "416009"});
    let index = 1;
    let headerByIndex1 = await (await page.headerCO.byIndex(index).element());
    let text = 'Page Title';
    let headerByText = await (await page.headerCO.byTextContains(text).element());
    let headerByTextAndIndex = await (await page.headerCO.byTextEqualsAndIndex(text, index).element());
    await expect(headerByIndex1).toBeDisplayed({wait:3000,message:'page by index "'+ index +'" is not displayed on page'});
    await expect(headerByText).toBeDisplayed({wait:3000,message:'page by text "'+ text +'" is not displayed on page'});
    await expect(headerByTextAndIndex).toBeDisplayed({wait:3000,message:'page by text "'+ text +'" and index "'+ index +'" is not displayed on page'});
    await chaiExpect(await page.headerCO.defaultComponentsCount()).equal(8, 'There should be 1 <eui-page-header> components on the page.');
    if(browser.config.useWdioImageComparison) {
      await headerByIndex1.scrollIntoView();
      await chaiExpect(await browser.checkElement(headerByIndex1, testFolder+'img_headerByIndex1', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for headerByIndex1');
      await chaiExpect(await browser.checkElement(headerByText, testFolder+'img_headerByText', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for headerByText');
      await chaiExpect(await browser.checkElement(headerByTextAndIndex, testFolder+'img_headerByTextAndIndex', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for headerByTextAndIndex');
    }
  });
  it('should verify the methods :  commonHeader, actionItems, actionItemsPlaceholder ', async () => {
    browser.addTestMeta({zephyrStep: "416010"});
    let index = 1;
    let header = page.headerCO.byIndex(index);
    let commonHeader = await $(header.commonHeader);
    await expect(commonHeader).toBeDisplayed({wait:3000,message:'commonHeader is not displayed on page'});
    index = 3;
    header = page.headerCO.byIndex(index);
    let actionItems = await $(header.actionItems);
    await expect(actionItems).toBeDisplayed({message:'actionItems is not displayed on page'});
    let actionItemsPlaceholder = await $(header.actionItemsPlaceholder);
    await expect(actionItemsPlaceholder).toBeDisplayed({message:'actionItemsPlaceholder is not displayed on page'});
    if(browser.config.useWdioImageComparison){
      await actionItems.scrollIntoView();
      if (browser.config.env.endsWith('DEV')){
      await chaiExpect(await browser.checkElement(actionItems, testFolder+'img_actionItemsDev', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for actionItems');
      await chaiExpect(await browser.checkElement(actionItemsPlaceholder, testFolder+'img_actionItemsPlaceholderDev', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for actionItemsPlaceholder');
      }
    else  {
      await chaiExpect(await browser.checkElement(actionItems, testFolder+'img_actionItems', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for actionItems');
      await chaiExpect(await browser.checkElement(actionItemsPlaceholder, testFolder+'img_actionItemsPlaceholder', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for actionItemsPlaceholder');
     }
    }
  });
  it('should verify the methods :  expandContent, isCollapsible, isCollapsed ', async () => {
    browser.addTestMeta({zephyrStep: "416011"});
    let index = 8;
    let header = page.headerCO.byIndex(index);
    await (await $(header.currentPath)).scrollIntoView();
    let expandContent = await $(header.expandContent);
    await expect(expandContent).toBeDisplayed({wait:3000,message:'expandContent is not displayed on page'});
    if(browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(expandContent, testFolder+'img_expandContent', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for expandContent');
    }
    await chaiExpect(await header.isCollapsible()).equal(true, 'isCollapsible is not true');
    await chaiExpect(await header.isCollapsed()).equal(false, 'isCollapsed is not false');
    await (await $(page.buttonComponentByTextContains('Expand').currentPath)).click();
    await chaiExpect(await header.isCollapsed()).equal(true, 'isCollapsed is not true');
  });
  it('should verify the methods :  body, bodyPlaceholder ', async () => {
    browser.addTestMeta({zephyrStep: "416012"});
    let index = 7;
    let header = page.headerCO.byIndex(index);
    await (await $(header.currentPath)).scrollIntoView();
    let headerBody = await $(header.body);
    let headerBodyPlaceholder = await $(header.bodyPlaceholder);
    await expect(headerBody).toBeDisplayed({wait:3000,message:'body is not displayed on page'});
    await expect(headerBodyPlaceholder).toBeDisplayed({wait:3000,message:'bodyPlaceholder is not displayed on page'});
    if(browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(headerBody, testFolder+'img_headerBody', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for headerBody');
      await chaiExpect(await browser.checkElement(headerBodyPlaceholder, testFolder+'img_headerBodyPlaceholder', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for headerBodyPlaceholder');
    }
  });
  it('should verify the methods :  label, haslabel, sublabel, hasSublabel ', async () => {
    browser.addTestMeta({zephyrStep: "416013"});
    let index = 2;
    let header = page.headerCO.byIndex(index);
    await (await $(header.currentPath)).scrollIntoView();
    let headerLabel = await $(header.label)
    await expect(headerLabel).toBeDisplayed({wait:3000,message:'label is not displayed on page'});
    await chaiExpect(await header.hasLabel()).equal(true, 'hasLable is not true');
    await expect(await $(header.label)).toHaveTextContaining('Page Title');
    let headerSublabel = await $(header.sublabel);
    await expect(headerSublabel).toBeDisplayed({wait:3000,message:'sublabel is not displayed on page'});
    await chaiExpect(await header.hasSublabel()).equal(true, 'hasSublabel is not true');
    await expect(await $(header.sublabel)).toHaveTextContaining('Page Sub-title');
    if(browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(headerLabel, testFolder+'img_headerLabel', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for headerLabel');
      await chaiExpect(await browser.checkElement(headerSublabel, testFolder+'img_headerSublabel', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for headerSublabel');
    }
  });
});
