import Routing from '../../../../pages/eui/10x/routing-10x.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'
import LayoutPageHeader from '../../../../pages/eui/10x/ux/ux-layout-page-header-10x.po.js'

describe('eUI - <ux-layout-page-header> Component Object @CCQA-693', async() => {
  let layoutPageHeaderPage = new LayoutPageHeader();
  it('should navigate to <ux-layout-page-header> component', async() => {
    browser.addTestMeta({uuid:"faa7f016-7c38-11eb-9439-0242ac130002", zephyrKey: "CCQA-693", zephyrStep: "353068", reportGroups: ["eUI.10x.ux"]});
    await layoutPageHeaderPage.open(Routing.getUxLayoutComponentUrl('ux-layout-page-header'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(layoutPageHeaderPage.pageTitle);
    let appDocPageId = await $(layoutPageHeaderPage.appDocPageById('ux-layout-page-header'));
    let navigationList = await $(layoutPageHeaderPage.navigationList);
    await pgTitle.scrollIntoView();
    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-layout-page-header> page title is not visible on page'});
    await expect(await pgTitle.getText()).toBe('ux-layout-page-header', '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: "353069"});
    let co1 = await $(layoutPageHeaderPage.layoutPageHeaderFromSectionById('Default').pageHeaderWrapper);
    let co2 = await $(layoutPageHeaderPage.layoutPageHeaderByIndex(1).pageHeaderWrapper);
    await expect(co1).toBeDisplayed({wait:1000, message:'<Default> section -> is not visible on page'});
    await expect(co2).toBeDisplayed({wait:1000, message:'Layout page header by index "1" is not visible on page'});

    await expect(await layoutPageHeaderPage.layoutPageHeaderByIndex(7).defaultComponentsCount()).toBe(8,
      'There should be 8 <ux-layout-page-header> components on the page.');
  });
  it('should verify the presence of the main elements of the Component Object on the page ', async() => {
    browser.addTestMeta({zephyrStep: "353070"});
    let sectionId = 'Default';
    let sectionElement = await $(layoutPageHeaderPage.layoutPageHeaderFromSectionById(sectionId).currentPath);
    await sectionElement.scrollIntoView();

    let layoutPageHeader1 = layoutPageHeaderPage.layoutPageHeaderFromSectionWithIdByIndex(sectionId, 1);
    await expect(await $(layoutPageHeader1.pageHeader)).toBeDisplayed({wait:1000, message:
      'Layout page header by index "1" from Default section property pageHeader is not visible on page'});
    await expect(await $(layoutPageHeader1.headerTitle)).toBeDisplayed({wait:1000, message:
      'Layout page header by index "1" from Default section property headerTitle is not visible on page'});
    await expect(await $(layoutPageHeader1.headerTitleText)).toBeDisplayed({wait:1000, message:
      'Layout page header by index "1" from Default section property headerTitleText is not visible on page'});

    await expect(await (await $(layoutPageHeader1.headerTitleText)).getText()).toContain('Page title');

    sectionId = 'pageSubtitle';
    sectionElement = await $(layoutPageHeaderPage.layoutPageHeaderFromSectionById(sectionId).currentPath);
    await sectionElement.scrollIntoView();
    layoutPageHeader1 = layoutPageHeaderPage.layoutPageHeaderFromSectionWithIdByIndex(sectionId, 1);

    await expect(await $(layoutPageHeader1.headerSubTitle)).toBeDisplayed({wait:1000, message:
      'Layout page header by index "1" from pageSubtitle section property headerSubTitle is not visible on page'});
    await expect(await $(layoutPageHeader1.headerSubTitleText)).toBeDisplayed({wait:1000, message:
      'Layout page header by index "1" from pageSubtitle section property headerSubTitleText is not visible on page'});

    await expect(await (await $(layoutPageHeader1.headerSubTitleText)).getText()).toContain('Page subtitle');
  });

  it('should verify the header buttons ', async() => {
    browser.addTestMeta({zephyrStep: "353071"});
    let sectionId = 'content-uxLayoutPageHeaderActionsContent';
    let sectionElement = await $(layoutPageHeaderPage.layoutPageHeaderFromSectionById(sectionId).currentPath);
    await sectionElement.scrollIntoView();
    let layoutPageHeader1 = layoutPageHeaderPage.layoutPageHeaderFromSectionWithIdByIndex(sectionId, 1);
    await expect(await $(layoutPageHeader1.headerTitleActions)).toBeDisplayed({wait:1000, message:
      'Layout page header by index "1" from ActionsContent section property headerTitleActions is not visible on page'});
    await expect(await $(layoutPageHeader1.headerActionsContent)).toBeDisplayed({wait:1000, message:
      'Layout page header by index "1" from ActionsContent section property headerActionsContent is not visible on page'});
    await expect(await $(layoutPageHeader1.actionContentButton)).toBeDisplayed({wait:1000, message:
      'Layout page header by index "1" from ActionsContent section property actionContentButton is not visible on page'});

    sectionId = 'hasLocalMenu';
    sectionElement = await $(layoutPageHeaderPage.layoutPageHeaderFromSectionById(sectionId).currentPath);
    await sectionElement.scrollIntoView();
    layoutPageHeader1 = layoutPageHeaderPage.layoutPageHeaderFromSectionWithIdByIndex(sectionId, 1);
    await expect(await $(layoutPageHeader1.headerLocalMenuDropDownButton)).toBeDisplayed({wait:1000, message:
      'Layout page header by index "1" from ActionsContent section property headerLocalMenuDropDownButton is not visible on page'});
  });
  it('should verify the header bookmark ', async() => {
    browser.addTestMeta({zephyrStep: "353072"});
    let sectionId = 'isBookmarkable';
    let sectionElement = await $(layoutPageHeaderPage.layoutPageHeaderFromSectionById(sectionId).currentPath);
    await sectionElement.scrollIntoView();
    let layoutPageHeader1 = layoutPageHeaderPage.layoutPageHeaderFromSectionWithIdByIndex(sectionId, 1);
    await expect(await layoutPageHeader1.isBookmarkable()).toBe(true, 'The isBookmarkable should be true');
    await expect(await layoutPageHeader1.isBookmarked()).toBe(false, 'The isBookmarked should be false');

    await expect(await $(layoutPageHeaderPage.buttonByTextContains('Bookmark').button)).toBeDisplayed({wait:1000, message:'Add a bookmark button is not visible on pag'});
    await (await $(layoutPageHeaderPage.buttonByTextContains('Bookmark').button)).click();
    await expect(await layoutPageHeader1.isBookmarked()).toBe(true, 'The isBookmarked should be true');
  });

});
