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

describe('eUI - <ux-tab> Component Object', async () => {
  let page = new TabPage();
  it('should navigate to <ux-tab> component', async () => {
    browser.addTestMeta({uuid:"48dd6768-c44e-11eb-8529-0242ac130003", zephyrKey: "CCQA-1073", zephyrStep: "401420", reportGroups: ["eUI.10x.ux"]});
    await page.open(Routing.getUxComponentUrl('ux-tab'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    let navigationList = await $(page.navigationList);
    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-tab> page title is not visible on page'});
    await expect(pgTitle).toHaveText('ux-tab', 'Page title text is not as expected')
    await expect(await $(page.appDocPageById('ux-tab'))).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 and number of component objects <ux-tab> on page ', async () => {
    browser.addTestMeta({zephyrStep: "401421"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let tab = page.tabByIndex(1);
    await expect(await $(page.sectionById(sectionId))).toBeDisplayedInViewport({message:'<Default> section -> is not visible on page'});
    await expect(await $(tab.dataE2E)).toBeDisplayedInViewport({message:'Tab by index "1" is not visible on page'});
    await expect(await $(page.tabByTextContains('Tab 1').dataE2E)).toBeDisplayedInViewport({message:'Tab by text "Tab 1" is not visible on page'});
    await expect(await $(page.tabByTextEqualsAndIndex('Tab 1', 1).dataE2E)).toExist({message:'Tab by text "Tab 1" and index 1 is not existing on page'});
    await expect(await tab.defaultComponentsCount()).toBe(78,'There should be 78 <ux-tab> components on the page.');
  });
  it('should verify the presence and number of component objects <ux-tabs> on page ', async () => {
    browser.addTestMeta({zephyrStep: "401422"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let tabs = page.tabsByIndex(1);
    await expect(await $(page.sectionById(sectionId))).toBeDisplayedInViewport({message:'<Default> section -> is not visible on page'});
    await expect(await $(tabs.dataE2E)).toBeDisplayedInViewport({message:'Tabs by index "1" is not visible on page'});
    await expect(await $(page.tabsByTextContains('Tab 1').dataE2E)).toBeDisplayedInViewport({message:'Tabs by text "Tab 1" is not visible on page'});
    await expect(await $(page.tabsByTextEqualsAndIndex('Tab 1', 1).dataE2E)).toBeDisplayedInViewport({message:'Tab by text "Tab 1" and index 1 is not visible on page'});
    await expect(await tabs.defaultComponentsCount()).toBe(23, 'There should be 23 <ux-tabs> components on the page.');
  });
  it('should verify the presence and number of component objects <ux-tab-item> on page ', async () => {
    browser.addTestMeta({zephyrStep: "401424"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let tab = page.tabsByIndex(1).tabItemCO;
    await expect(await $(page.sectionById(sectionId))).toBeDisplayedInViewport({message:'<Default> section -> is not visible on page'});
    await expect(await $(tab.currentPath)).toBeDisplayedInViewport({message:'Tab item by is not visible on page'});
    await expect(await $(page.tabsByIndex(1).tabItemByIndex(1).labelCO.currentPath)).
      toBeDisplayedInViewport({message:'labelCO currentPathtabItemByIndex is not visible on page'});
    await expect(await tab.defaultComponentsCount()).toBe(2,'There should be 2 <ux-tab-item> components on the page.');
  });
  it('should verify the ux-tab CO methods: dataE2E, isHidden ', async () => {
    browser.addTestMeta({zephyrStep: "401425"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let tab = page.tabByIndex(1);
    await expect(await $(tab.dataE2E)).toBeDisplayedInViewport({message:'dataE2E is visible on page'});
    await expect(await tab.isHidden()).toBe(false,'isHidden should be false');
    tab = page.tabByIndex(2);
    await expect(await $(tab.dataE2E)).not.toBeDisplayedInViewport({message:'dataE2E is visible on page'});
    await expect(await tab.isHidden()).toBe(true,'isHidden should be true');
  });
  it('should verify the ux-tabs CO methods: isMainNavigation, items, tabItemCO, tabItemByIndex, tabCO, tabItemByIndex ', async () => {
    browser.addTestMeta({zephyrStep: "401426"});
    let sectionId = 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    tabs = page.tabsFromSectionById(sectionId);
    await expect(await $(tabs.items)).toBeDisplayedInViewport({message:'tabs items are not visible on page'});
    await expect(await tabs.isMainNavigation()).toBe(false,'isMainNavigation should be false');
    await expect(await $(tabs.tabItemCO.currentPath)).toBeDisplayedInViewport({message:'tab item is not visible on page'});
    await expect(await $(tabs.tabItemByIndex(1).currentPath)).toBeDisplayedInViewport({message:'tabItemByIndex 1 is not visible on page'});
    sectionId = 'isMainNavigation';
    scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    tabs = page.tabsFromSectionById(sectionId);
    await expect(await $(tabs.dataE2E)).toBeDisplayedInViewport({message:'tabs is not visible on page'});
    await expect(await tabs.isMainNavigation()).toBe(true,'isMainNavigation should be true');
  });
  it('should verify the ux-tabs CO methods: rightContent, uxTabsRightContent, tabContent, tabCO, tabItemByIndex, tabCO, tabByIndex ', async () => {
    browser.addTestMeta({zephyrStep: "401429"});
    let sectionId= 'content-uxTabsRightContent';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    tabs = page.tabsFromSectionById(sectionId);
    await expect(await $(tabs.rightContent)).toBeDisplayedInViewport({message:'tabs rightContent is not visible on page'});
    await expect(await $(tabs.uxTabsRightContent)).toBeDisplayedInViewport({message:'tabs uxTabsRightContent is not visible on page'});
    await expect(await $(tabs.tabContent)).toBeDisplayedInViewport({message:'tabs tabContent is not visible on page'});
    await expect(await $(tabs.tabCO.currentPath)).toBeDisplayedInViewport({message:'tab is not visible on page'});
    await expect(await $(tabs.tabByIndex(1).currentPath)).toBeDisplayedInViewport({message:'tabByIndex 1 is not visible on page'});
  });
  it('should verify the ux-tab-item CO methods: isActive, isDisabled, isSubTabs, hasValidationErrors ', async () => {
    browser.addTestMeta({zephyrStep: "401430"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let tabItem = page.tabsByIndex(1);
    await expect(await tabItem.tabItemByIndex(1).isActive()).toBe(true,'isActive should be true');
    await expect(await tabItem.tabItemByIndex(1).isDisabled()).toBe(false,'isDisabled should be false');
    await expect(await tabItem.tabItemByIndex(1).isSubTabs()).toBe(false,'isSubTabs should be false');
    await expect(await tabItem.tabItemByIndex(1).hasValidationErrors()).toBe(false,'hasValidationErrors should be false');

    sectionId= 'isDisabled';
    scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await page.tabsFromSectionById(sectionId).tabItemByIndex(3).isDisabled()).toBe(true,'isDisabled should be true');
    await expect(await page.tabsFromSectionById(sectionId).tabItemByIndex(3).isActive()).toBe(false,'isActive should be false');

    sectionId = 'sub-tabs';
    scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await page.tabsFromSectionById(sectionId).tabItemByIndex(3).isSubTabs()).toBe(true,'isSubTabs should be true');

    sectionId= 'hasValidationErrors';
    scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await page.tabsFromSectionById(sectionId).tabItemByIndex(3).hasValidationErrors()).toBe(true,'hasValidationErrors should be true');
  });

  it('should verify the ux-tab-item CO methods: iconCO, labelCO, markerCO, hasMarker ', async () => {
    browser.addTestMeta({zephyrStep: "401431"});
    let sectionId= 'iconClass';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();

    let tabItem = page.tabsFromSectionById(sectionId);
    await expect(await $(tabItem.tabItemByIndex(1).iconCO.currentPath)).toBeDisplayedInViewport({message:'tab item iconCO selector is not visible on page'});
    await expect(await $(tabItem.tabItemByIndex(1).labelCO.currentPath)).toBeDisplayedInViewport({message:'tab item labelCO selector is not visible on page'});

    sectionId= 'hasMarker-markerTypeClass';
    scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    tabItem = page.tabsFromSectionById(sectionId);
    await expect(await $(tabItem.tabItemByIndex(1).markerCO.currentPath)).toBeDisplayedInViewport({message:'tab item markerCO selector is not visible on page'});
    await expect(await tabItem.tabItemByIndex(1).hasMarker()).toBe(true,'hasMarker should be true');
  });

  it('should verify the ux-tab-item CO methods: closeIcon, isClosable ', async () => {
    browser.addTestMeta({zephyrStep: "401432"});
    let sectionId= 'isClosable';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();

    let tabItem = page.tabsFromSectionById(sectionId);
    await expect(await $(tabItem.tabItemByIndex(3).closeIcon)).toBeDisplayedInViewport({message:'tab item closeIcon is not visible on page'});
    await expect(await tabItem.tabItemByIndex(3).isClosable()).toBe(true,'isClosable should be true');
    await (await $(tabItem.tabItemByIndex(3).closeIcon)).click();
    await expect(await $(tabItem.tabItemByIndex(3).closeIcon)).not.toBeDisplayedInViewport({message:'tab item closeIcon is visible on page'});
    await expect(await tabItem.tabItemByIndex(3).isClosable()).toBe(false,'isClosable should be false');
  });

});
