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

describe('eUI - <eui-button> Component Object', async () => {
  let page = new EuiButtonPage();
  let testFolder = './/v14x//eui-button//'
  let pageName = '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.14x.eui"]});
    await page.open(Routing.getEUIComponentUrl('eui-button'));
    await CookieBannerActions.cookieBanner(true);
    await BaseActions.verifyPageTitle(pageName);
    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';
    await BaseActions.verifySection(sectionId, pageName);
    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(244, 'There should be 244 <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';
    await BaseActions.verifySection(sectionId, pageName);
    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';
    await BaseActions.verifySection(sectionId, pageName);
    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';
    await BaseActions.verifySection(sectionId, pageName);
    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';
    await BaseActions.verifySection(sectionId, pageName);
    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 = 'icon-button';
    await BaseActions.verifySection(sectionId, pageName);
    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 = 'line-wrap';
    await BaseActions.verifySection(sectionId, pageName);
    button = page.buttonFromSectionWithIdByIndex(sectionId,2);
    let lineWrapButton = await $(button.container);
    await expect(lineWrapButton).toBeDisplayed({message:'Composition button is not displayed on page'});
    if(browser.config.useWdioImageComparison) {
      await lineWrapButton.scrollIntoView();
      await chaiExpect(await browser.checkElement(lineWrapButton,  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');
  });
});
