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

describe('eUI - <eui-fieldset> Component Object', async () => {
  let fieldsetPage = new FieldsetPage();
  let testFolder = './/v14x//eui-fieldset//';
  let pageName = 'eui-fieldset';
  it('should navigate to <eui-fieldset> component', async () => {
    browser.addTestMeta({uuid:"0ab74188-7cec-11eb-9439-0242ac130002", zephyrKey: "CCQA-596", zephyrStep: "327490", reportGroups: ["eUI.14x.ux"]});
    await fieldsetPage.open(Routing.getEUIComponentUrl('eui-fieldset'));
    await CookieBannerActions.cookieBanner(true);
    await BaseActions.verifyPageTitle(pageName);
    let navigationList = await $(fieldsetPage.navigationList);
   await expect(navigationList).toBeDisplayed({wait:1000, message:'Navigation List -> is not displayed on page'});
  });
  it('should verify the presence of the Component Object on the page ', async () => {
   browser.addTestMeta({zephyrStep: "354043"});
   await expect(await $(fieldsetPage.fieldsetFromSectionById('label').container)).toBeDisplayed({wait: 3000, message:
      '<Default> section -> is not displayed on page'});
   let fieldsetPageByIndex1 = await $(fieldsetPage.fieldsetByIndex(1).container);
   await expect(fieldsetPageByIndex1).toBeDisplayed({wait: 3000, message:
        'Fieldset by index "1" is not displayed on page'});
   await expect(await $(fieldsetPage.fieldsetByTextContains('Fieldset label').container)).toBeDisplayed({wait: 3000, message:
      'Fieldset by text "Fieldset label" is not displayed on page'});
   await expect(await $(fieldsetPage.fieldsetByTextEqualsAndIndex('Fieldset label', 1).container)).toBeDisplayed({wait: 3000, message:
      'Fieldset by text "Fieldset label" and index 1 is not displayed on page'});
   await expect(await fieldsetPage.fieldsetByIndex(1).defaultComponentsCount()).toBe(22, 'There should be 22 <eui-fieldset> components on the page.');
   if(browser.config.useWdioImageComparison) {
    await fieldsetPageByIndex1.scrollIntoView();
    await chaiExpect(await browser.checkElement(fieldsetPageByIndex1, testFolder+'img_fieldsetPageByIndex1', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for fieldsetPageByIndex1');
  }
  });
  it('should verify the presence of other CO in page and icon types ', async () => {
   browser.addTestMeta({zephyrStep: "327493"});
   let sectionId = 'typeClass-iconClass';
   await BaseActions.verifySection(sectionId, pageName);
   let sectionElement = await $(fieldsetPage.fieldsetFromSectionById(sectionId).currentPath);
   await sectionElement.scrollIntoView();

   let fieldset1 = fieldsetPage.fieldsetFromSectionWithIdByIndex(sectionId, 1);
   let fieldsetHeader = await $(fieldset1.header);
   let fieldsetHeaderLabel = await $(fieldset1.headerLabel);
   await expect(fieldsetHeader).toBeDisplayed({wait: 3000, message:'Fieldset by index "1" from typeClass-iconClass section property header is not displayed on page'});
   await expect(fieldsetHeaderLabel).toBeDisplayed({wait: 3000, message:
      'Fieldset by index "1" from typeClass-iconClass section property headerLabel is not displayed on page'});
      await expect(await $(fieldset1.headerLabel)).toHaveTextContaining('FOLLOWING LIST CONTAINS INFOS (10)');

   let fieldsetHeaderIcon = await $(fieldsetPage.fieldsetFromSectionWithIdByIndex(sectionId, 5).headerIcon);
   await expect(fieldsetHeaderIcon).toBeDisplayed({wait: 3000, message:
    'Fieldset by index "5" from typeClass-iconClass section property headerIcon is not displayed on page'});
   if(browser.config.useWdioImageComparison) {
    await fieldsetHeader.scrollIntoView();
    await chaiExpect(await browser.checkElement(fieldsetHeader, testFolder+'img_fieldsetHeader', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for fieldsetHeader');
    await fieldsetHeaderLabel.scrollIntoView();
    await chaiExpect(await browser.checkElement(fieldsetHeaderLabel, testFolder+'img_fieldsetHeaderLabel', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for fieldsetHeaderLabel');
  }
   await expect(await fieldsetPage.fieldsetFromSectionWithIdByIndex(sectionId,1).element()).toHaveAttrContaining('class', 'info');
   await expect(await fieldsetPage.fieldsetFromSectionWithIdByIndex(sectionId,2).element()).toHaveAttrContaining('class', 'success');
   await expect(await fieldsetPage.fieldsetFromSectionWithIdByIndex(sectionId,3).element()).toHaveAttrContaining('class', 'warning');
   await expect(await fieldsetPage.fieldsetFromSectionWithIdByIndex(sectionId,4).element()).toHaveAttrContaining('class', 'danger');
  });
  it('should verify expanded state of fieldset ', async () => {
   browser.addTestMeta({zephyrStep: "327495"});
   let sectionId = 'isExpandable';
   await BaseActions.verifySection(sectionId, pageName);

   let fieldset1 = fieldsetPage.fieldsetFromSectionWithIdByIndex(sectionId, 1);
   let headerRightContent = await $(fieldset1.headerRightContent);
   let expandToggle = await $(fieldset1.expandToggleButtonCO.currentPath);
   await expect(headerRightContent).toBeDisplayed({wait: 3000, message:
      'Fieldset by index "1" from isExpandable section property headerRightContent is not displayed on page'});
   await expect(expandToggle).toBeDisplayed({wait: 3000, message:
      'Fieldset by index "1" from isExpandable section property expandToggle is not displayed on page'});
   await expect(await fieldset1.isExpandable()).toBe(true, 'isExpandable should be true');
   await expect(await fieldset1.isExpanded()).toBe(true, 'isExpanded should be true');
   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 expandToggle.scrollIntoView();
    await chaiExpect(await browser.checkElement(expandToggle, testFolder+'img_expandToggle', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for expandToggle');
  }
  });
  it('should verify content of fieldset  ', async () => {
   browser.addTestMeta({zephyrStep: "327496"});
   let sectionId = 'label-extra-content';
   await BaseActions.verifySection(sectionId, pageName);
   let fieldset1 = fieldsetPage.fieldsetFromSectionWithIdByIndex(sectionId, 1);
   await expect(await $(fieldset1.container)).toBeDisplayed({wait: 3000, message:
      'Fieldset by index "1" from label-extra-content section property container is not displayed on page'});
    await expect(await $(fieldset1.headerLabel)).toHaveTextContaining('MANAGERS AND PARTNERS');
  });

});
