import Routing from '../../../../pages/eui/10x/routing-10x.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'
import UxDynamicMessageBoxPage from '../../../../pages/eui/10x/ux/ux-dynamic-message-box-10x.po.js'

describe('eUI - <ux-dynamic-message-box> Component Object', async () => {
  let dynMessagePage = new UxDynamicMessageBoxPage();
  it('should navigate to <ux-dynamic-message-box> component', async () => {
   browser.addTestMeta({uuid:"a9ede6de-d730-47c7-9912-f5329354dce7", zephyrKey: "CCQA-1047", zephyrStep: "397820", reportGroups: ["eUI.10x.ux"]});
   await dynMessagePage.open(Routing.getUxComponentUrl('ux-dynamic-message-box'));
   await CookieBannerActions.cookieBanner(true);
   let pgTitle = await $(dynMessagePage.pageTitle);
   let appDocPageId = await $(dynMessagePage.appDocPageById('ux-dynamic-message-box'));
   let navigationList = await $(dynMessagePage.navigationList);

   await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-dynamic-message-box> page title is not visible on page'});
   await expect(pgTitle).toHaveText('ux-dynamic-message-box', {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 verify component elements', async () => {
   browser.addTestMeta({zephyrStep: "397822"});

   let sectionId = 'Default';
   await (await $(dynMessagePage.sectionById(sectionId))).scrollIntoView();

   let button = await $(dynMessagePage.buttonFromSectionById(sectionId).buttonContent);
   await expect(button).toBeDisplayed({ message: 'Button from section ' + sectionId + ' is not visible on page' });
   await button.click();

   let mBox = dynMessagePage.dynamicMessageBoxByIndex(1);
   await expect(await $(mBox.bodyContent)).toBeDisplayed({ message: 'Dynamic message box from section ' + sectionId + ' is not visible on page' });

   await expect(await $(mBox.uxDynamicModalCo.modalHeaderTitle)).toHaveTextContaining('WARNING');
   await expect(await $(mBox.bodyContent)).toHaveTextContaining('this is the message of the ux-message-box');
   await expect(await mBox.hasBodyIcon()).toBe(true, 'Dynamic message Box doesnt have a body icon');

   await (await $( await mBox.dismissBtn())).click();
   await expect(await $(mBox.bodyContent)).not.toBeDisplayed({ message: 'Dynamic message box from section '
      + sectionId + ' is still visible on page' });
  });
  it('should verify buttons labels', async () => {
   browser.addTestMeta({zephyrStep: "397823"});

   let sectionId = 'button-labels';
   await (await $(dynMessagePage.sectionById(sectionId))).scrollIntoView();

   let button = await $(dynMessagePage.buttonFromSectionById(sectionId).buttonContent);
   await expect(button).toBeDisplayed({ message: 'Button from section ' + sectionId + ' is not visible on page' });
   await button.click();

   let mBox = dynMessagePage.dynamicMessageBoxByIndex(1);
   await expect(await $(mBox.bodyContent)).toBeDisplayed({ message: 'Dynamic message box from section '
      + sectionId + ' is not visible on page' });

   await expect(await $(mBox.uxDynamicModalCo.modalHeaderTitle)).toHaveTextContaining('Delete Item');
   await expect(await $(mBox.bodyContent)).toHaveTextContaining('Are you sure you want to delete this item?');
   await expect(await mBox.hasBodyIcon()).toBe(true, 'Dynamic message Box doesnt have a body icon');

   await expect(await $(await mBox.dismissBtn())).toHaveTextContaining('NO keep it');
   await expect(await $(await mBox.acceptBtn())).toHaveTextContaining('YES delete it');
   await (await $(await mBox.dismissBtn())).click();
   await expect(await $(mBox.bodyContent)).not.toBeDisplayed({ message: 'Dynamic message box from section '
      + sectionId + ' is still visible on page' });
  });
  it('should verify custom footer', async () => {
   browser.addTestMeta({zephyrStep: "397828"});

   let sectionId = 'custom-footer';
   await (await $(dynMessagePage.sectionById(sectionId))).scrollIntoView();

   let button = await $(dynMessagePage.buttonFromSectionById(sectionId).buttonContent);
   await expect(button).toBeDisplayed({ message: 'Button from section ' + sectionId + ' is not visible on page' });
   await button.click();

   let mBox = dynMessagePage.dynamicMessageBoxByIndex(1);
   await expect(await $(mBox.bodyContent)).toBeDisplayed({ message: 'Dynamic message box from section '
      + sectionId + ' is not visible on page' });
   await expect(await $(mBox.dynamicMessageBoxFooter)).toBeDisplayed({ message: 'Dynamic message box messageBoxFooter '
      + ' is not visible on page' });
   await expect(await $(mBox.dynamicMBoxFooterHorizontalLeft)).toBeDisplayed({ message: 'Dynamic message box footerHorizontalLeft '
      + ' is not visible on page' });
   let customBtn = await (await dynMessagePage.buttonCo.byTextContains('Related Action').element());
   await expect(customBtn).toBeDisplayed({ message: 'Dynamic message box custom footer button is not visible' });
   await expect(await mBox.hasCustomFooterContent()).toBe(true);

   await expect(await $(mBox.uxDynamicModalCo.modalHeaderTitle)).toHaveTextContaining('INFORMATION');
   await expect(await $(mBox.bodyContent)).toHaveTextContaining('this is the message of the ux-message-box');
   await expect(await mBox.hasBodyIcon()).toBe(true, 'Dynamic message Box doesnt have a body icon');

   await customBtn.click();
   await expect(await $(mBox.bodyContent)).not.toBeDisplayed({ message: 'Dynamic message box from section '
      + sectionId + ' is still visible on page' });
  });
  it('should verify typeClass=danger', async () => {
   browser.addTestMeta({zephyrStep: "397824"});

   let sectionId = 'typeClass';
   await (await $(dynMessagePage.sectionById(sectionId))).scrollIntoView();

   let button = await $(dynMessagePage.buttonFromSectionById(sectionId).byTextContains('typeclass=danger').buttonContent);
   await expect(button).toBeDisplayed({ message: 'Button from section ' + sectionId + ' is not visible on page' });
   await button.click();

   let mBox = dynMessagePage.dynamicMessageBoxByIndex(1);
   await expect(await $(mBox.bodyContent)).toBeDisplayed({ message: 'Dynamic message box from section '
      + sectionId + ' is not visible on page' });

   await expect(await $(mBox.uxDynamicModalCo.modalHeaderTitle)).toHaveTextContaining('ATTENTION');
   await expect(await $(mBox.bodyContent)).toHaveTextContaining('this is the message of the ux-message-box');
   await expect(await mBox.hasBodyIcon()).toBe(true, 'Dynamic message Box doesnt have a body icon');
   await expect(await mBox.isTypeDanger()).toBe(true);

   await (await $(await mBox.dismissBtn())).click();
   await expect(await $(mBox.bodyContent)).not.toBeDisplayed({ message: 'Dynamic message box from section '
      + sectionId + ' is still visible on page' });
  });
  it('should verify typeClass=success', async () => {
   browser.addTestMeta({zephyrStep: "397825"});

   let sectionId = 'typeClass';
   await (await $(dynMessagePage.sectionById(sectionId))).scrollIntoView();

   let button = await $(dynMessagePage.buttonFromSectionById(sectionId).byTextContains('typeclass=success').buttonContent);
   await expect(button).toBeDisplayed({ message: 'Button from section ' + sectionId + ' is not visible on page' });
   await button.click();

   let mBox = dynMessagePage.dynamicMessageBoxByIndex(1);
   await expect(await $(mBox.bodyContent)).toBeDisplayed({ message: 'Dynamic message box from section '
      + sectionId + ' is not visible on page' });

   await expect(await $(mBox.uxDynamicModalCo.modalHeaderTitle)).toHaveTextContaining('ATTENTION');
   await expect(await $(mBox.bodyContent)).toHaveTextContaining('this is the message of the ux-message-box');
   await expect(await mBox.hasBodyIcon()).toBe(true, 'Dynamic message Box doesnt have a body icon');
   await expect(await mBox.isTypeSuccess()).toBe(true);

   await (await $(await mBox.dismissBtn())).click();
   await expect(await $(mBox.bodyContent)).not.toBeDisplayed({ message: 'Dynamic message box from section '
      + sectionId + ' is still visible on page' });
  });
  it('should verify typeClass=info', async () => {
   browser.addTestMeta({zephyrStep: "397826"});

   let sectionId = 'typeClass';
   await (await $(dynMessagePage.sectionById(sectionId))).scrollIntoView();

   let button = await $(dynMessagePage.buttonFromSectionById(sectionId).byTextContains('typeclass=info').buttonContent);
   await expect(button).toBeDisplayed({ message: 'Button from section ' + sectionId + ' is not visible on page' });
   await button.click();

   let mBox = dynMessagePage.dynamicMessageBoxByIndex(1);
   await expect(await $(mBox.bodyContent)).toBeDisplayed({ message: 'Dynamic message box from section '
      + sectionId + ' is not visible on page' });

   await expect(await $(mBox.uxDynamicModalCo.modalHeaderTitle)).toHaveTextContaining('ATTENTION');
   await expect(await $(mBox.bodyContent)).toHaveTextContaining('this is the message of the ux-message-box');
   await expect(await mBox.hasBodyIcon()).toBe(true, 'Dynamic message Box doesnt have a body icon');
   await expect(await mBox.isTypeInfo()).toBe(true);

   await (await $(await mBox.dismissBtn())).click();
   await expect(await $(mBox.bodyContent)).not.toBeDisplayed({ message: 'Dynamic message box from section '
      + sectionId + ' is still visible on page' });
  });
  it('should verify typeClass=question', async () => {
   browser.addTestMeta({zephyrStep: "397827"});

   let sectionId = 'typeClass';
   await (await $(dynMessagePage.sectionById(sectionId))).scrollIntoView();

   let button = await $(dynMessagePage.buttonFromSectionById(sectionId).byTextContains('typeclass=question').buttonContent);
   await expect(button).toBeDisplayed({ message: 'Button from section ' + sectionId + ' is not visible on page' });
   await button.click();

   let mBox = dynMessagePage.dynamicMessageBoxByIndex(1);
   await expect(await $(mBox.bodyContent)).toBeDisplayed({ message: 'Dynamic message box from section '
      + sectionId + ' is not visible on page' });

   await expect(await $(mBox.uxDynamicModalCo.modalHeaderTitle)).toHaveTextContaining('ATTENTION');
   await expect(await $(mBox.bodyContent)).toHaveTextContaining('this is the message of the ux-message-box');
   await expect(await mBox.hasBodyIcon()).toBe(true, 'Dynamic message Box doesnt have a body icon');
   await expect(await mBox.isTypeQuestion()).toBe(true);

   await (await $(await mBox.dismissBtn())).click();
   await expect(await $(mBox.bodyContent)).not.toBeDisplayed({ message: 'Dynamic message box from section '
      + sectionId + ' is still visible on page' });
  });
  it('should verify typeClass=warning', async () => {
   browser.addTestMeta({zephyrStep: "397829"});

   let sectionId = 'typeClass';
   await (await $(dynMessagePage.sectionById(sectionId))).scrollIntoView();

   let button = await $(dynMessagePage.buttonFromSectionById(sectionId).byTextContains('typeclass=warning').buttonContent);
   await expect(button).toBeDisplayed({ message: 'Button from section ' + sectionId + ' is not visible on page' });
   await button.click();

   let mBox = dynMessagePage.dynamicMessageBoxByIndex(1);
   await expect(await $(mBox.bodyContent)).toBeDisplayed({ message: 'Dynamic message box from section '
      + sectionId + ' is not visible on page' });

   await expect(await $(mBox.uxDynamicModalCo.modalHeaderTitle)).toHaveTextContaining('ATTENTION');
   await expect(await $(mBox.bodyContent)).toHaveTextContaining('this is the message of the ux-message-box');
   await expect(await mBox.hasBodyIcon()).toBe(true, 'Dynamic message Box doesnt have a body icon');
   await expect(await mBox.isTypeWarning()).toBe(true);

   await (await $(await mBox.dismissBtn())).click();
   await expect(await $(mBox.bodyContent)).not.toBeDisplayed({ message: 'Dynamic message box from section '
      + sectionId + ' is still visible on page' });
  });
});
