import Routing from '../../../../pages/eui/10x/routing-10x.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'
import DashboardCard from '../../../../pages/eui/10x/ux/ux-dashboard-card.po.js.10x.js'

describe('should navigate to  <ux-dashboard-card> Component Object', async() => {
  let dashboardCard = new DashboardCard();
  it('should navigate to <ux-dashboard-card> component', async() => {
    browser.addTestMeta({uuid:"18aac2e0-71f9-11eb-9439-0242ac130002", zephyrKey: "CCQA-778", zephyrStep: "367053", reportGroups: ["eUI.10x.ux"]});
    dashboardCard.open(Routing.getUxComponentUrl('ux-dashboard-card'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(dashboardCard.pageTitle);
    let appDocPageId = await $(dashboardCard.appDocPageById('ux-dashboard-card'));
    let navigationList = await $(dashboardCard.navigationList);
    await pgTitle.scrollIntoView();
    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-dashboard-card> page title is not displayed on page'});
    await expect(pgTitle).toHaveText('ux-dashboard-card', {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 identify methods:dashboardCardByIndex,dashboardCardByTextContains,dashboardCardByTextEqualsAndIndex', async() => {
    browser.addTestMeta({zephyrStep: "367054"});
    await expect(await $(dashboardCard.sectionById('Default'))).toBeDisplayed({wait: 3000, message:
      '<Default> section -> is not displayed on page'});
    await expect(await $(dashboardCard.dashboardCardByIndex(1).currentPath)).toBeDisplayed({wait: 3000, message:
       'Dashboard-card by index "1" is not displayed on page'});
    await expect(await $(dashboardCard.dashboardCardByTextContains('LABEL').currentPath)).toBeDisplayed({wait: 3000, message:
      'Dashboard-card by text "LABEL" is not displayed on page'});
    await expect(await $(dashboardCard.dashboardCardByTextEqualsAndIndex('LABEL', 1).currentPath)).toBeDisplayed({wait: 3000, message:
       'Dashboard-card by text "LABEL" and index 1 is not displayed on page'});
    await chaiExpect(await dashboardCard.dashboardCardByIndex(1).defaultComponentsCount()).equal(45, 'There should be 45 <ux-dashboard-card> components on the page.')
  });
  it('should verify the Dashboard Card CO -  methods: cardContent, contentLabel, contentSublabel', async() => {
    browser.addTestMeta({zephyrStep: "367055"});
    let dashboardCard1 = dashboardCard.dashboardCardFromSectionWithIdByIndex('Default',1);
    await expect(await $(dashboardCard1.currentPath)).toBeDisplayed({wait: 3000, message:
      'Dashboard-card with index 1 from default section is not displayed on page'});
    let card1Text = await $(dashboardCard1.cardContent)
    await expect(card1Text).toHaveTextContaining('LABEL');
    await expect(card1Text).toHaveTextContaining('This is the sub label of the card');
    await expect(card1Text).toHaveTextContaining('more');
    await expect(await $(dashboardCard1.contentLabel)).toHaveTextContaining('LABEL');
    await expect(await $(dashboardCard1.contentSublabel)).toHaveTextContaining('This is the sub label of the card');
    await expect(await $(dashboardCard1.contentLink)).toBeDisplayed({wait: 3000, message:
       'dashboardCard1  content link - is not displayed on page'});
    await expect(await $(dashboardCard1.buttonLinkLabel)).toBeDisplayed({wait: 3000, message:
       'dashboardCard1  button link label - is not displayed on page'});

       let sectionId= 'iconClass';
    let scrollIntoSection = await $(dashboardCard.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let dashboardCard2 = dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(dashboardCard2.currentPath)).toBeDisplayed({wait: 3000, message:
      'Dashboard-card with index 2 from iconClass section is not displayed on page'});
    await expect(await $(dashboardCard2.cardIconContainer)).toBeDisplayed({wait: 3000, message:
      'dashboardCard2  cardIconContainer - is not displayed on page' });
    await expect(await dashboardCard2.hasIconContainer()).toBe(true);
    await expect(await $(dashboardCard2.iconWrapper)).toBeDisplayed({wait: 3000, message:
      'dashboardCard2  iconWrapper - is not displayed on page'});
    await expect(await $(dashboardCard2.iconWrapperIcon)).toBeDisplayed({wait: 3000, message:
      'dashboardCard2  iconWrapperIcon - is not displayed on page'});

      sectionId= 'imageUrl';
    scrollIntoSection = await $(dashboardCard.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let dashboardCard3 = dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(dashboardCard3.currentPath)).toBeDisplayed({wait: 3000, message:
      'Dashboard-card with index 2 from imageUrl section is not displayed on page'});
    await expect(await $(dashboardCard3.cardImageContainer)).toBeDisplayed({wait: 3000, message:
       'dashboardCard3  cardImageContainer - is not displayed on page'});
    await expect(await dashboardCard3.hasImageUrl()).toBe(true);
    await expect(await $(dashboardCard3.imageWrapper)).toBeDisplayed({wait: 3000, message:
      'dashboardCard3  imageWrapper - is not displayed on page'});
    await expect(await $(dashboardCard3.imageWrapperImage)).toBeDisplayed({wait: 3000, message:
      'dashboardCard3  imageWrapperImage - is not displayed on page'});
  });
  it('should verify the "isClickable", "isIconCompact", "isHorizontalLayout", "isIconCompactAndHorizontalLayout" methods', async() => {
    browser.addTestMeta({zephyrStep: "367056"});
    let sectionId = 'isClickable';
    let scrollIntoSection = await $(dashboardCard.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let dashboardCard1 = dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(dashboardCard1.currentPath)).toBeDisplayed({wait: 3000, message:
      'Dashboard-card with index 1 from isClickable section is not displayed on page'});
   await expect(await dashboardCard1.isClickable()).toBe(true);

    sectionId = 'Default';
    scrollIntoSection = await $(dashboardCard.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let dashboardCard2 = dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(dashboardCard1.currentPath)).toBeDisplayed({wait: 3000, message:
      'Dashboard-card with index 1 from default section is not displayed on page'});
    await expect(await dashboardCard2.isClickable()).toBe(false);
    await expect(await dashboardCard2.hasIconContainer()).toBe(false);
    await expect(await dashboardCard2.hasImageUrl()).toBe(false);
    await expect(await dashboardCard2.isIconCompact()).toBe(true);
    await expect(await dashboardCard2.isHorizontalLayout()).toBe(false);
    await expect(await dashboardCard2.isIconCompactAndHorizontalLayout()).toBe(false);

    sectionId = 'iconClass-isIconCompact';
    scrollIntoSection = await $(dashboardCard.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let dashboardCard3 = dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(dashboardCard3.currentPath)).toBeDisplayed({wait: 3000, message:
      'Dashboard-card with index 1 from iconClass-isIconCompact section is not displayed on page'});
    await expect(await dashboardCard3.isIconCompact()).toBe(false);

    sectionId = 'iconClass-isHorizontalLayout';
    scrollIntoSection = await $(dashboardCard.sectionById(sectionId));
    let dashboardCard4 = dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(dashboardCard4.currentPath)).toBeDisplayed({wait: 3000, message:
      'Dashboard-card with index 1 from iconClass-isHorizontalLayout section is not displayed on page'});
    await expect(await dashboardCard4.isHorizontalLayout()).toBe(true);
    await expect(await dashboardCard4.isIconCompactAndHorizontalLayout()).toBe(true);
  });
  it('should verify the "hasIconClass" method,typeClasses and styleClass', async() => {
    browser.addTestMeta({zephyrStep: "376786"});
    let sectionId= 'iconClass';
    let scrollIntoSection = await $(dashboardCard.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,1).hasIconClass()).toBe(true);

    sectionId= 'iconClass-iconTypeClass';
    scrollIntoSection = await $(dashboardCard.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,3).iconWrapper)).getAttribute('class')).toContain('info');
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,1).iconWrapper)).getAttribute('class')).toContain('primary');
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,2).iconWrapper)).getAttribute('class')).toContain('secondary');
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,4).iconWrapper)).getAttribute('class')).toContain('success');
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,5).iconWrapper)).getAttribute('class')).toContain('warning');
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,6).iconWrapper)).getAttribute('class')).toContain('danger');
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,7).iconWrapper)).getAttribute('class')).toContain('accent');
 
    sectionId= 'typeClass';
    scrollIntoSection = await $(dashboardCard.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,3).dataE2E)).getAttribute('class')).toContain('info');
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,1).dataE2E)).getAttribute('class')).toContain('primary');
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,2).dataE2E)).getAttribute('class')).toContain('secondary');
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,4).dataE2E)).getAttribute('class')).toContain('success');
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,5).dataE2E)).getAttribute('class')).toContain('warning');
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,6).dataE2E)).getAttribute('class')).toContain('danger');
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,7).dataE2E)).getAttribute('class')).toContain('accent');

    sectionId= 'buttonStyleClass';
    scrollIntoSection = await $(dashboardCard.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,3).buttonLinkLabel)).getAttribute('class')).toContain('outline');
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,1).buttonLinkLabel)).getAttribute('class')).toContain('small');
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,2).buttonLinkLabel)).getAttribute('class')).toContain('large');
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,4).buttonLinkLabel)).getAttribute('class')).toContain('rounded');

    sectionId= 'buttonTypeClass';
    scrollIntoSection = await $(dashboardCard.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,3).buttonLinkLabel)).getAttribute('class')).toContain('info');
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,1).buttonLinkLabel)).getAttribute('class')).toContain('primary');
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,2).buttonLinkLabel)).getAttribute('class')).toContain('secondary');
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,4).buttonLinkLabel)).getAttribute('class')).toContain('success');
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,5).buttonLinkLabel)).getAttribute('class')).toContain('warning');
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,6).buttonLinkLabel)).getAttribute('class')).toContain('danger');
    await expect(await (await $(dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,7).buttonLinkLabel)).getAttribute('class')).toContain('accent');
  });
  it('should verify the "maxLines#", "maxLines#" methods', async() => {
    browser.addTestMeta({zephyrStep: "376787"});
    let sectionId= 'labelMaxLines-subLabelMaxLines';
    let scrollIntoSection = await $(dashboardCard.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,1).maxLines()).toBe(1);
    await expect(await dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,2).maxLines()).toBe(2);
    await expect(await dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,3).maxLines()).toBe(3);
    await expect(await dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,4).maxLines()).toBe(4);
    await expect(await dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,5).maxLines()).toBe(5);
    await expect(await dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,1).maxSublines()).toBe(1);
    await expect(await dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,2).maxSublines()).toBe(2);
    await expect(await dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,3).maxSublines()).toBe(3);
    await expect(await dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,4).maxSublines()).toBe(4);
    await expect(await dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,5).maxSublines()).toBe(5);

    sectionId= 'events-onClicked';
    scrollIntoSection = await $(dashboardCard.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();

    await expect(await dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,1).isClickable()).toBe(false);
    await (await $('//input[@id="checkbox"]')).scrollIntoView();
    await (await $('//label[@for="checkbox"]')).click();
    await expect(await dashboardCard.dashboardCardFromSectionWithIdByIndex(sectionId,1).isClickable()).toBe(true);
  });
});
