import Routing from '../../../../pages/eui/10x/routing-10x.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'
import OverlayPage from '../../../../pages/eui/10x/ux/ux-overlay-10x.po.js'
import ButtonPage from '../../../../pages/eui/10x/ux/ux-button-10x.po.js'

describe('eUI - <ux-overlay> Component Object @CCQA-694', async() => {
  let overlayPage = new OverlayPage();
  let buttonPage = new ButtonPage();
  it('should navigate to <ux-overlay> component ', async() => {
    browser.addTestMeta({uuid:"ee0c7cfe-8576-11eb-8dcd-0242ac130003", zephyrKey: "CCQA-694", zephyrStep: "353064", reportGroups: ["eUI.10x.ux"]});
    await overlayPage.open(Routing.getUxLayoutComponentUrl('ux-overlay'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(overlayPage.pageTitle);
    let appDocPageId = await $(overlayPage.appDocPageById('ux-overlay'));
    let navigationList = await $(overlayPage.navigationList);
    await pgTitle.scrollIntoView();
    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-overlay> page title is not visible on page'});
    await expect(await pgTitle.getText()).toBe('ux-overlay', '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: "353065"});
    await expect(await $(overlayPage.overlayFromSectionById('Default').currentPath)).toExist({wait:1000, message:
      '<Default> section -> is not existing on page'});
    let overlayPage1 = overlayPage.overlayByIndex(1);
    await expect(await $(overlayPage1.dataE2E)).toExist({wait:1000, message: 'Overlay by index "1" is not existing on page'});
    await expect(await overlayPage1.defaultComponentsCount()).toBe(1, 'There should be 1 <ux-overlay> components on the page.');
  });
  it('should verify if overlay is active', async() => {
    browser.addTestMeta({zephyrStep: "353066"});
    let overlayPage1 = overlayPage.overlayByIndex(1);
    await expect(await overlayPage1.isActive()).toBe(false, 'isActive should be false');
    let buttonToggleOverlay = buttonPage.buttonByTextContains('Toggle overlay');

    await expect(await $(buttonToggleOverlay.button)).toBeDisplayed({wait:1000, message: 'Button Toggle overlay is not visible on page'});
    await (await $(buttonToggleOverlay.button)).click();
    await expect(await $(overlayPage1.overlayActive)).toBeDisplayed({wait:1000, message: 'Overlay by index "1" is not visible on page'});
    await expect(await overlayPage1.isActive()).toBe(true, 'isActive should be true');
  });

});
