import Routing from '../../../../pages/eui/10x/routing-10x.js'
import EuiMessageBoxPage from '../../../../pages/eui/10x/eui/eui-message-box-container-10x.po.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'

describe('eUI - <eui-message-box> Component Object ', async () => {
  let page = new EuiMessageBoxPage();
  let testFolder = './/eui-message-box//';
  it('should navigate to <eui-message-box> demo page', async () => {
    browser.addTestMeta({uuid:"aadceb31-0d6a-4dfe-862f-98cdbca684ed", zephyrKey: "CCQA-1805", zephyrStep: "444701", reportGroups: ["eUI.10x.eui"]});
    await page.open(Routing.getEUIComponentUrl('eui-message-box'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    await pgTitle.scrollIntoView();
    await expect(pgTitle).toBeDisplayedInViewport({wait: 2000, message:'<eui-message-box> page title is not displayed on page'});
    await expect(await $(page.appDocPageById('eui-message-box'))).toExist({wait: 2000, message:
       'Page Id is not existing on page'});
    await expect(pgTitle).toHaveText('eui-message-box', 'Page title text is not as expected');
    await expect(await $(page.navigationList)).toBeDisplayedInViewport({wait: 2000, message:'Navigation List -> is not displayed on page'});
  });
  it('should verify the presence and number of component objects <eui-message-box> on page ', async () => {
    browser.addTestMeta({zephyrStep: "444702"});
    let sectionId= 'Default';
    let sectionElement = await $(page.sectionById(sectionId));
    await sectionElement.scrollIntoView();

    let messageBoxButton = page.euiButtonCOFromSectionWithId(sectionId).byTextContains('Open Message Box').andByIndex(1);
    await expect(await (await messageBoxButton.element())).toBeDisplayedInViewport({wait: 2000, message:'Message Box button is not displayed on page'});
    await (await $(messageBoxButton.currentPath)).click();
    let messageBox = await(await page.euiMessageBoxCo.element());
    await expect(messageBox).toBeDisplayedInViewport({wait: 2000, message:'Message Box window is not displayed on page'});

    await browser.pause(1000);
    if(browser.config.useWdioImageComparison) {
      await (await $(page.euiMessageBoxCo.messageBoxContent)).scrollIntoView();
      await chaiExpect(await browser.checkElement(await $(page.euiMessageBoxCo.messageBoxContent), testFolder+'img_MessageBoxByIndex1', 
      {hideElements: [await $('//eui-app-toolbar')]})).within(0, 6, 'Image comparison failed for img_MessageBoxByIndex1');
    }
  });
  it('should verify the Message Box header, content, accept and dismiss methods', async () => {
    browser.addTestMeta({zephyrStep: "444703"});
    let messageBox = page.euiMessageBoxCo;
    await expect(await $(messageBox.messageBoxTitle)).toBeDisplayedInViewport({wait: 2000, message:'Message Box header is not displayed on page'});
    await expect(await $(messageBox.messageBoxTitle)).toHaveText('Message box title', {wait: 2000, message:'Message Box header content is not as expected'});
    
    await chaiExpect(await messageBox.hasCloseButton()).equal(true, 'Message Box header should have close button');
    await expect(await $(messageBox.closeButtonIcon)).toBeDisplayedInViewport({wait: 2000, message:'Message Box close icon is not displayed'});
    await expect(await $(messageBox.messageBoxBodyContent)).toBeDisplayedInViewport({wait: 2000, message:'Message Box Body content is not displayed'});
    await expect(await $(messageBox.dismissButton.currentPath)).toBeDisplayedInViewport({wait: 2000, message:'Message Box dismiss button is not displayed'});
    await expect(await $(messageBox.acceptButton.currentPath)).toBeDisplayedInViewport({wait: 2000, message:'Message Box accept button is not displayed'});
    await (await (await messageBox.closeButtonCo.element())).click();
    
    await expect(await (await messageBox.element())).not.toBeDisplayed({wait: 2000, message:'Message Box should not be displayed after clicking on close button'});

    let sectionId= 'no-close-button';
    let sectionElement = await $(page.sectionById(sectionId));
    await sectionElement.scrollIntoView();

    let messageBoxButton = page.euiButtonCOFromSectionWithId(sectionId).byTextContains('Open Message Box').andByIndex(1);
    await expect(await (await messageBoxButton.element())).toBeDisplayedInViewport({wait: 2000, message:'Message Box button is not displayed on page'});
    await (await $(messageBoxButton.currentPath)).click();
  await browser.pause(1000);
    await expect(await (await messageBox.element())).toBeDisplayedInViewport({wait: 2000, message:'Message Box window is not displayed on page'});

    if(browser.config.useWdioImageComparison) {
      await (await $(page.euiMessageBoxCo.messageBoxContent)).scrollIntoView();
      await chaiExpect(await browser.checkElement(await $(page.euiMessageBoxCo.messageBoxContent), testFolder+'img_MessageBoxNoCloseButton', 
      {hideElements: [await $('//eui-app-toolbar')]})).within(0, 6, 'Image comparison failed for img_MessageBoxNoCloseButton');
    }

    await chaiExpect(await messageBox.hasCloseButton()).equal(false, 'Message Box header should NOT have close button');
    await (await $(messageBox.dismissButton.currentPath)).click();
    await browser.pause(1000);
    await expect(await (await messageBox.element())).not.toBeDisplayed({wait: 2000, message:'Message Box should not be displayed after clicking on close button'});
  });
  it('should verify the Message Box body severity warning', async () => {
    browser.addTestMeta({zephyrStep: "444704"});
    let sectionId = 'types';
    let sectionElement = await $(page.sectionById(sectionId));
    await sectionElement.scrollIntoView();
    let messageBoxButton = page.euiButtonCOFromSectionWithId(sectionId).byTextContains('Warning').andByIndex(1);
    await expect(await (await messageBoxButton.element())).toBeDisplayedInViewport({wait: 2000, message:'Message Box button is not displayed on page'});
    await (await $(messageBoxButton.currentPath)).click();
    await browser.pause(1000);
    let messageBox = page.euiMessageBoxCo;
    await expect(await (await messageBox.element())).toBeDisplayedInViewport({wait: 2000, message:'Message Box window is not displayed on page'});
    await chaiExpect(await messageBox.severity()).equal('warning', 'Message Box severity is not as expected');

    if(browser.config.useWdioImageComparison) {
      await (await $(messageBox.messageBoxContent)).scrollIntoView();
      await chaiExpect(await browser.checkElement(await $(messageBox.messageBoxContent), testFolder+'img_MessageBoxWarning', 
      {hideElements: [await $('//eui-app-toolbar')]})).within(0, 6, 'Image comparison failed for img_MessageBoxWarning');
    }

    await (await $(messageBox.closeButtonCo.currentPath)).click();
    await expect(await (await messageBox.element())).not.toBeDisplayed({wait: 2000, message:'Message Box should not be displayed after clicking on close button'})
  });
  it('should verify the Message Box body severity danger', async () => {
    browser.addTestMeta({zephyrStep: "444705"});
    let sectionId= 'types';
    let sectionElement = await $(page.sectionById(sectionId));
    await sectionElement.scrollIntoView();

    let messageBoxButton = page.euiButtonCOFromSectionWithId(sectionId).byTextContains('Danger').andByIndex(1);
    await expect(await (await messageBoxButton.element())).toBeDisplayedInViewport({wait: 2000, message:'Message Box button is not displayed on page'});
    await (await $(messageBoxButton.currentPath)).click();
    await browser.pause(1000);
    let messageBox = page.euiMessageBoxCo;
    await expect(await (await messageBox.element())).toBeDisplayedInViewport({wait: 2000, message:'Message Box window is not displayed on page'});
    await chaiExpect(await messageBox.severity()).equal('danger', 'Message Box severity is not as expected');
    
    if(browser.config.useWdioImageComparison) {
      await (await $(messageBox.messageBoxContent)).scrollIntoView();
      await chaiExpect(await browser.checkElement(await $(messageBox.messageBoxContent), testFolder+'img_MessageBoxDanger', 
      {hideElements: [await $('//eui-app-toolbar')]})).within(0, 6, 'Image comparison failed for img_MessageBoxDanger');
    }

    await (await $(messageBox.closeButtonCo.currentPath)).click();
    await expect(await (await messageBox.element())).not.toBeDisplayed({wait: 2000, message:'Message Box should not be displayed after clicking on close button'})
  });
  it('should verify the Message Box body severity success', async () => {
    browser.addTestMeta({zephyrStep: "444706"});
    let sectionId= 'types';
    let sectionElement = await $(page.sectionById(sectionId));
    await sectionElement.scrollIntoView();

    let messageBoxButton = page.euiButtonCOFromSectionWithId(sectionId).byTextContains('Success').andByIndex(1);
    await expect(await (await messageBoxButton.element())).toBeDisplayedInViewport({wait: 2000, message:'Message Box button is not displayed on page'});
    await (await $(messageBoxButton.currentPath)).click();
    await browser.pause(1000);
    let messageBox = page.euiMessageBoxCo;
    await expect(await (await messageBox.element())).toBeDisplayedInViewport({wait: 2000, message:'Message Box window is not displayed on page'});
    await chaiExpect(await messageBox.severity()).equal('success', 'Message Box severity is not as expected');

    if(browser.config.useWdioImageComparison) {
      await (await $(messageBox.messageBoxContent)).scrollIntoView();
      await chaiExpect(await browser.checkElement(await $(messageBox.messageBoxContent), testFolder+'img_MessageBoxSuccess', 
      {hideElements: [await $('//eui-app-toolbar')]})).within(0, 6, 'Image comparison failed for img_MessageBoxSuccess');
    }

    await (await $(messageBox.closeButtonCo.currentPath)).click();
    await expect(await (await messageBox.element())).not.toBeDisplayed({wait: 2000, message:'Message Box should not be displayed after clicking on close button'})
  });
  it('should verify the Message Box body severity Info', async () => {
    browser.addTestMeta({zephyrStep: "444707"});
    let sectionId= 'types';
    let sectionElement = await $(page.sectionById(sectionId));
    await sectionElement.scrollIntoView();

    let messageBoxButton = page.euiButtonCOFromSectionWithId(sectionId).byTextContains('Info').andByIndex(1);
    await expect(await (await messageBoxButton.element())).toBeDisplayedInViewport({wait: 2000, message:'Message Box button is not displayed on page'});
    await (await $(messageBoxButton.currentPath)).click();
    await browser.pause(1000);
    let messageBox = page.euiMessageBoxCo;
    await expect(await (await messageBox.element())).toBeDisplayedInViewport({wait: 2000, message:'Message Box window is not displayed on page'});
    await chaiExpect(await messageBox.severity()).equal('info', 'Message Box severity is not as expected');

    if(browser.config.useWdioImageComparison) {
      await (await $(messageBox.messageBoxContent)).scrollIntoView();
      await chaiExpect(await browser.checkElement(await $(messageBox.messageBoxContent), testFolder+'img_MessageBoxInfo', 
      {hideElements: [await $('//eui-app-toolbar')]})).within(0, 6, 'Image comparison failed for img_MessageBoxInfo');
    }

    await (await $(messageBox.closeButtonCo.currentPath)).click();
    await expect( await (await messageBox.element())).not.toBeDisplayed({wait: 2000, message:'Message Box should not be displayed after clicking on close button'})
  });
  it('should verify the Message Box body severity Question', async () => {
    browser.addTestMeta({zephyrStep: "444708"});
    let sectionId= 'types';
    let sectionElement = await $(page.sectionById(sectionId));
    await sectionElement.scrollIntoView();

    let messageBoxButton = page.euiButtonCOFromSectionWithId(sectionId).byTextContains('Question').andByIndex(1);
    await expect(await (await messageBoxButton.element())).toBeDisplayedInViewport({wait: 2000, message:'Message Box button is not displayed on page'});
    await (await $(messageBoxButton.currentPath)).click();
    await browser.pause(1000);
    let messageBox = page.euiMessageBoxCo;
    await expect(await (await messageBox.element())).toBeDisplayedInViewport({wait: 2000, message:'Message Box window is not displayed on page'});
    await chaiExpect(await messageBox.severity()).equal('question', 'Message Box severity is not as expected');

    if(browser.config.useWdioImageComparison) {
      await (await $(messageBox.messageBoxContent)).scrollIntoView();
      await chaiExpect(await browser.checkElement(await $(messageBox.messageBoxContent), testFolder+'img_MessageBoxQuestion', 
      {hideElements: [await $('//eui-app-toolbar')]})).within(0, 6, 'Image comparison failed for img_MessageBoxQuestion');
    }

    await (await $(messageBox.closeButtonCo.currentPath)).click();
    await expect(await (await messageBox.element())).not.toBeDisplayed({wait: 2000, message:'Message Box should not be displayed after clicking on close button'})

    sectionId= 'button-label';
    sectionElement = await $(page.sectionById(sectionId));
    await sectionElement.scrollIntoView();

    messageBoxButton = page.euiButtonCOFromSectionWithId(sectionId).byTextContains('Open Message Box').andByIndex(1);
    await expect(await (await messageBoxButton.element())).toBeDisplayedInViewport({wait: 2000, message:'Message Box button is not displayed on page'});
    await (await $(messageBoxButton.currentPath)).click();
    await browser.pause(1000);
    messageBox = page.euiMessageBoxCo;
    await expect( await (await messageBox.element())).toBeDisplayedInViewport({wait: 2000, message:'Message Box window is not displayed on page'});

    if(browser.config.useWdioImageComparison) {
      await (await $(messageBox.messageBoxContent)).scrollIntoView();
      await chaiExpect(await browser.checkElement(await $(messageBox.messageBoxContent), testFolder+'img_MessageBoxButtonLabel', 
      {hideElements: [await $('//eui-app-toolbar')]})).within(0, 6.2, 'Image comparison failed for img_MessageBoxButtonLabel');
    }

    await (await $(messageBox.closeButtonCo.currentPath)).click();
   await expect(await (await messageBox.element())).not.toBeDisplayed({wait: 2000, message:'Message Box should not be displayed after clicking on close button'})

  });
  
});
