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

describe('eUI - <ux-notifications> Component Object ', async () => {
  let notificationsPage = new NotificationsPage();
  it('should navigate to <ux-notifications> component', async () => {
    browser.addTestMeta({uuid:"a06944e8-859c-11eb-8dcd-0242ac130003", zephyrKey: "CCQA-740", zephyrStep: "363986", reportGroups: ["eUI.10x.ux"]});
    await notificationsPage.open(Routing.getUxComponentUrl('ux-notifications'));
    await CookieBannerActions.cookieBanner(true);
    const pgTitle = await $(notificationsPage.pageTitle);
    let navigationList = await $(notificationsPage.navigationList);
    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-notifications> page title is not visible on page'});
    await expect(pgTitle).toHaveText('ux-notifications', 'Page title text is not as expected')
    await expect(await $(notificationsPage.appDocPageById('ux-notifications'))).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 in page', async () => {
    browser.addTestMeta({zephyrStep: "363987"});
    let sectionId = 'simple';
    let scrollIntoSection = await $(notificationsPage.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await $(notificationsPage.sectionById(sectionId))).
      toBeDisplayedInViewport({message:'<simple> section -> is not visible on page'});
    await expect(await $(notificationsPage.notificationItemByIndex(1).dataE2E)).
      toBeDisplayedInViewport({message:'Notification by index "1" is not visible on page'});
    await expect(await $(notificationsPage.notificationItemByTextContains('Lorem ipsum').dataE2E)).
      toBeDisplayedInViewport({message:'Notification item by text "Lorem ipsum" is not visible on page'});
    await expect(await $(notificationsPage.notificationItemByTextContainsAndIndex('Lorem ipsum',1).dataE2E)).
      toBeDisplayedInViewport({message:'Notification item by index "1" and by text "Lorem ipsum" is not visible on page'});
    await expect(await notificationsPage.notificationItemByIndex(1).defaultComponentsCount()).toBe(49,
        'There should be 49 <ux-notification-item> components on page.');
    sectionId = 'Default';
    scrollIntoSection = await $(notificationsPage.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await $(notificationsPage.notificationsPanelByIndex(1).dataE2E)).
      toBeDisplayedInViewport({message:'Notifications panel by index "1" is not visible on page'});
    await expect(await $(notificationsPage.notificationsPanelByTextContains('Lorem ipsum').dataE2E)).
      toBeDisplayedInViewport({message:'Notifications panel by text "Lorem ipsum" is not visible on page'});
    await expect(await $(notificationsPage.notificationsPanelByTextContainsAndIndex('Lorem ipsum',1).dataE2E)).
        toBeDisplayedInViewport({message:'Notifications panel by index "1" and by text "Lorem ipsum" is not visible on page'});
    await expect(await notificationsPage.notificationsPanelByIndex(1).defaultComponentsCount()).toBe(11,
          'There should be 11 <ux-notification-items> components on page.');
  });
  it('should verify the Notification Item  CO properties and methods ', async () => {
    browser.addTestMeta({zephyrStep: "363988"});
    let sectionId = 'metadata';
    let sectionElement = await $(notificationsPage.notificationItemFromSectionById(sectionId).currentPath);
    await sectionElement.scrollIntoView();

    let notificationItem1 = notificationsPage.notificationItemFromSectionWithIdByIndex(sectionId, 1);
    await expect(await $(notificationItem1.dataE2E)).
        toBeDisplayedInViewport({message:'Notification item by index "1" from metadata section property dataE2E is not visible on page'});
    await expect(await $(notificationItem1.itemContent)).
      toBeDisplayedInViewport({message:'Notification item by index "1" from metadata section property itemContent is not visible on page'});
    await expect(await $(notificationItem1.itemLeftContent)).
      toBeDisplayedInViewport({message:'Notification item by index "1" from metadata section property itemLeftContent is not visible on page'});
    await expect(await $(notificationItem1.itemCenterContent)).
      toBeDisplayedInViewport({message:'Notification item by index "1" from metadata section property itemCenterContent is not visible on page'});
    await expect(await $(notificationItem1.itemRightContent)).
      toBeDisplayedInViewport({message:'Notification item by index "1" from metadata section property itemRightContent is not visible on page'});
    await expect(await $(notificationItem1.badgeCO.currentPath)).
      toBeDisplayedInViewport({message:'Notification item by index "1" from metadata section property badgeCO currentPath is not visible on page'});
    await expect(await $(notificationItem1.dateTagCO.currentPath)).
      toBeDisplayedInViewport({message:'Notification item by index "1" from metadata section property dateTagCO currentPath is not visible on page'});
    await expect(await $(notificationItem1.dateTagCO.dateTag)).
      toBeDisplayedInViewport({message:'Notification item by index "1" from metadata section property dateTagCO dateTag is not visible on page'});
  });

  it('should verify the Notifications Panel CO properties and methods ', async () => {
    browser.addTestMeta({zephyrStep: "363989"});
    let sectionId = 'Default';
    let sectionElement = await $(notificationsPage.notificationsPanelFromSectionById(sectionId).currentPath);
    await sectionElement.scrollIntoView();

    let notificationsPanel1 = notificationsPage.notificationsPanelFromSectionWithIdByIndex(sectionId, 1);
    await expect(await $(notificationsPanel1.dataE2E)).
      toBeDisplayedInViewport({message:'Notifications panel by index "1" from Default section property dataE2E is not visible on page'});
    await expect(await $(notificationsPanel1.notificationsPanelHeader)).
      toBeDisplayedInViewport({message:'Notifications panel by index "1" from Default section property notificationsPanelHeader is not visible on page'});
    await expect(await $(notificationsPanel1.headerTitle)).
      toBeDisplayedInViewport({message:'Notifications panel by index "1" from Default section property headerTitle is not visible on page'});
    await expect(await $(notificationsPanel1.headerTitleLabel)).
      toBeDisplayedInViewport({message:'Notifications panel by index "1" from Default section property headerTitleLabel is not visible on page'});
    await expect(await $(notificationsPanel1.headerTitleNotificationUnreadLabel)).
      toExist({message:'Notifications panel by index "1" from Default section property headerTitleNotificationUnreadLabel is not existing on page'});
    await expect(await $(notificationsPanel1.notificationsQuantityBadge.currentPath)).
      toBeDisplayedInViewport({message:'Notifications panel by index "1" from Default section property notificationsQuantityBadge currentPath is not visible on page'});
    await expect(await $(notificationsPanel1.headerActions)).
      toBeDisplayedInViewport({message:'Notifications panel by index "1" from Default section property headerActions is not visible on page'});
    await expect(await $(notificationsPanel1.markAllAsReadButtonCO.button)).
      toBeDisplayedInViewport({message:'Notifications panel by index "1" from Default section property markAllAsReadButtonCO button is not visible on page'});
    await expect(await $(notificationsPanel1.headerTitleLabel)).toHaveText('My notifications 0');
  })

  it('should verify the Notifications Panel CO - content properties ', async () => {
    browser.addTestMeta({zephyrStep: "363990"});
    let sectionId = 'simple';
    let sectionElement = await $(notificationsPage.notificationsPanelFromSectionById(sectionId).currentPath);
    sectionElement.scrollIntoView();

    let notificationsPanel1 = notificationsPage.notificationsPanelFromSectionWithIdByIndex(sectionId, 1);
    await expect(await $(notificationsPanel1.dataE2E)).
      toBeDisplayedInViewport({message:'Notifications panel by index "1" from simple section property dataE2E is not visible on page'});
    await expect(await $(notificationsPanel1.notificationsPanelContent)).
      toBeDisplayedInViewport({message:'Notifications panel by index "1" from simple section property notificationsPanelContent is not visible on page'});
    await expect(await $(notificationsPanel1.notificationItemCO.currentPath)).
      toBeDisplayedInViewport({message:'Notifications panel by index "1" from simple section property notificationItemCO currentPath is not visible on page'});
    await expect(await $(notificationsPanel1.notificationsQuantityBadge.currentPath)).
      toBeDisplayedInViewport({message:'Notifications panel by index "1" from simple section property notificationsQuantityBadge currentPath is not visible on page'});
    await expect(await $(notificationsPanel1.notificationsQuantityBadge.badgeDataSpan)).toHaveText('6');
    await expect(await notificationsPanel1.notificationItemCO.defaultComponentsCount()).toBe(6,'There should be 6 <ux-notification-item> in the notifications panel.');
  })

  it('should verify the Notifications Panel CO - footer properties ', async () => {
    browser.addTestMeta({zephyrStep: "384056"});
    let sectionId = 'simple';
    let sectionElement = await $(notificationsPage.notificationsPanelFromSectionById(sectionId).currentPath);
    await sectionElement.scrollIntoView();

    let notificationsPanel1 = notificationsPage.notificationsPanelFromSectionWithIdByIndex(sectionId, 1);
    await expect(await $(notificationsPanel1.dataE2E)).
      toBeDisplayedInViewport({message:'Notifications panel by index "1" from simple section property dataE2E is not visible on page'});
    await expect(await $(notificationsPanel1.notificationsPanelFooter)).
      toBeDisplayedInViewport({message:'Notifications panel by index "1" from simple section property notificationsPanelFooter is not visible on page'});
    await expect(await $(notificationsPanel1.notificationPanelFooterViewAllLink)).
      toBeDisplayedInViewport({message:'Notifications panel by index "1" from simple section property notificationPanelFooterViewAllLink is not visible on page'});
    await expect(await $(notificationsPanel1.notificationPanelFooterViewAllLink)).toHaveText('View all notifications');
    await expect(await notificationsPanel1.hasNotifications()).toBe(true,'hasNotifications should be true');

    sectionId = 'Default';
    sectionElement = await $(notificationsPage.notificationsPanelFromSectionById(sectionId).currentPath);
    await sectionElement.scrollIntoView();
    notificationsPanel1 = notificationsPage.notificationsPanelFromSectionWithIdByIndex(sectionId, 1);
    await expect(await $(notificationsPanel1.notificationsPanelFooter)).
      toBeDisplayedInViewport({message:'Notifications panel by index "1" from Default section property notificationsPanelFooter is not visible on page'});
    await expect(await $(notificationsPanel1.notificationsPanelFooterItem)).
      toBeDisplayedInViewport({message:'Notifications panel by index "1" from Default section property notificationsPanelFooterItem is not visible on page'});
    await expect(await $(notificationsPanel1.noNotificationFoundLabel)).
      toBeDisplayedInViewport({message:'Notifications panel by index "1" from Default section property noNotificationFoundLabel is not visible on page'});
    await expect(await notificationsPanel1.hasNotifications()).toBe(false,'hasNotifications should be false');

    let notificationsPanel2 = notificationsPage.notificationsPanelFromSectionWithIdByIndex(sectionId, 2);
    await expect(await $(notificationsPanel2.notificationsPanelFooter)).
      toBeDisplayedInViewport({message:'Notifications panel by index "2" from Default section property notificationsPanelFooter is not visible on page'});
    await expect(await $(notificationsPanel2.notificationsPanelFooterItem)).
      toBeDisplayedInViewport({message:'Notifications panel by index "2" from Default section property notificationsPanelFooterItem is not visible on page'});
    await expect(await $(notificationsPanel2.noNotificationFoundLink)).
      toBeDisplayedInViewport({message:'Notifications panel by index "2" from Default section property noNotificationFoundLink is not visible on page'});
    await expect(await $(notificationsPanel2.noNotificationFoundLink)).toHaveText('No notification found');
    await expect(await notificationsPanel2.hasNotifications()).toBe(false,'hasNotifications should be false');
  })

  it('should verify the Notifications Panel CO -  methods ', async () => {
    browser.addTestMeta({zephyrStep: "384057"});
    let sectionId = 'isRenderHTML';
    let sectionElement = await $(notificationsPage.notificationsPanelFromSectionById(sectionId).currentPath);
    await sectionElement.scrollIntoView();
    let notificationsPanel1 = notificationsPage.notificationsPanelFromSectionWithIdByIndex(sectionId, 1);
    await expect(await $(notificationsPanel1.notificationsPanelHeader)).
      toBeDisplayedInViewport({message:'Notifications panel by index "1" from isRenderHTML section property notificationsPanelHeader is not visible on page'});
    await expect(await notificationsPanel1.isShowMarkAllAsReadButton()).toBe(true,'isShowMarkAllAsReadButton should be true');

    sectionId = 'isShowMarkAllAsReadButton';
    sectionElement = await $(notificationsPage.notificationsPanelFromSectionById(sectionId).currentPath);
    await sectionElement.scrollIntoView();
    notificationsPanel1 = notificationsPage.notificationsPanelFromSectionWithIdByIndex(sectionId, 1);
    await expect(await $(notificationsPanel1.notificationsPanelHeader)).
      toBeDisplayedInViewport({message:'Notifications panel by index "1" from isShowMarkAllAsReadButton section property notificationsPanelHeader is not visible on page'});
    await expect(await notificationsPanel1.isShowSettingsButton()).toBe(true,'isShowSettingsButton should be true');

    sectionId = 'isShowRefreshButton';
    sectionElement = await $(notificationsPage.notificationsPanelFromSectionById(sectionId).currentPath);
    await sectionElement.scrollIntoView();
    notificationsPanel1 = notificationsPage.notificationsPanelFromSectionWithIdByIndex(sectionId, 1);
    await expect(await $(notificationsPanel1.notificationsPanelHeader)).
      toBeDisplayedInViewport({message:'Notifications panel by index "1" from isShowRefreshButton section property notificationsPanelHeader is not visible on page'});
    await expect(await notificationsPanel1.isShowRefreshButton()).toBe(false,'isShowRefreshButton should be false');

    sectionId = 'metadata';
    sectionElement = await $(notificationsPage.notificationsPanelFromSectionWithIdByIndex(sectionId, 2).currentPath);
    await sectionElement.scrollIntoView();

    let notificationsItem = notificationsPage.notificationsPanelFromSectionWithIdByIndex(sectionId, 2).notificationItemCO;
    await expect(await $(notificationsItem.currentPath)).
      toBeDisplayedInViewport({message:'Notification item from metadata section  is not visible on page'});
    await expect(await $(notificationsItem.byIndex(1).itemContent)).toHaveAttrContaining('class','danger');
    await expect(await $(notificationsItem.byIndex(2).itemContent)).toHaveAttrContaining('class','warning');
    await expect(await $(notificationsItem.byIndex(3).itemContent)).toHaveAttrContaining('class','success');
    await expect(await $(notificationsItem.byIndex(4).itemContent)).toHaveAttrContaining('class','info');
  })

});
