import Routing from '../../../../pages/eui/10x/routing-10x.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'
import ListItem from '../../../../pages/eui/10x/ux/ux-list-item-10x.po.js'

describe('eUI  <ux-list-item> Component Object', async () => {
  let listItemPage = new ListItem();
  it('should navigate to <ux-list-item> component', async () => {
    browser.addTestMeta({uuid:"f0dc183c-7c1a-11eb-9439-0242ac130002", zephyrKey: "CCQA-803", zephyrStep: "368894", reportGroups: ["eUI.10x.ux"]});
    await listItemPage.open(Routing.getUxComponentUrl('ux-list-item'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(listItemPage.pageTitle);
    let appDocPageId = await $(listItemPage.appDocPageById('ux-list-item'));
    let navigationList = await $(listItemPage.navigationList);

    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-list-item> page title is not displayed on page'});
    await expect(pgTitle).toHaveText('ux-list-item', {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 and number of component objects <ux-list-item> on page ', async () => {
    browser.addTestMeta({zephyrStep: "368895"});
    await expect(await $(listItemPage.sectionById('Default'))).toBeDisplayed({wait: 3000, message:'<Default> section -> is not displayed on page'});
    await expect(await (await listItemPage.listItemByIndex(1).element())).toBeDisplayed({wait: 3000, message:'List-item by index "1" is not displayed on page'});
    await expect(await (await listItemPage.listItemByTextContains('Item 1').element())).toBeDisplayed({wait: 3000, message:'List-item by text "Item 1" is not displayed on page'});
    await expect(await (await $$(listItemPage.listItemByIndex(1).byDefault().listItemDataDiv)).length).toBe(72);
  });
  it('should verify the presence and number of component objects <ux-list-items> on page ', async () => {
    browser.addTestMeta({zephyrStep: "368896"});
    await expect(await (await listItemPage.listItemsByIndex(1).element())).toBeDisplayed({wait: 3000, message:'List-items by index "1" is not displayed on page'});
    await expect(await (await listItemPage.listItemsByTextContains('Item 1').element())).toBeDisplayed({wait: 3000, message:'List-items by text "Item 1" is not displayed on page'});
    await expect(await (await listItemPage.listItemsByTextEqualsAndIndex('Item 1', 1).element())).toBeDisplayed({wait: 3000, message:
      'List-items by text "Item 1" and index 1 is not displayed on page'});
    await expect(await (await $$(listItemPage.listItemsByIndex(1).byDefault().listItemsDataUl)).length).toBe(19);
  });
  it('should verify the list-item CO methods: listItem, rightContent ', async () => {
    browser.addTestMeta({zephyrStep: "368897"});
    let sectionId = 'Default';
    let scrollIntoSection = await $(listItemPage.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,1).listItem)).toBeDisplayed({wait: 3000, message:
      'List-item with index 1 from Default section is not displayed on page'});
    await expect(await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,1).rightContent)).toBeExisting({wait: 3000, message:
      'List-item with index 1 from typeClass section is not displayed on page'});

    sectionId ='typeClass';
    scrollIntoSection = await $(listItemPage.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,12).rightContent)).toBeDisplayed({wait: 3000, message:
      'List-item with index 12 from typeClass section is not displayed on page'});
  });
  it('should verify the list-item CO methods: isSmall, isLarge, notHoverable, isHovered ', async () => {
    browser.addTestMeta({zephyrStep: "368898"});
    let sectionId = 'Default';
    let scrollIntoSection = await $(listItemPage.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,11).isSmall()).toBe(true, 'The isSmall should be true');
    await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,12).isSmall()).toBe(false, 'The isSmall should be false');
    await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,12).isLarge()).toBe(true, 'The isLarge should be true');
    await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,11).isLarge()).toBe(false, 'The isLarge should be false');
    await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,13).isHoverable()).toBe(false, 'The NotHoverable should be false');
    await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,11).isHoverable()).toBe(true, 'The NotHoverable should be true');
    await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,13).isHovered()).toBe(false, 'The isHovered should be false');
  });
  it('should verify the list-item CO methods: hasBorder, isCollapsed, isActive, hasSeperator, isDisabled ', async () => {
    browser.addTestMeta({zephyrStep: "368899"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(listItemPage.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,1).hasBorder()).toBe(true, 'The hasBorder should be true');
    await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,1).hasSeperator()).toBe(false, 'The seperator should be false');

    sectionId= 'typeClass';
    scrollIntoSection = await $(listItemPage.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,1).isCollapsed()).toBe(false, 'The isCollapsed should be false');
    await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,42).isActive()).toBe(true, 'The isActive should be true');
    await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,41).isActive()).toBe(false, 'The isActive should be false');
    await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,1).hasBorder()).toBe(true, 'The hasBorder should be true');
    await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,1).hasBorder()).toBe(true, 'The hasBorder should be true');
    await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,42).isDisabled()).toBe(false, 'The isDisabled should be false');

  });
  it('should verify the list-item CO methods: listLabel, rightContentTag ', async () => {
    browser.addTestMeta({zephyrStep: "368900"});
    let sectionId = 'Default';
    let scrollIntoSection = await $(listItemPage.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let listLabel1 = await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,1).listLabel.currentPath);
    await expect(listLabel1).toBeDisplayed({wait: 3000, message:
      'List-item with index 1 from Default section with listLabel is not displayed on page'});
    await expect(listLabel1).toHaveText('Item 1', 'The listLabel text should be "Item 1"');

    sectionId = 'typeClass';
    scrollIntoSection = await $(listItemPage.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,12).rightContentTag.currentPath)).toBeDisplayed({wait: 3000, message:
      'List-item with index 12 from typeClass section with rightContentTag is not displayed on page'});
  });
  it('should verify the list-items CO method: listTitle ', async () => {
    browser.addTestMeta({zephyrStep: "368901"});
    await expect( await $(listItemPage.listItemsByIndex(3).listTitle)).toBeDisplayed({wait: 3000, message:
      'List-items with index 3 with listTitle is not displayed on page'});
  });
  it('should verify the methods: customSubLabel ', async () => {
    browser.addTestMeta({zephyrStep: "368902"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(listItemPage.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let customSubLabel1 = await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,9).listLabel.subLabel);
    await expect(customSubLabel1).toBeDisplayed({wait: 3000, message:
      'List-item with index 9 from Default section with customSubLabel is not displayed on page'});
    await expect(customSubLabel1).toHaveText('sub label', 'The customSubLabel text should be "sub label"');
  });
  it('should verify the list-item CO typeClass, iconClass, iconTypeClass ', async () => {
    browser.addTestMeta({zephyrStep: "368903"});
    let sectionId= 'typeClass';
    let scrollIntoSection = await $(listItemPage.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,2).typeClass()).toBe('info');
    await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,1).typeClass()).toBe('primary');
    await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,3).typeClass()).toBe('success');
    await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,4).typeClass()).toBe('warning');
    await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,5).typeClass()).toBe('danger');
    let sectionTitle= 'With icon : iconClass / iconTypeClass';
    scrollIntoSection = await $(listItemPage.sectionPartBySectionTitle(sectionTitle));
    await scrollIntoSection.scrollIntoView();
    // iconClass
    await expect(await (await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,30).listLabel.iconCO.iconContent)).getAttribute('data-e2e')).toContain('ux-a-icon');
    // iconTypeClass
   await expect(await (await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,31).listLabel.iconCO.iconContent)).getAttribute('class')).toContain('primary');
   await expect(await (await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,32).listLabel.iconCO.iconContent)).getAttribute('class')).toContain('info');
   await expect(await (await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,33).listLabel.iconCO.iconContent)).getAttribute('class')).toContain('success');
   await expect(await (await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,34).listLabel.iconCO.iconContent)).getAttribute('class')).toContain('warning');
   await expect(await (await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,35).listLabel.iconCO.iconContent)).getAttribute('class')).toContain('danger');
    // isIconRounded
   await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,36).listLabel.iconCO.isRounded()).toBe(true);
  });
  it('should verify the list-item CO hasMarker, markerTypeClass ', async () => {
    browser.addTestMeta({zephyrStep: "378036"});
    let sectionId= 'typeClass';
    let sectionTitle= 'with marker : hasMarker=true / markerTypeClass';
    let scrollIntoSection = await $(listItemPage.sectionPartBySectionTitle(sectionTitle));
    await scrollIntoSection.scrollIntoView();
    //hasMarker
    await expect(await (await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,6).listLabel.markerCO.icon)).getAttribute('class')).toContain('ux-a-marker__icon');
    // markerTypeClass
    await expect(await (await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,7).listLabel.markerCO.icon)).getAttribute('class')).toContain('primary');
    await expect(await (await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,8).listLabel.markerCO.icon)).getAttribute('class')).toContain('info');
    await expect(await (await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,9).listLabel.markerCO.icon)).getAttribute('class')).toContain('success');
    await expect(await (await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,10).listLabel.markerCO.icon)).getAttribute('class')).toContain('warning');
    await expect(await (await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,11).listLabel.markerCO.icon)).getAttribute('class')).toContain('danger');
  });
  it('should verify the list-item CO tagTypeClass, tagLabel, tagCount, isTagRounded ', async () => {
    browser.addTestMeta({zephyrStep: "378037"});
    let sectionId= 'typeClass';
    let sectionTitle= 'with tag : tagLabel / tagCount / tagTypeClass';
    let scrollIntoSection = await $(listItemPage.sectionPartBySectionTitle(sectionTitle));
    await scrollIntoSection.scrollIntoView();
    //tagTypeClass
    await expect(await (await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,13).rightContentTag.tagLabel)).getAttribute('class')).toContain('primary');
    await expect(await (await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,14).rightContentTag.tagLabel)).getAttribute('class')).toContain('info');
    await expect(await (await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,15).rightContentTag.tagLabel)).getAttribute('class')).toContain('success');
    await expect(await (await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,16).rightContentTag.tagLabel)).getAttribute('class')).toContain('warning');
    await expect(await (await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,17).rightContentTag.tagLabel)).getAttribute('class')).toContain('danger');
    // tagLabel
    await expect(await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,13).rightContentTag.tagLabel)).toHaveText('tagLabel');
     //tagCount
    await expect(await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,19).rightContentTag.tagSubLabel)).toHaveTextContaining('10');
    await expect(await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,19).rightContentTag.tagSubLabel)).toHaveTextContaining('10');
    await expect(await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,20).rightContentTag.tagSubLabel)).toHaveTextContaining('10');
    await expect(await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,21).rightContentTag.tagSubLabel)).toHaveTextContaining('10');
    await expect(await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,22).rightContentTag.tagSubLabel)).toHaveTextContaining('10');
    await expect(await $(listItemPage.listItemFromSectionWithIdByIndex(sectionId,23).rightContentTag.tagSubLabel)).toHaveTextContaining('10');
    sectionTitle= 'with tag : tagLabel / tagTypeClass / isTagRounded=true';
    scrollIntoSection = await $(listItemPage.sectionPartBySectionTitle(sectionTitle));
    await scrollIntoSection.scrollIntoView();
    //   //isTagRounded
    await expect(await listItemPage.listItemFromSectionWithIdByIndex(sectionId,27).isTagRounded()).toBe(true);
  });
});


