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

describe('eUI - <ux-timebar> Component Object', async () => {
  let page = new TimebarPage();
  it('should navigate to <ux-timebar> component', async () => {
    browser.addTestMeta({uuid:"91ae1800-b31b-11eb-8529-0242ac130003", zephyrKey: "CCQA-835", zephyrStep: "371772", reportGroups: ["eUI.10x.ux"]});
    await page.open(Routing.getUxComponentUrl('ux-timebar'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-timebar> page title is not visible on page'});
    await expect(pgTitle).toHaveText('ux-timebar', 'Page title text is not as expected')
    await expect(await $(page.appDocPageById('ux-timebar'))).toExist({wait:1000, message:'Page Id is not present in page'});
    await expect(await $(page.navigationList)).toBeDisplayed({wait:1000, message:'Navigation List -> is not visible on page'});
  });
  it('should verify the visibility and number of component objects <ux-timebar> on page', async () => {
    browser.addTestMeta({zephyrStep: "371773"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await $(page.timebarByIndex(1).dataE2E)).toBeDisplayedInViewport({message:'Timebar by index 1 is not visible on page'});
    await expect(await $(page.timebarByTextContains('2014-01-01').dataE2E)).
      toBeDisplayedInViewport({message:'Timebar by text "2014-01-01" is not visible on page'});
    await expect(await $(page.timebarByTextEqualsAndIndex('2014-01-01', 1).dataE2E)).
     toBeDisplayedInViewport({message:'Timebar by text "2014-01-01" and index 1 is not visible on page'});
    await expect(await $$(page.timebarByIndex(1).byDefault().dataE2E)).toBeElementsArrayOfSize(15);
  });
  it('should verify the  ux-timebar methods: hasTimebarStartLabel, hasTimebarEndLabel ', async () => {
    browser.addTestMeta({zephyrStep: "371774"});
    let sectionId= 'startLabel-endLabel';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let timebar= page.timebarFromSectionWithIdByIndex(sectionId,1);
    await chaiExpect(await timebar.hasTimebarStartLabel()).equal(true,'hasTimebarStartLabel should be true');
    await chaiExpect(await timebar.hasTimebarEndLabel()).equal(true,'hasTimebarEndLabel should be true');
   });
  it('should verify the ux-timebar methods:  timebarStartLabel, timebarEndLabel, timebar ', async () => {
    browser.addTestMeta({zephyrStep: "371775"});
    let sectionId = 'startLabel-endLabel';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let timebar= page.timebarFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(timebar.timebarStartLabel)).
      toBeDisplayedInViewport({message:'Timebar timebarStartLabel from startLabel-endLabel section is not visible on page'});
    await expect(await $(timebar.timebarEndLabel)).
      toBeDisplayedInViewport({message:'Timebar timebarEndLabel from startLabel-endLabel  section is not visible on page'});
    await expect(await $(timebar.timebar)).
      toBeDisplayedInViewport({message:'Timebar timebar from startLabel-endLabel  section is not visible on page'});
  });
  it('should verify the  ux-timebar methods: isShowCurrentDateMarker, hasMarkedDate  ', async () => {
    browser.addTestMeta({zephyrStep: "371776"});
    let sectionId= 'isShowCurrentDateMarker';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let timebar= page.timebarFromSectionWithIdByIndex(sectionId,1);
    await chaiExpect(await timebar.isShowCurrentDateMarker()).equals(true,'isShowCurrentDateMarker should be true');
    sectionId = 'Default';
    scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    timebar = page.timebarFromSectionWithIdByIndex(sectionId,1);
    await chaiExpect(await timebar.isShowCurrentDateMarker()).equals(false,'isShowCurrentDateMarker should be false');
    sectionId = 'markedDate-custom';
    scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    timebar = page.timebarFromSectionWithIdByIndex(sectionId,1);
    await chaiExpect(await timebar.hasMarkedDate()).equals(true,'hasMarkedDate should be true');
  });
  it('should verify the ux-timebar method timebarStepCO and  ux-timebar-step method dateItem ', async () => {
    browser.addTestMeta({zephyrStep: "371777"});
    let sectionId = 'isShowCurrentDateMarker';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let timebar= page.timebarFromSectionWithIdByIndex(sectionId,1);
    await (await $(timebar.currentPath)).scrollIntoView();
    await expect(await $(timebar.timebarStepCO.currentPath)).toBeDisplayedInViewport({message:'timebarStepCO.currentPath from isShowCurrentDateMarker section is not visible on page'});
    await expect(await $(timebar.timebarStepCO.dateItem)).toBeDisplayedInViewport({message:'Timebar dateItem from isShowCurrentDateMarker section is not visible on page'});
  });
  it('should verify the ux-timebar-step method label ', async () => {
    browser.addTestMeta({zephyrStep: "371778"});
    let sectionId= 'isShowCurrentDateMarker';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let timebar= page.timebarFromSectionWithIdByIndex(sectionId,1);
    await (await $(timebar.currentPath)).scrollIntoView();
    await expect(await $(timebar.timebarStepCO.label)).toBeDisplayedInViewport({message:'timebarStepCO.label from isShowCurrentDateMarker section is not visible on page'});
   });
  it('should verify the  ux-timebar methods: dateMarker, dateMarkerStep', async () => {
    browser.addTestMeta({zephyrStep: "371781"});
    let sectionId= 'markedDate-isShowCurrentDateMarker';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let timebar= page.timebarFromSectionWithIdByIndex(sectionId,1);
    await (await $(timebar.currentPath)).scrollIntoView();
    await expect(await $(timebar.dateMarker)).toBeDisplayedInViewport({message:'Timebar dateMarker from markedDate-isShowCurrentDateMarker section is not visible on page'});
    await expect(await $(timebar.dateMarkerStep)).
      toBeDisplayedInViewport({message:'Timebar dateMarkerStep from markedDate-isShowCurrentDateMarker section is not visible on page'});
  });
  it('should verify the  ux-timebar methods: isShowLegend ', async () => {
    browser.addTestMeta({zephyrStep: "371782"});
    let sectionId= 'startLabel-endLabel';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let timebar = page.timebarFromSectionWithIdByIndex(sectionId,1);
    await chaiExpect(await timebar.isShowLegend()).equal(false,'isShowLegend should be false');
    sectionId = 'isShowLegendAsIndex';
    scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    timebar = page.timebarFromSectionWithIdByIndex(sectionId,1);
    await chaiExpect(await timebar.isShowLegend()).equal(true,'isShowLegend should be true');
  });
  it('should verify the ux-timebar methods: secondContainer, timebarLegend, timebarLegendItemCO', async () => {
    browser.addTestMeta({zephyrStep: "371783"});
    let sectionId= 'isShowLegend';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let timebar= page.timebarFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(timebar.secondContainer)).
      toBeDisplayedInViewport({message:'Timebar secondContainer from isShowLegend section is not visible on page'});
    await expect(await $(timebar.timebarLegend)).
      toBeDisplayedInViewport({message:'Timebar timebarLegend from isShowLegend section is not visible on page'});
    await expect(await $(timebar.timebarLegendItemCO.currentPath)).
      toBeDisplayedInViewport({message:'Timebar timebarLegendItemCO from isShowLegend section is not visible on page'});
  });
  it('should verify the ux-timebar-legend-item method: isShowLegendAsIndexGenerated', async () => {
    browser.addTestMeta({zephyrStep: "371784"});
    let sectionId = 'isShowLegend';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let timebar = page.timebarFromSectionWithIdByIndex(sectionId,1);
    await chaiExpect(await timebar.timebarLegendItemCO.isShowLegendAsIndexGenerated()).equal(true,'isShowLegendAsIndexGenerated should be true');
    sectionId = 'isShowLegendAsIndex';
    scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    timebar = page.timebarFromSectionWithIdByIndex(sectionId,1);
    await (await $(timebar.currentPath)).scrollIntoView();
    await chaiExpect(await timebar.timebarLegendItemCO.isShowLegendAsIndexGenerated()).equal(false,'isShowLegendAsIndexGenerated should be false');
  });
  it('should verify the ux-timebar-legend-item methods: label, indexWrapper', async () => {
    browser.addTestMeta({zephyrStep: "371785"});
    let sectionId= 'isShowLegend';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let timebar= page.timebarFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(timebar.timebarLegendItemCO.indexWrapper)).
      toBeDisplayedInViewport({message:'Timebar-legend-item indexWrapper from isShowLegend section is not visible on page'});
    await expect(await $(timebar.timebarLegendItemCO.label)).
      toBeDisplayedInViewport({message:'Timebar-legend-item label from isShowLegend section is not visible on page'});
  });
  it('should verify the stepType-items color ', async () => {
    browser.addTestMeta({zephyrStep: "372148"});
    let sectionId= 'stepType-items';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let timebarStep= page.timebarFromSectionWithIdByIndex(sectionId,1).timebarStepCO;
    await chaiExpect(await (await $(timebarStep.byIndex(2).currentPath)).getAttribute('class')).contains('info');
    await chaiExpect(await (await $(timebarStep.byIndex(3).currentPath)).getAttribute('class')).contains('success');
    await chaiExpect(await (await $(timebarStep.byIndex(4).currentPath)).getAttribute('class')).contains('warning');
    await chaiExpect(await (await $(timebarStep.byIndex(5).currentPath)).getAttribute('class')).contains('danger');
  });
  it('should verify the  ux-timebar-step method: isGroupedStep ', async () => {
    browser.addTestMeta({zephyrStep: "372149"});
    let sectionId= 'isGroupOverlappingLabels';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let timebar= page.timebarFromSectionWithIdByIndex(sectionId,1);
    await chaiExpect(await timebar.timebarStepCO.byIndex(1).isGroupedStep()).equal(false,'isGroupedStep should be false');
    await chaiExpect(await timebar.timebarStepCO.byIndex(2).isGroupedStep()).equal(true,'isGroupedStep should be true');
   });
  it('should verify the ux-timebar-legend-item methods: itemIcon, circleIcon, isMobile ', async () => {
    browser.addTestMeta({zephyrStep: "372166"});
    let sectionId= 'isShowLegendAsIndex';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let timebar= page.timebarFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(timebar.timebarLegendItemCO.currentPath)).
      toBeDisplayedInViewport({message:'Timebar-legend-item timebarLegendCO from isShowLegend section is not visible on page'});
    await expect(await $(timebar.timebarLegendItemCO.itemIcon)).
      toBeDisplayedInViewport({message:'Timebar-legend-item legendItemIcon from isShowLegend section is not visible on page'});
    await expect(await $(timebar.timebarLegendItemCO.circleIcon)).
      toBeDisplayedInViewport({message:'Timebar-legend-item circleIcon from isShowLegend section is not visible on page'});
    await chaiExpect(await timebar.timebarStepCO.isMobile()).equal(false,'isMobile should be false');
    });
  it('should verify the visibility and number of component objects <ux-timebar-step> on page', async () => {
    browser.addTestMeta({zephyrStep: "372408"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let timebarStep = page.timebarByIndex(1).timebarStepCO;
    await expect(await $(timebarStep.currentPath)).
      toBeDisplayedInViewport({message:'Timebarstep currentpath is not visible on page'});
    await expect(await $(timebarStep.byIndex(1).currentPath)).
      toBeDisplayedInViewport({message:'Timebarstep by index 1 is not visible on page'});
    await expect(await $(timebarStep.byTextContains('2014-01-01').currentPath)).
      toBeDisplayedInViewport({message:'Timebarstep by text "2014-01-01" is not visible on page'});
    await expect(await $$(timebarStep.byDefault().currentPath)).toBeElementsArrayOfSize(3);
  });
  it('should verify the ux-timebar_step and ux-timebar__legend-item size', async () => {
    browser.addTestMeta({zephyrStep: "372754"});
    let sectionId = 'isShowCurrentDateMarker';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let step = page.timebarFromSectionWithIdByIndex(sectionId,1).timebarStepCO;
    await expect(await $$(step.byDefault().currentPath)).toBeElementsArrayOfSize(3);
    sectionId = 'isShowLegend';
    scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let legend = page.timebarFromSectionWithIdByIndex(sectionId,1).timebarLegendItemCO;
    await expect(await $$(legend.byDefault().currentPath)).toBeElementsArrayOfSize(18);
  });
  it('should verify the ux-timebar-step methods: groupedSteps', async () => {
    browser.addTestMeta({zephyrStep: "372766"});
    let sectionId = 'isGroupOverlappingLabels';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let step = page.timebarFromSectionWithIdByIndex(sectionId,1).timebarStepCO;
    await expect(await $(step.groupedStep)).toBeDisplayedInViewport({message:'groupedStep from isGroupOverlappingLabels section is not visible on page'});
    step = page.timebarFromSectionWithIdByIndex(sectionId,1).timebarStepCO.byIndex(2);
  });
  it('should verify values of component objects <ux-timebar-step> on page', async () => {
    browser.addTestMeta({zephyrStep: "372933"});
    let sectionId= 'isGroupOverlappingLabels';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let step = page.timebarFromSectionWithIdByIndex(sectionId,1).timebarStepCO;
    await expect(await $(step.byIndex(1).labelSpan)).
     toHaveText('item 1',{message:'labelSpan from isGroupOverlappingLabels section should have text item 1'});
    await expect(await $(step.byIndex(2).labelSpan)).
      toHaveText('1, 2',{message:'labelSpan from isGroupOverlappingLabels section should have text 1, 2'});
    await expect(await $(step.byIndex(3).labelSpan)).
      toHaveText('item 4',{message:'labelSpan from isGroupOverlappingLabels section should have text item 4'});
    await expect(await $(step.byIndex(4).labelSpan)).
      toHaveText('3, 4, 5',{message:'labelSpan from isGroupOverlappingLabels section should have text 1, 2'});
    await expect(await $(step.byIndex(5).labelSpan)).
      toHaveText('item 8',{message:'labelSpan from isGroupOverlappingLabels section should have text item 8'});
    await expect(await $(step.byIndex(1).dateItem)).
      toHaveText('2014-01-01',{message:'dateItem from isGroupOverlappingLabels section should have text 2014-01-01'});
    await expect(await $(step.byIndex(2).dateItem)).
      toHaveTextContaining('2015-11-01',{message:'dateItem from isGroupOverlappingLabels section should have text 2015-11-01'});
    await expect(await $(step.byIndex(2).dateItem)).
      toHaveTextContaining('2015-10-01',{message:'dateItem from isGroupOverlappingLabels section should have text 2015-10-01'});
    await expect(await $(step.byIndex(3).dateItem)).
      toHaveText('2016-07-04',{message:'dateItem from isGroupOverlappingLabels section should have text 2016-07-04'});
    await expect(await $(step.byIndex(4).dateItem)).
      toHaveTextContaining('2017-12-01',{message:'dateItem from isGroupOverlappingLabels section should have text 2017-12-01'});
    await expect(await $(step.byIndex(4).dateItem)).
      toHaveTextContaining('2018-03-01',{message:'dateItem from isGroupOverlappingLabels section should have text 2018-03-01'});
    await expect(await $(step.byIndex(5).dateItem)).
      toHaveText('2019-06-01',{message:'dateItem from isGroupOverlappingLabels section should have text 2019-06-01'});
  });
});
