import Routing from '../../../../pages/eui/10x/routing-10x.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'
import DynamicModalPage from '../../../../pages/eui/10x/ux/ux-dynamic-modal-10x.po.js'

describe('eUI - <ux-dynamic-modal> Component Object', async () => {
  let dynModalPage = new DynamicModalPage();
  it('should navigate to <ux-dynamic-modal> component', async () => {
   browser.addTestMeta({uuid:"2289db5c-92e2-11eb-a8b3-0242ac130003", zephyrKey: "CCQA-551", zephyrStep: "316148", reportGroups: ["eUI.10x.ux"]});
   await dynModalPage.open(Routing.getUxComponentUrl('ux-dynamic-modal'));
   await CookieBannerActions.cookieBanner(true);
   let pgTitle = await $(dynModalPage.pageTitle);
   let appDocPageId = await $(dynModalPage.appDocPageById('ux-dynamic-modal'));
   let navigationList = await $(dynModalPage.navigationList);

   await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-dynamic-modal> page title is not visible on page'});
   await expect(pgTitle).toHaveText('ux-dynamic-modal', {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 visible on page'});
  });
  it('should open the default dynamic modal window', async () => {
   browser.addTestMeta({zephyrStep: "316156"});
   let sectionId= 'Default';
   let scrollIntoSection = await $(dynModalPage.sectionById(sectionId));
   await scrollIntoSection.scrollIntoView();
   await (await $(dynModalPage.buttonPage.buttonFromSectionById(sectionId).button)).click();
   let modal = dynModalPage.dynamicModalByIndex(1);
   await expect(await $(modal.dataE2E)).toBeDisplayedInViewport({message:'Dynamic modal by index 1 is not visible on page'});
   await expect(await $(dynModalPage.dynamicModalByTextContains('Modal title').dataE2E)).
      toBeDisplayedInViewport({message:'Dynamic modal by text "Modal title" is not visible on page'});
   await expect(await $(dynModalPage.dynamicModalByTextEqualsAndIndex('Modal title', 1).dataE2E)).
     toBeDisplayedInViewport({message:'Dynamic modal by text "Modal title" and index 1 is not visible on page'});
   await expect(await $$(modal.byDefault().dataE2E)).toBeElementsArrayOfSize(1);
   await expect(await $(modal.closeButton)).toBeDisplayedInViewport({message:'Dynamic modal closeButton is not visible on page'});
   await (await $(modal.closeButton)).click();
  });
  it('should verify the modal window elements ', async () => {
   browser.addTestMeta({zephyrStep: "316149"});
   let sectionId= 'Default';
   let scrollIntoSection = await $(dynModalPage.sectionById(sectionId));
   await scrollIntoSection.scrollIntoView();
   await (await $(dynModalPage.buttonPage.buttonFromSectionById(sectionId).button)).click();

   let modal = dynModalPage.dynamicModalByIndex(1);
   await expect(await $(modal.modalDialog)).toBeDisplayedInViewport({message:'Dynamic modal modalDialog from Deafault section is not visible on page'});
   await expect(await $(modal.modalContent)).toBeDisplayedInViewport({message:'Dynamic modal modalContent from Deafault section is not visible on page'});
   await expect(await $(modal.modalHeader)).toBeDisplayedInViewport({message:'Dynamic modal modalHeader from Deafault section is not visible on page'});
   await expect(await $(modal.modalHeaderTitle)).toBeDisplayedInViewport({message:'Dynamic modal modalHeaderTitle from Deafault section is not visible on page'});
   await expect(await $(modal.closeButton)).toBeDisplayedInViewport({message:'Dynamic modal closeButton is not visible on page'});
   await expect(await $(modal.closeIcon)).toBeDisplayedInViewport({message:'Dynamic modal closeIcon from Deafault section is not visible on page'});
   await expect(await $(modal.modalBody)).toBeDisplayedInViewport({message:'Dynamic modal modalBody from Deafault section is not visible on page'});
   await expect(await $(modal.modalFooter)).toBeDisplayedInViewport({message:'Dynamic modal modalFooter from Deafault section is not visible on page'});
   await expect(await $(modal.footerSecondaryButtonCO.currentPath)).
      toBeDisplayedInViewport({message:'Dynamic modal footerContentSecondaryButton from Deafault section is not visible on page'});
   await expect(await $(modal.footerPrimaryButtonCO.currentPath)).
      toBeDisplayedInViewport({message:'Dynamic modal footerContentPrimaryButton from Deafault section is not visible on page'});
   await expect(await $(modal.modalBackdrop)).
      toBeDisplayedInViewport({message:'Dynamic modal modalBackdrop from Deafault section is not visible on page'});
   await (await $(modal.footerPrimaryButtonCO.currentPath)).click();
  });
  it('should open <dynamic-injection> modal window and verify elements inside modal window ', async () => {
   browser.addTestMeta({zephyrStep: "316150"});
   let sectionId= 'dynamic-injection';
   let scrollIntoSection = await $(dynModalPage.sectionById(sectionId));
   await scrollIntoSection.scrollIntoView();
   await (await $(dynModalPage.buttonPage.buttonFromSectionById(sectionId).button)).click();

   let modal = dynModalPage.dynamicModalByIndex(1);
   let header = await $(modal.modalHeaderTitle);
   await expect(header).toBeDisplayedInViewport({message:'Dynamic modal modalHeaderTitle from Deafault section is not visible on page'});
   await expect(header).toHaveText('Modal title + dynamic component');
   await expect(await modal.isDraggable()).toBe(false,'isDraggable should be false');
   await expect(await modal.isSlideInDown()).toBe(true,'isSlideInDown should be true');
   await expect(await modal.isMessageBox()).toBe(false,'isFlipInY should be false');

   await expect(await $(modal.modalFooterLeftButtonCO.button)).
    toBeDisplayedInViewport({message:'Dynamic modal modalFooterLeftButtonCO button is not visible on page'});

   await expect(await $(modal.modalFooterRightButtonCO.button)).
    toBeDisplayedInViewport({message:'Dynamic modal modalFooterRightButtonCO button is not visible on page'});

   await expect(await $(modal.closeButton)).
     toBeDisplayedInViewport({message:'Dynamic modal closeButton is not visible on page'});
   await (await $(modal.closeButton)).click();
  });
  it('should open <Draggable> modal window and verify if the window is draggable ', async () => {
   browser.addTestMeta({zephyrStep: "316151"});
   let sectionId= 'draggable';
   let scrollIntoSection = await $(dynModalPage.sectionById(sectionId));
   await scrollIntoSection.scrollIntoView();
   await (await $(dynModalPage.buttonPage.buttonFromSectionById(sectionId).button)).click();

   let modal = dynModalPage.dynamicModalByIndex(1);
   await expect(await $(modal.modalDialog)).
      toBeDisplayedInViewport({message:'Dynamic modal modalDialog from Deafault section is not visible on page'});

   await expect(await modal.isDraggable()).toBe(true,'isDraggable should be true');

   await expect(await $(modal.closeButton)).toBeDisplayedInViewport({message:'Dynamic modal closeButton is not visible on page'});
   await (await $(modal.closeButton)).click();
  });
  it('should open <Custom footer> modal window and verify elements inside modal window ', async () => {
   browser.addTestMeta({zephyrStep: "316159"});
   let sectionId= 'custom-footer';
   let scrollIntoSection = await $(dynModalPage.sectionById(sectionId));
   await scrollIntoSection.scrollIntoView();
   await (await $(dynModalPage.buttonPage.buttonFromSectionById(sectionId).button)).click();

   let modal = dynModalPage.dynamicModalByIndex(1);
   await expect(await $(modal.modalFooter)).toBeDisplayedInViewport({message:'Dynamic modal modalFooter from Deafault section is not visible on page'});
   await expect(await modal.hasCustomFooterContent()).toBe(true,'customFooterContent should be true');

   await expect(await $(modal.closeButton)).toBeDisplayedInViewport({message:'Dynamic modal closeButton is not visible on page'});
   await (await $(modal.closeButton)).click();
  });
});
