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

describe('eUI - <eui-button> Component Object', async () => {
  let page = new EuiButtonPage();
  let testFolder = './/eui-button//'
  it('should navigate to <eui-button> demo page ', async () => {
    browser.addTestMeta({uuid:"6d9af61e-cf62-11eb-b8bc-0242ac130003", zephyrKey: "CCQA-1111", zephyrStep: "408308", reportGroups: ["eUI.10x.eui"]});
    await page.open(Routing.getEUIComponentUrl('eui-button'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    await pgTitle.scrollIntoView();
    await expect(await $(pgTitle)).toBeDisplayedInViewport({message:'<eui-button> page title is not displayed on page'});
    await expect(await $(page.appDocPageById('eui-button'))).toExist({message:'Page Id is not existing on page'});
    await expect(pgTitle).toHaveText('eui-button', {wait:1000,message:'Page title text is not as expected'});
    await expect(await $(page.navigationList)).toBeDisplayed({message:'Navigation List -> is not displayed on page'});
  });
  it('should verify the <eui-button> identification methods', async () => {
    browser.addTestMeta({zephyrStep: "408309"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let index = 3;
    let buttonByIndex1 = await page.buttonByIndex(index).element();
    let text = 'Default';
    let buttonByText = await page.buttonByTextContains(text).element();
    index = 1;
    let buttonByTextAndIndex = await page.buttonByTextEqualsAndIndex(text, index).element();

    await expect(await $(page.sectionById(sectionId))).toBeDisplayed({message:'<'+sectionId+'> section -> is not displayed on page'});
    await expect(buttonByIndex1).toBeDisplayed({message:'Button by index '+ index +' is not displayed on page'});
    await expect(buttonByText).toBeDisplayed({message:'Button by text '+ text +' is not displayed on page'});
    await expect(buttonByTextAndIndex).toBeDisplayed({message:'Button by index '+ index +' and text '+ text +' is not displayed on page'});
    await chaiExpect(await page.buttonByIndex(index).defaultComponentsCount()).equal(342, 'There should be 342 <eui-button> components on the page.');
    if(browser.config.useWdioImageComparison) {
      await buttonByIndex1.scrollIntoView();
      await chaiExpect(await browser.checkElement(buttonByIndex1,  testFolder+'img_buttonByIndex1', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for buttonByIndex1');
      await buttonByText.scrollIntoView();
      await chaiExpect(await browser.checkElement(buttonByText,  testFolder+'img_buttonByText', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for buttonByText');
      await buttonByTextAndIndex.scrollIntoView();
      await chaiExpect(await browser.checkElement(buttonByTextAndIndex,  testFolder+'img_buttonByTextAndIndex', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for buttonByTextAndIndex');
    }
  });
  it('should verify the methods container, isLoading, loadingIcon ', async () => {
    browser.addTestMeta({zephyrStep: "408310"});
    let sectionId = 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let button = page.buttonByIndex(3);
    let buttonContainer = await $(button.container);
    await expect(buttonContainer).toBeDisplayed({message:'Button container is not displayed on page'});
    await chaiExpect(await button.isLoading()).equal(false, 'isLoading is not false');
    if(browser.config.useWdioImageComparison) {
      await buttonContainer.scrollIntoView();
      await chaiExpect(await browser.checkElement(buttonContainer,  testFolder+'img_buttonContainer', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for buttonContainer');
    }

    sectionId= 'is-loading';
    scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    button = page.buttonFromSectionById(sectionId);
    await expect(await $(button.loadingIcon)).toExist({message:'Button loadingIcon is not existing on page'});
    await expect(await $(button.euiIconCO.currentPath)).toExist({message:'Button euiIconCO currentPath is not existing on page'});
    await chaiExpect(await button.isLoading()).equal(true, 'isLoading is not true');
  });

  it('should verify the methods isBasic, isBlock, isRaised, isIconOnly, isLineWrap  ', async () => {
    browser.addTestMeta({zephyrStep: "408311"});
    let sectionId = 'basic';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let button = page.buttonFromSectionWithIdByIndex(sectionId,2);
    let buttonBasic = await $(button.container);
    await expect(buttonBasic).toBeDisplayed({message:'Button basic is not displayed on page'});
    if(browser.config.useWdioImageComparison) {
      await buttonBasic.scrollIntoView();
      await chaiExpect(await browser.checkElement(buttonBasic,  testFolder+'img_buttonBasic', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for buttonBasic');
    }
    await chaiExpect(await button.isBasic()).equal(true, 'isBasic is not true');
    await chaiExpect(await button.isBlock()).equal(false, 'isBlock is not false');

    sectionId= 'block-button';
    scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    button = page.buttonFromSectionWithIdByIndex(sectionId,2);
    let buttonBlocked = await $(button.container);
    await expect(buttonBlocked).toBeDisplayed({message:'Button blocked is not displayed on page'});
    if(browser.config.useWdioImageComparison) {
      await buttonBlocked.scrollIntoView();
      await chaiExpect(await browser.checkElement(buttonBlocked,  testFolder+'img_buttonBlocked', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for buttonBlocked');
    }
    await chaiExpect(await button.isBasic()).equal(false, 'isBasic is not false');
    await chaiExpect(await button.isBlock()).equal(true, 'isBlock is not true');

    sectionId= 'raised';
    scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    button = page.buttonFromSectionWithIdByIndex(sectionId,2);
    let buttonRaised = await $(button.container);
    await expect(buttonRaised).toBeDisplayed({message:'Button raised is not displayed on page'});
    if(browser.config.useWdioImageComparison) {
      await buttonRaised.scrollIntoView();
      await chaiExpect(await browser.checkElement(buttonRaised,  testFolder+'img_buttonRaised', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for buttonRaised');
    }
    await chaiExpect(await button.isIconOnly()).equal(false, 'isIconOnly is not false');
    await chaiExpect(await button.isRaised()).equal(true, 'isRaised is not true');

    sectionId = 'icon-button';
    scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    button = page.buttonFromSectionWithIdByIndex(sectionId,2);
    let iconButton = await $(button.container);
    await expect(iconButton).toBeDisplayed({message:'Icon button is not displayed on page'});
    if(browser.config.useWdioImageComparison) {
      await iconButton.scrollIntoView();
      await chaiExpect(await browser.checkElement(iconButton,  testFolder+'img_iconButton', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for iconButton');
    }
    await chaiExpect(await button.isIconOnly()).equal(true, 'isIconOnly is not true');
    await chaiExpect(await button.isRaised()).equal(false, 'isRaised is not false');
    await chaiExpect(await button.isLineWrap()).equal(false, 'isLineWrap is not false');

    sectionId = 'composition';
    scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    button = page.buttonFromSectionWithIdByIndex(sectionId,2);
    let compositionButton = await $(button.container);
    await expect(compositionButton).toBeDisplayed({message:'Composition button is not displayed on page'});
    if(browser.config.useWdioImageComparison) {
      await compositionButton.scrollIntoView();
      await chaiExpect(await browser.checkElement(compositionButton,  testFolder+'img_compositionButton', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for compositionButton');
    }
    await chaiExpect(await button.isLineWrap()).equal(true, 'isLineWrap is not true');
  });
});
