import Routing from '../../../../pages/eui/10x/routing-10x.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'
import FieldsetPage from '../../../../pages/eui/10x/ux/ux-fieldset-10x.po.js'

describe('eUI - <ux-fieldset> Component Object', async () => {
  let fieldsetPage = new FieldsetPage();
  it('should navigate to <ux-fieldset> component', async () => {
    browser.addTestMeta({uuid:"0ab74188-7cec-11eb-9439-0242ac130002", zephyrKey: "CCQA-596", zephyrStep: "327490", reportGroups: ["eUI.10x.ux"]});
    await fieldsetPage.open(Routing.getUxComponentUrl('ux-fieldset'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(fieldsetPage.pageTitle);
    let appDocPageId = await $(fieldsetPage.appDocPageById('ux-fieldset'));
    let navigationList = await $(fieldsetPage.navigationList);

   await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-fieldset> page title is not displayed on page'});
   await expect(pgTitle).toHaveText('ux-fieldset', {wait: 1000, message: 'Page title text is not as expected'});
   await expect(appDocPageId).toExist({wait:1000, message:'Page Id is not present in page'});
   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').dataE2E)).toBeDisplayed({wait: 3000, message:
      '<Default> section -> is not displayed on page'});
   await expect(await $(fieldsetPage.fieldsetByIndex(1).dataE2E)).toBeDisplayed({wait: 3000, message:
        'Fieldset by index "1" is not displayed on page'});
   await expect(await $(fieldsetPage.fieldsetByTextContains('FIELDSET LABEL').dataE2E)).toBeDisplayed({wait: 3000, message:
      'Fieldset by text "FIELDSET LABEL" is not displayed on page'});
   await expect(await $(fieldsetPage.fieldsetByTextEqualsAndIndex('FIELDSET LABEL', 1).dataE2E)).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(16, 'There should be 16 <ux-fieldset> components on the page.');
  });
  it('should verify the presence of other CO in page and icon types ', async () => {
   browser.addTestMeta({zephyrStep: "327493"});
   let sectionId = 'label';
   let sectionElement = await $(fieldsetPage.fieldsetFromSectionById(sectionId).currentPath);
   await sectionElement.scrollIntoView();

   let fieldset1 = fieldsetPage.fieldsetFromSectionWithIdByIndex(sectionId, 1);
   await expect(await $(fieldset1.header)).toBeDisplayed({wait: 3000, message:'Fieldset by index "1" from Default section property header is not displayed on page'});
   await expect(await $(fieldset1.headerLabel)).toBeDisplayed({wait: 3000, message:
      'Fieldset by index "1" from Default section property headerLabel is not displayed on page'});
   await expect(await $(fieldset1.headerLabel)).toHaveTextContaining('FIELDSET LABEL');
   sectionId = 'typeClass-iconClass';
   sectionElement = await $(fieldsetPage.fieldsetFromSectionById(sectionId).currentPath);
   await sectionElement.scrollIntoView();
   await expect(await $(fieldsetPage.fieldsetFromSectionWithIdByIndex(sectionId,1).headerIcon)).toBeDisplayed({wait: 3000, message:
      'Fieldset by index "1" from typeClass-iconClass section property headerIcon is not displayed on page'});
   await expect(await fieldsetPage.fieldsetFromSectionWithIdByIndex(sectionId,1).typeclass()).toBe('info');
   await expect(await fieldsetPage.fieldsetFromSectionWithIdByIndex(sectionId,2).typeclass()).toBe('success');
   await expect(await fieldsetPage.fieldsetFromSectionWithIdByIndex(sectionId,3).typeclass()).toBe('warning');
   await expect(await fieldsetPage.fieldsetFromSectionWithIdByIndex(sectionId,4).typeclass()).toBe('danger');
  });
  it('should verify expanded state of fieldset ', async () => {
   browser.addTestMeta({zephyrStep: "327495"});
   let sectionId = 'isExpandable';
   let sectionElement = await $(fieldsetPage.fieldsetFromSectionById(sectionId).currentPath);
   await sectionElement.scrollIntoView();

   let fieldset1 = fieldsetPage.fieldsetFromSectionWithIdByIndex(sectionId, 1);
   await expect(await $(fieldset1.headerRightContent)).toBeDisplayed({wait: 3000, message:
      'Fieldset by index "1" from isExpandable section property headerRightContent is not displayed on page'});
   await expect(await $(fieldset1.headerExpandToggle)).toBeDisplayed({wait: 3000, message:
      'Fieldset by index "1" from isExpandable section property headerExpandToggle 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');
  });
  it('should verify content of fieldset  ', async () => {
   browser.addTestMeta({zephyrStep: "327496"});
   let sectionId = 'isLarge';
   let sectionElement = await $(fieldsetPage.fieldsetFromSectionById(sectionId).currentPath);
   await sectionElement.scrollIntoView();
   let fieldset1 = fieldsetPage.fieldsetFromSectionWithIdByIndex(sectionId, 1);
   await expect(await $(fieldset1.dataE2E)).toBeDisplayed({wait: 3000, message:
      'Fieldset by index "1" from isLarge section property dataE2E is not displayed on page'});
   await expect(await fieldset1.isLarge()).toBe(true, 'isLarge should be true');
  });
});
