import Routing from '../../../pages/eui/14x/routing.js'
import CoEuiPageColumns from '../../../pages/eui/14x/eui-page-columns.po.js'
import * as CookieBannerActions from '../../../actions/cookieBanner.js';
import BaseActions from '../../../actions/V14/base-actions.js';

describe('eUI - <eui-page-columns> Component Object ', async () => {
  let page = new CoEuiPageColumns();
  let testFolder = './/v14x//eui-page-columns//';
  let pageName= 'eui-page-columns'
  it('should navigate to <eui-page-columns> demo page', async () => {
    browser.addTestMeta({uuid:"9dfc0146-eba9-11eb-9a03-0242ac130003", zephyrKey: "CCQA-1444", zephyrStep: "416445", reportGroups: ["eUI.14x.eui"]});
    await page.open(Routing.getEUILayoutComponentUrl('eui-page-column'));
    await CookieBannerActions.cookieBanner(true);
    await BaseActions.verifyPageTitle(pageName, false);
    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-columns> on page', async () => {
    browser.addTestMeta({zephyrStep: "416446"});
    let pageColumnsByIndex = await $(page.columnsCO.byIndex(1).currentPath);
    let pageColumnsByText = await $(page.columnsCO.byTextContains('S').currentPath);
    let pageColumnsByTextAndIndex = await $(page.columnsCO.byTextEqualsAndIndex('S', 1).currentPath);
    await expect(pageColumnsByIndex).toBeDisplayed({wait:3000,message:'page columns by Index "1" is not displayed on page'});
    await expect(pageColumnsByText).toBeDisplayed({wait:3000,message:'page columns by text "S" is not displayed on page'});
    await expect(pageColumnsByTextAndIndex).toBeDisplayed({wait:3000,message:'page columns by text "S" and index 1 is not displayed on page'});
    await chaiExpect(await page.columnsCO.byIndex(1).defaultComponentsCount()).equal(1, 'There should be 1 <eui-page-columns> components on the page.');
    if(browser.config.useWdioImageComparison) {
      await pageColumnsByIndex.scrollIntoView();
      if(browser.config.env.endsWith('DEV')) {
        await chaiExpect(await browser.checkElement(pageColumnsByIndex, testFolder+'img_pageColumnsByIndexDev', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for pageColumnsByIndex');
        await pageColumnsByText.scrollIntoView();
        await chaiExpect(await browser.checkElement(pageColumnsByText, testFolder+'img_pageColumnsByTextDev', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for pageColumnsByText');
        await pageColumnsByTextAndIndex.scrollIntoView();
        await chaiExpect(await browser.checkElement(pageColumnsByTextAndIndex, testFolder+'img_pageColumnsByTextAndIndexDev', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for pageColumnsByTextAndIndex');""
      }
      else {
        await chaiExpect(await browser.checkElement(pageColumnsByIndex, testFolder+'img_pageColumnsByIndex', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for pageColumnsByIndex');
        await pageColumnsByText.scrollIntoView();
        await chaiExpect(await browser.checkElement(pageColumnsByText, testFolder+'img_pageColumnsByText', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for pageColumnsByText');
        await pageColumnsByTextAndIndex.scrollIntoView();
        await chaiExpect(await browser.checkElement(pageColumnsByTextAndIndex, testFolder+'img_pageColumnsByTextAndIndex', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for pageColumnsByTextAndIndex');""
      }

    }
  });
  it('should verify the presence and number of component objects <eui-page-column> on page', async () => {
    browser.addTestMeta({zephyrStep: "416447"});
    let pageColumnByIndex = await $(page.columnCO.byIndex(1).currentPath);
    let pageColumnByText = await $(page.columnCO.byTextContains('S').currentPath);
    let pageColumnByTextAndIndex = await $(page.columnCO.byTextEqualsAndIndex('S', 1).currentPath);
    await expect(pageColumnByIndex).toBeDisplayed({wait:3000,message:'page column by index "1" is not displayed on page'});
    await expect(pageColumnByText).toBeDisplayed({wait:3000,message:'page column by text "S" is not displayed on page'});
    await expect(pageColumnByTextAndIndex).toBeDisplayed({wait:3000,message:'page column by text "S" and index 1 is not displayed on page'});
    await chaiExpect(await page.columnCO.byIndex(1).defaultComponentsCount()).equal(5, 'There should be 5 <eui-page-column> components on the page.');
    if(browser.config.useWdioImageComparison) {
      await pageColumnByIndex.scrollIntoView();
      await chaiExpect(await browser.checkElement(pageColumnByIndex, testFolder+'img_pageColumnByIndex', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for pageColumnByIndex');
      await pageColumnByText.scrollIntoView();
      await chaiExpect(await browser.checkElement(pageColumnByText, testFolder+'img_pageColumnByText', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for pageColumnByText');
      await pageColumnByTextAndIndex.scrollIntoView();
      await chaiExpect(await browser.checkElement(pageColumnByTextAndIndex, testFolder+'img_pageColumnByTextAndIndex', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for pageColumnByTextAndIndex');
    }
  });
  it('should verify eui-page-columns the method euiPageColumnCO', async () => {
    browser.addTestMeta({zephyrStep: "416448"});
    let columns = page.columnsCO.byIndex(1);
    await expect(await $(columns.euiPageColumnCO.currentPath)).toBeDisplayed({wait:3000,message:'euiPageColumnCO currentPath is not displayed on page'});
  });
  it('should verify eui-page-column methods: header, headerLeftContent, headerLeftContentLabel, hasHeaderLeftContentLabel', async () => {
    browser.addTestMeta({zephyrStep: "416455"});
    let column = page.columnsCO.byIndex(1).euiPageColumnCO.byIndex(1);
    let columnHeader = await $(column.header);
    let columnHeaderLeftContent = await $(column.headerLeftContent);
    let columnHeaderLeftContentLabel = await $(column.headerLeftContentLabel);
    await expect(columnHeader).toBeDisplayed({wait:3000,message:'header is not displayed on page'});
    await chaiExpect(await column.isCollapsedWithIcons()).equal(false, 'isCollapsedWithIcons should be false');
    await expect(columnHeaderLeftContent).toBeDisplayed({wait:3000,message:'headerLeftContent is not displayed on page'});
    await expect(columnHeaderLeftContentLabel).toBeDisplayed({wait:3000,message:'headerLeftContentLabel is not displayed on page'});
    await chaiExpect(await column.hasHeaderLeftContentLabel()).equal(true, 'hasHeaderLeftContentLabel should be true');
    if(browser.config.useWdioImageComparison) {
      await columnHeader.scrollIntoView();
      await chaiExpect(await browser.checkElement(columnHeader, testFolder+'img_columnHeader', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for columnHeader');
      await columnHeaderLeftContent.scrollIntoView();
      await chaiExpect(await browser.checkElement(columnHeaderLeftContent, testFolder+'img_columnHeaderLeftContent', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for columnHeaderLeftContent');
      await columnHeaderLeftContentLabel.scrollIntoView();
      await chaiExpect(await browser.checkElement(columnHeaderLeftContentLabel, testFolder+'img_columnHeaderLeftContentLabel', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for columnHeaderLeftContentLabel');
    }
  });
  it('should verify eui-page-column methods: hasCustomHeaderCollapsedContent, headerLeftContentPlaceholder, hasCustomHeaderLeftContent', async () => {
    browser.addTestMeta({zephyrStep: "416456"});
    let column = page.columnsCO.byIndex(1).euiPageColumnCO.byIndex(5);
    await chaiExpect(await column.hasCustomHeaderCollapsedContent()).equal(false, 'hasCustomHeaderCollapsedContent should be false');
    let headerLeftContentPlaceholder = await $(column.headerLeftContentPlaceholder);
    await expect(headerLeftContentPlaceholder). toBeDisplayed({wait:3000,message:'headerLeftContentPlaceholder is not displayed on page'});
    if(browser.config.useWdioImageComparison) {
      await headerLeftContentPlaceholder.scrollIntoView();
      await chaiExpect(await browser.checkElement(headerLeftContentPlaceholder, testFolder+'img_headerLeftContentPlaceholder', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for headerLeftContentPlaceholder');
    }
    await chaiExpect(await column.hasCustomHeaderLeftContent()).equal(true, 'hasCustomHeaderLeftContent should be true');
  });
  it('should verify eui-page-column methods: headerRightContent,headerRightContentBody, hasCustomHeaderRightContent, headerRightContentPlaceholder', async () => {
    browser.addTestMeta({zephyrStep: "416457"});
    let column = page.columnsCO.byIndex(1).euiPageColumnCO.byIndex(4);
    let headerRightContent= await $(column.headerRightContent);
    let headerRightContentBody= await $(column.headerRightContentBody);
    let headerRightContentPlaceholder= await $(column.headerRightContentPlaceholder);
    await expect(headerRightContent).toBeDisplayed({wait:3000,message:'headerRightContent is not displayed on page'});
    await expect(headerRightContentBody).toBeDisplayed({wait:3000,message:'headerRightContentBody is not displayed on page'});
    await chaiExpect(await column.hasCustomHeaderRightContent()).equal(true, 'hasCustomHeaderRightContent should be true');
    await expect(headerRightContentPlaceholder).toBeDisplayed({wait:3000,message:'headerRightContentPlaceholder is not displayed on page'});
    if(browser.config.useWdioImageComparison) {
      await headerRightContent.scrollIntoView();
      await chaiExpect(await browser.checkElement(headerRightContent, testFolder+'img_headerRightContent', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for headerRightContent');
      await headerRightContentBody.scrollIntoView();
      await chaiExpect(await browser.checkElement(headerRightContentBody, testFolder+'img_headerRightContentBody', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for headerRightContentBody');
      await headerRightContentPlaceholder.scrollIntoView();
      await chaiExpect(await browser.checkElement(headerRightContentPlaceholder, testFolder+'img_headerRightContentPlaceholder', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for headerRightContentPlaceholder');
    }
  });
  it('should verify eui-page-column methods: buttonCO, headerToggleIcon, hasIconAngleRight, hasIconAngleLeft, hasIconAngleDown, hasIconAngleUp, isCollapsible', async () => {
    browser.addTestMeta({zephyrStep: "416458"});
    let column = page.columnsCO.byIndex(1).euiPageColumnCO.byIndex(4);
    let button = await $(column.buttonCO.currentPath);
    await expect(button).toBeDisplayed({wait:3000,message:'buttonCO currentPath is not displayed on page'});
    let headerToggleIcon = await $(column.headerToggleIcon);
    await expect(headerToggleIcon).toBeDisplayed({wait:3000,message:'headerToggleIcon is not displayed on page'});
    if(browser.config.useWdioImageComparison) {
      await button.scrollIntoView();
      await chaiExpect(await browser.checkElement(button, testFolder+'img_button', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for button');
      await headerToggleIcon.scrollIntoView();
      await chaiExpect(await browser.checkElement(headerToggleIcon, testFolder+'img_headerToggleIcon', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for headerToggleIcon');
    }
    column = page.columnsCO.byIndex(1).euiPageColumnCO.byIndex(3);
    await chaiExpect(await column.hasIconAngleRight()).equal(false, 'hasIconAngleRight should be false');
    await chaiExpect(await column.hasIconAngleLeft()).equal(true, 'hasIconAngleLeft should be true');
    await chaiExpect(await column.hasIconAngleDown()).equal(false, 'hasIconAngleDown should be false');
    await chaiExpect(await column.hasIconAngleUp()).equal(false, 'hasIconAngleUp should be false');
    await chaiExpect(await column.isCollapsible()).equal(true, 'isCollapsible should be true');
  });
  it('should verify eui-page-column methods: headerLeftContentBody, hasCustomHeaderBodyContent', async () => {
    browser.addTestMeta({zephyrStep: "416459"});
    let column = page.columnsCO.byIndex(1).euiPageColumnCO.byIndex(3);
    let headerLeftContentBody = await $(column.headerLeftContentBody);
    await expect(headerLeftContentBody).toBeDisplayed({wait:3000,message:'headerLeftContentBody is not displayed on page'});
    await chaiExpect(await column.hasCustomHeaderBodyContent()).equal(true, 'hasCustomHeaderBodyContent should be true');
    if(browser.config.useWdioImageComparison) {
      await headerLeftContentBody.scrollIntoView();
      await chaiExpect(await browser.checkElement(headerLeftContentBody, testFolder+'img_headerLeftContentBody', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for headerLeftContentBody');
    }
  });

  it('should verify eui-page-column methods: isHeaderBodyShrinked, headerBodyPlaceholder, body, bodyPlaceholder isBodyInteractiveScrollbars', async () => {
    browser.addTestMeta({zephyrStep: "416460"});
    let column = page.columnsCO.byIndex(1).euiPageColumnCO.byIndex(3);
    await chaiExpect(await column.isHeaderBodyShrinked()).equal(false, 'isHeaderBodyShrinked should be false');
    let headerBodyPlaceholder = await $(column.headerBodyPlaceholder);
    let body = await $(column.body);
    let bodyPlaceholder = await $(column.bodyPlaceholder);
    await expect(headerBodyPlaceholder).toBeDisplayed({wait:3000,message:'headerBodyPlaceholder is not displayed on page'});
    await expect(body).toBeDisplayed({wait:3000,message:'body is not displayed on page'});
    await expect(bodyPlaceholder).toBeDisplayed({wait:3000,message:'bodyPlaceholder is not displayed on page'});
    await chaiExpect(await column.isBodyInteractiveScrollbars()).equal(true, 'isBodyInteractiveScrollbars should be true');
    await chaiExpect(await column.isBodyCollapsedWithIcons()).equal(false, 'isBodyCollapsedWithIcons should be false');
    if(browser.config.useWdioImageComparison) {

      await headerBodyPlaceholder.scrollIntoView();
      await chaiExpect(await browser.checkElement(headerBodyPlaceholder, testFolder+'img_headerBodyPlaceholder', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for headerBodyPlaceholder');
      await body.scrollIntoView();
      if(browser.config.env.endsWith('DEV')) {
      await chaiExpect(await browser.checkElement(body, testFolder+'img_bodyDev', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for body');
      await bodyPlaceholder.scrollIntoView();
      await chaiExpect(await browser.checkElement(bodyPlaceholder, testFolder+'img_bodyPlaceholderDev', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for bodyPlaceholder');
    } else {
    await chaiExpect(await browser.checkElement(body, testFolder+'img_body', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for body');
    await bodyPlaceholder.scrollIntoView();
    await chaiExpect(await browser.checkElement(bodyPlaceholder, testFolder+'img_bodyPlaceholder', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for bodyPlaceholder');
    }
  }
  });
  it('should verify eui-page-column methods: footer, hasCustomFooterContent, isHighlighted, footerPlaceholder', async () => {
    browser.addTestMeta({zephyrStep: "416468"});
    let column = page.columnsCO.byIndex(1).euiPageColumnCO.byIndex(3);
    let footer = await $(column.footer);
    let footerPlaceholder = await $(column.footerPlaceholder);
    await expect(footer).toBeDisplayed({wait:3000,message:'footer is not displayed on page'});
    await expect(await column.hasCustomFooterContent()).toBe(true);
    await expect(await column.isHighlighted()).toBe(false);
    await chaiExpect(await column.hasCustomFooterContent()).equal(true, 'hasCustomFooterContent should be true');
    await chaiExpect(await column.isHighlighted()).equal(false, 'isHighlighted should be false');
    await expect(footerPlaceholder).toBeDisplayed({wait:3000,message:'footerPlaceholder is not displayed on page'});
    if(browser.config.useWdioImageComparison) {
      await footer.scrollIntoView();
      await chaiExpect(await browser.checkElement(footer, testFolder+'img_footer', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for footer');
      await footerPlaceholder.scrollIntoView();
      await chaiExpect(await browser.checkElement(footerPlaceholder, testFolder+'img_footerPlaceholder', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for footerPlaceholder');
    }
  });

});
