import Routing from '../../../../pages/eui/10x/routing-10x.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'
import AlabelPage from '../../../../pages/eui/10x/ux/ux-a-label-10x.po.js'

describe('eUI - <ux-a-label> Component Object @CCQA-702', async() => {
  let labelPage = new AlabelPage();
  it('should navigate to <ux-a-label> component ', async() => {
    browser.addTestMeta({uuid:"e4df9ca0-782f-11eb-9439-0242ac130002", zephyrKey: "CCQA-702", zephyrStep: "354117", reportGroups: ["eUI.10x.ux"]});
    await labelPage.open(Routing.getUxComponentUrl('ux-a-label'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(labelPage.pageTitle);
    let appDocPageId = await $(labelPage.appDocPageById('ux-a-label'));
    let navigationList = await $(labelPage.navigationList);
    await pgTitle.scrollIntoView();
    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-a-label> page title is not visible on page'});
    await expect(pgTitle).toHaveText('ux-a-label', {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 visible on page'});
  });
  it('should verify the presence of the Component Object on the page ', async() => {
    browser.addTestMeta({zephyrStep: "354118"});
    let dataE2e1 = await $(labelPage.labelFromSectionById('Default').dataE2E);
    let dataE2e2 = await $(labelPage.labelByIndex(1).dataE2E)
    let dataE2e3 = await $(labelPage.labelByTextContains('Label').dataE2E);
    let dataE2e4 = await $(labelPage.labelByTextEqualsAndIndex('Label', 1).dataE2E);
    await expect(dataE2e1).toBeDisplayed({wait:1000, message:'<Default> section -> is not visible on page'});
    await expect(dataE2e2).toBeDisplayed({wait:1000, message:'Label by index "1" is not visible on page'});
    await expect(dataE2e3).toBeDisplayed({wait:1000, message:'Label by text "Label" is not visible on page'});
    await expect(dataE2e4).toBeDisplayed({wait:1000, message:'Label by text "Label" and index 1 is not visible on page'});
  //  await expect(await $(labelPage.labelByIndex(1).byDefault().currentPath).length).toBe(32);
    await chaiExpect(await labelPage.labelByIndex(1).defaultComponentsCount()).equal(32, 'There should be 32 <ux-a-label> components on the page.')
  });
  it('should verify the presence of the main elements of the Component Object on the page ', async() => {
    browser.addTestMeta({zephyrStep: "354119"});
    let sectionId= 'hasMarker';
    let scrollIntoSection = await $(labelPage.labelFromSectionById(sectionId).dataE2E);
    await scrollIntoSection.scrollIntoView();

    let labelPage1 = labelPage.labelFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(labelPage1.dataE2E)).toBeDisplayed({wait:1000, message:'Label with index 1 from hasMarker section is not visible on page'});
    await expect(await labelPage1.hasMarker()).toBe(true, 'hasMarker should be true ');

    sectionId= 'subLabel';
    scrollIntoSection = await $(labelPage.labelFromSectionById(sectionId).dataE2E);
    await scrollIntoSection.scrollIntoView();
    labelPage1 = labelPage.labelFromSectionWithIdByIndex(sectionId,1);

    await expect(await $(labelPage1.labelContent)).toBeDisplayed({wait:1000, message:
      'Label with index 1 from subLabel section is not visible on page'});

    await expect(await (await $(labelPage1.labelContentLabel)).getText()).toBe('Label');
    await expect(await (await $(labelPage1.subLabel)).getText()).toBe('Sub label');

    sectionId= 'custom-label';
    scrollIntoSection = await $(labelPage.labelFromSectionById(sectionId).dataE2E);
    await scrollIntoSection.scrollIntoView();
    labelPage1 = labelPage.labelFromSectionWithIdByIndex(sectionId,1);

    await expect(await $(labelPage1.customLabel)).toBeDisplayed({wait:1000, message:
      'Label with index 1 from custom-label section is not visible on page'});

    await expect(await (await $(labelPage1.customLabel)).getText()).toContain('Label with formatted HTML and internal link or external link');

    sectionId= 'custom-subLabel';
    scrollIntoSection = await $(labelPage.labelFromSectionById(sectionId).dataE2E);
    await scrollIntoSection.scrollIntoView();
    labelPage1 = labelPage.labelFromSectionWithIdByIndex(sectionId,1);

    await expect(await $(labelPage1.labelContent)).toBeDisplayed({wait:1000, message:
      'Label with index 1 from custom-subLabel section is not visible on page'});
    await expect(await (await $(labelPage1.subLabel)).getText()).toContain('Custom content');
});
it('should verify the labels with badge', async() => {
  browser.addTestMeta({zephyrStep: "354120"});
  let sectionId= 'badgeLabel';
  let label = await $(labelPage.labelFromSectionById(sectionId).dataE2E);
  await label.scrollIntoView();
  let labelPage1 = labelPage.labelFromSectionWithIdByIndex(sectionId,1);

  await expect(await $(labelPage1.badgeCO.currentPath)).toBeDisplayed({wait:1000, message:
    'Label with index 1 from badgeLabel section is not visible on page'});
  await expect(await (await $(labelPage1.badgeCO.currentPath)).getText()).toContain('badgeLabel');

  sectionId= 'badgeLabel-badgeTypeClass';
  label = await $(labelPage.labelFromSectionById(sectionId).dataE2E);
  await label.scrollIntoView();
  labelPage1 = labelPage.labelFromSectionWithIdByIndex(sectionId,1);

  await expect(await $(labelPage1.badgeCO.currentPath)).toBeDisplayed({wait:1000, message:
    'Label with index 1 from badgeLabel-badgeTypeClass section is not visible on page'});
  await expect(await (await $(labelPage1.badgeCO.currentPath)).getAttribute('styleClass')).toBe('ml-2', 'badgeStyleClass should be ml-2 ');
  await expect(await (await $(labelPage.labelFromSectionWithIdByIndex(sectionId,1).badgeCO.badgeDataSpan)).getAttribute('class')).toContain('primary');
  await expect(await (await $(labelPage.labelFromSectionWithIdByIndex(sectionId,2).badgeCO.badgeDataSpan)).getAttribute('class')).toContain('default');
  await expect(await (await $(labelPage.labelFromSectionWithIdByIndex(sectionId,3).badgeCO.badgeDataSpan)).getAttribute('class')).toContain('info');
  await expect(await (await $(labelPage.labelFromSectionWithIdByIndex(sectionId,4).badgeCO.badgeDataSpan)).getAttribute('class')).toContain('success');
  await expect(await (await $(labelPage.labelFromSectionWithIdByIndex(sectionId,5).badgeCO.badgeDataSpan)).getAttribute('class')).toContain('warning');
  await expect(await (await $(labelPage.labelFromSectionWithIdByIndex(sectionId,6).badgeCO.badgeDataSpan)).getAttribute('class')).toContain('danger');

  await expect(await labelPage1.badgeCO.isPill()).toBe(true, 'badgeCO.isPill() should be true ');
  await expect(await labelPage1.badgeCO.isSmall()).toBe(true, 'badgeCO.isSmall() should be true ');
  await expect(await labelPage1.hasMarker()).toBe(false, 'hasMarker should be false ');
  });
  it('should verify hasMarker, markerTypeClass ', async() => {
    browser.addTestMeta({zephyrStep: "354121"});
    let sectionId= 'hasMarker-markerTypeClass';
    let scrollIntoSection = await $(labelPage.labelFromSectionById(sectionId).dataE2E);
    await scrollIntoSection.scrollIntoView();
    let labelPage1 = labelPage.labelFromSectionWithIdByIndex(sectionId,1);

    //hasMarker
   await expect(await labelPage1.hasMarker()).toBe(true, 'hasMarker should be true ');
    // markerTypeClass
   await expect(await (await $(labelPage.labelFromSectionWithIdByIndex(sectionId,1).markerCO.icon)).getAttribute('class')).toContain('primary');
   await expect(await (await $(labelPage.labelFromSectionWithIdByIndex(sectionId,2).markerCO.icon)).getAttribute('class')).toContain('info');
   await expect(await (await $(labelPage.labelFromSectionWithIdByIndex(sectionId,3).markerCO.icon)).getAttribute('class')).toContain('success');
   await expect(await (await $(labelPage.labelFromSectionWithIdByIndex(sectionId,4).markerCO.icon)).getAttribute('class')).toContain('warning');
   await expect(await (await $(labelPage.labelFromSectionWithIdByIndex(sectionId,5).markerCO.icon)).getAttribute('class')).toContain('danger');
  });
  it('should verify the labels with icon ', async() => {
   browser.addTestMeta({zephyrStep: "354122"});
   let sectionId= 'iconClass-iconTypeClass';
   let scrollIntoSection = await $(labelPage.labelFromSectionById(sectionId).dataE2E);
   await scrollIntoSection.scrollIntoView();
   let labelPage1 = labelPage.labelFromSectionWithIdByIndex(sectionId,1);
   await (await $(labelPage1.iconCO.currentPath)).waitForDisplayed({timeout:1000, reverse:false, timeoutMsg:
      'Label with index 1 from iconClass-iconTypeClass section is not visible on page', interval:100});

   await expect(await labelPage1.iconStyleClass()).toBe('mr-2', 'iconStyleClass should be mr-2 ');
   await expect(await (await $(labelPage.labelFromSectionWithIdByIndex(sectionId,1).iconCO.iconContent)).getAttribute('class')).toContain('primary');
   await expect(await (await $(labelPage.labelFromSectionWithIdByIndex(sectionId,2).iconCO.iconContent)).getAttribute('class')).toContain('info');
   await expect(await (await $(labelPage.labelFromSectionWithIdByIndex(sectionId,3).iconCO.iconContent)).getAttribute('class')).toContain('success');
   await expect(await (await $(labelPage.labelFromSectionWithIdByIndex(sectionId,4).iconCO.iconContent)).getAttribute('class')).toContain('warning');
   await expect(await (await $(labelPage.labelFromSectionWithIdByIndex(sectionId,5).iconCO.iconContent)).getAttribute('class')).toContain('danger');
    });
  it('should verify isRenderHTML, isSmall, isClickable, infos ', async() => {
   browser.addTestMeta({zephyrStep: "381269"});
   let sectionId= 'isRenderHTML';
   let scrollIntoSection = await $(labelPage.labelFromSectionById(sectionId).dataE2E);
   await scrollIntoSection.scrollIntoView();
   let labelPage1 = labelPage.labelFromSectionWithIdByIndex(sectionId,1);
   await expect(await $(labelPage1.labelContent)).toBeDisplayed({wait:1000, message:
      'Label with index 1 from isRenderHTML section is not visible on page'});
   await expect(await labelPage1.isRenderHTML()).toBe(true, 'isRenderHTML should be true ');

   sectionId= 'isSmall';
   scrollIntoSection = await $(labelPage.labelFromSectionById(sectionId).dataE2E);
   await  scrollIntoSection.scrollIntoView();
   labelPage1 = labelPage.labelFromSectionWithIdByIndex(sectionId,1);

   await expect(await $(labelPage1.labelContent)).toBeDisplayed({wait:1000, message:
      'Label with index 1 from isSmall section is not visible on page'});
   await expect(await labelPage1.isSmall()).toBe(true, 'isSmall should be true ');

   sectionId= 'custom-label';
   scrollIntoSection = await $(labelPage.labelFromSectionById(sectionId).dataE2E);
   await scrollIntoSection.scrollIntoView();
   labelPage1 = labelPage.labelFromSectionWithIdByIndex(sectionId,1);
   await expect(await $(labelPage1.clickableLink)).toBeDisplayed({wait:1000, message:
      'Label with index 1 from custom-label section is not visible on page'});
   await expect(await (await $(labelPage1.clickableLink)).getText()).toContain('internal link');
   await expect(await (await $(labelPage1.clickableLink)).getAttribute('href')).toContain('/eui-showcase-ux-10.x/');
   await expect(await labelPage1.isClickable()).toBe(true, 'isClickable should be true ');

   sectionId= 'badgeLabel-infos';
   scrollIntoSection = await $(labelPage.labelFromSectionById(sectionId).dataE2E);
   await scrollIntoSection.scrollIntoView();
   labelPage1 = labelPage.labelFromSectionWithIdByIndex(sectionId,1);
   await expect(await $(labelPage1.infos)).toBeDisplayed({wait:1000, message:
      'Label with index 1 from badgeLabel-infos section is not visible on page'});
   await expect(await (await $(labelPage1.infos)).getText()).toContain('additional information text');
   });
});
