import Routing from '../../../../pages/eui/10x/routing-10x.js';
import CookieBannerActions from '../../../../actions/cookieBanner.js';
import GrowlPage from '../../../../pages/eui/10x/eui/eui-growl-10x.po.js';
import EcasBasePage from '../../../../pages/ecas/ecas-base.js';

describe('eUI - <eui-growl> Component Object',async () => {
  let growlPage = new GrowlPage();
  let testFolder = './/eui-growl//';
  it('should navigate to <eui-growl> component',async () => {
    browser.addTestMeta({uuid:"804509e3-5c90-45d8-aec4-a13b63f7b57c", zephyrKey: "CCQA-1128", zephyrStep: "411006", reportGroups: ["eUI.10x.eui"]});
    await growlPage.open(Routing.getEUIComponentUrl('eui-growl'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(growlPage.pageTitle);
    let appDocPageId = await $(growlPage.appDocPageById('eui-growl'));
    let navigationList = await $(growlPage.navigationList);

    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<eui-growl> page title is not displayed on page'});
    await expect(pgTitle).toHaveText('eui-growl', {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 displayed on page'});
  });
  it('should verify the presence of component object in page ',async () => {
    browser.addTestMeta({zephyrStep: "411007"});
    let section = await $(growlPage.sectionById('Options'));
    await expect(section).toBeDisplayed({wait:1000, message:'<Options> section -> is not displayed on page'});
    await (await $('//options//input[@type="number"]')).setValue(5000);
    await (await $(growlPage.positionRadiobutton('bottom-center'))).click();
    await (await $(growlPage.buttonByTextContains('Info growl').currentPath)).click();
    let growl1 = growlPage.growlByIndex(1);
    let imageComparisonGrowl =  await $(growlPage.growlByIndex(1).dataE2E);
    await expect(imageComparisonGrowl).toExist({wait:1000, message:'Growl is present on page'});
    await expect(imageComparisonGrowl).toBeDisplayed({wait:1000, message:'Growl is displayed on page'});

    if(browser.config.useWdioImageComparison) {
      await imageComparisonGrowl.scrollIntoView();
      await browser.pause(1000);
      await chaiExpect(await browser.checkElement(imageComparisonGrowl, testFolder + 'img_InfoGrowl_ByIndex1',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_InfoGrowl_ByIndex1');
    }
    await expect(await $(growl1.dataE2E)).toExist({message:'Growl Data Div is not present on page'});
    await chaiExpect(await growl1.severity()).equal('info',{wait:1000, message: 'Growl Severity should be info'});
    await expect(await $(growl1.growlItemClose)).toBeDisplayed({wait:1000, message:'growlItemClose is not displayed on page'});
    await (await $(growl1.growlItemClose)).click()
  });
  it('should verify severity levels',async () => {
    browser.addTestMeta({zephyrStep: "411008"});
    await (await $(growlPage.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(growlPage.buttonByTextContains('Warning growl').currentPath)).click();
    let imageComparisonGrowl = await $(growlPage.growlByIndex(1).dataE2E);
    await expect(imageComparisonGrowl).toExist({wait:1000, message:'Growl is present on page'});
    await expect(imageComparisonGrowl).toBeDisplayed({wait:1000, message:'Growl is displayed on page'});

    if(browser.config.useWdioImageComparison) {
      await imageComparisonGrowl.scrollIntoView();
      await browser.pause(1000);
      await chaiExpect(await browser.checkElement(imageComparisonGrowl, testFolder+'img_WarningGrowl_ByIndex1',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_WarningGrowl_ByIndex1');
    }
    let growl1 = growlPage.growlByIndex(1);
    await chaiExpect(await growl1.severity()).equal('warning', {wait:1000, message:'Growl Severity should be warning'});
    await expect(await $(growl1.growlItemClose)).toBeDisplayedInViewport({message:'Growl Item Close is not displayed on page'});
    if (!(await (await $(growl1.growlItemClose)).isExisting() && await (await $(growl1.growlItemClose)).isDisplayed())){
      await (await $(growlPage.buttonByTextContains('Warning growl').currentPath)).click();
    }
    await (await $(growl1.growlItemClose)).click()
    await (await $(growlPage.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(growlPage.buttonByTextContains('Danger growl').currentPath)).click();

    if(browser.config.useWdioImageComparison) {
      await imageComparisonGrowl.scrollIntoView();
      await browser.pause(1000);
      await chaiExpect(await browser.checkElement(imageComparisonGrowl, testFolder+'img_DangerGrowl_ByIndex1',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_DangerGrowl_ByIndex1');
    }
    await chaiExpect(await growl1.severity()).equal('danger', {wait:1000, message:'growlSeverity should be danger'});
  });
  it('should verify the Growl CO Title and Details',async () => {
    browser.addTestMeta({zephyrStep: "411009"});
    await (await $(growlPage.sectionById('Options'))).scrollIntoView();
    await (await $(growlPage.allowStickyGrowlCheckbox)).click();
    await (await $(growlPage.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(growlPage.buttonByTextContains('Success growl').currentPath)).click();
    let imageComparisonGrowl = await $(growlPage.growlByIndex(1).dataE2E);

    if(browser.config.useWdioImageComparison) {
      await imageComparisonGrowl.scrollIntoView();
      await browser.pause(1000);
      await chaiExpect(await browser.checkElement(imageComparisonGrowl, testFolder+'img_SuccessGrowl_ByIndex1',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_SuccessGrowl_ByIndex1');
    }
    let growl1 = growlPage.growlByIndex(1);
    await expect(await $(growl1.growlItemContainer)).toBeDisplayedInViewport({message:' growlItemContainer is not displayed on page'});
    await chaiExpect(await growlPage.growlByIndex(1).severity()).equal('success', {wait:1000, message:'growlSeverity should be success'});
    await expect(await $(growl1.growlTitle)).toBeDisplayedInViewport({message: 'Growl Message Title is not displayed on page'});
    await (await $(growlPage.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(growlPage.buttonByTextContains('Success growl').currentPath)).click();
    await expect(await $(growl1.growlTitle)).toHaveText('Summary title', {message: 'Summary title should be "Summary title"'});
    await expect(await $(growl1.growlDetail)).toBeDisplayedInViewport({message:'Growl Message Detail is not displayed on page'});
    await expect(await $(growl1.growlDetail)).toHaveText('Message details', 'Growl Message Details should be "Message details');
    await expect(await $(growl1.growlItemClose)).toBeDisplayedInViewport({message:'Growl Item Close is not displayed on page'});
    await (await $(growl1.growlItemClose)).click();
    await (await $(growlPage.allowStickyGrowlCheckbox)).click();
  });
  it('should verify the apperance of multiple Growls on screen',async () => {
    browser.addTestMeta({zephyrStep: "411010"});
    await (await $(growlPage.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(growlPage.allowMultipleGrowlsCheckbox)).click();
    await (await $(growlPage.buttonByTextContains('Info growl').currentPath)).click();
    await (await $(growlPage.buttonByTextContains('Success growl').currentPath)).click();
    await (await $(growlPage.buttonByTextContains('Warning growl').currentPath)).click();
    await (await $(growlPage.buttonByTextContains('Danger growl').currentPath)).click();
    await chaiExpect(await (await $$(growlPage.growlByTextContains("growl").byDefault().growlItemContainer)).length).equal(4, 'There should be 4 growl itemts on page');
    await (await $(growlPage.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(growlPage.allowMultipleGrowlsCheckbox)).click();
  });
  it('should verify icon severity levels',async () => {
    browser.addTestMeta({zephyrStep: "411011"});
    await (await $(growlPage.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(growlPage.buttonByTextContains('Info growl').currentPath)).click();
    let growl1 = growlPage.growlByIndex(1);
    await chaiExpect(await growl1.iconSeverity()).equal('info', {wait:1000, message:'info-circle icon is not displayed on Info growl'});
    await (await $(growlPage.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(growlPage.buttonByTextContains('Warning growl').currentPath)).click();
    await chaiExpect(await growl1.iconSeverity()).equal('warning', {wait:1000, message:'exclamation-circle icon is not displayed on Warning growl'});
    await (await $(growlPage.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(growlPage.buttonByTextContains('Success growl').currentPath)).click();
    await chaiExpect(await (growl1.iconSeverity())).equal('success', {wait:1000, message:'check-circle icon is not displayed on Success growl'});
    await (await $(growlPage.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(growlPage.buttonByTextContains('Danger growl').currentPath)).click();
    await chaiExpect(await growl1.iconSeverity()).equal('danger', {wait:1000, message:'ecl-error icon is not displayed on Danger growl'});
  });
  it('should verify position',async () => {
    browser.addTestMeta({zephyrStep: "411012"});
    await (await $(growlPage.sectionById('Options'))).scrollIntoView();
    await (await $(growlPage.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(growlPage.positionRadiobutton('top-left'))).click();
    await (await $(growlPage.buttonByTextContains('Info growl').currentPath)).click();
    let growl1= growlPage.growlByIndex(1);
    await chaiExpect(await growl1.growlPosition()).equal('top-left', {wait:1000, message:'class on growl should contain eui-growl--top-left'});
    await chaiExpect(await growl1.growlSlideDirection()).equal('SlideInDown', {wait:1000, message:'growlSlideInDown is not displayed on page'});
    await (await $(growlPage.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(growlPage.positionRadiobutton('top-center'))).click();
    await (await $(growlPage.buttonByTextContains('Info growl').currentPath)).click();
    await chaiExpect(await growl1.growlPosition()).equal('top-center', {wait:1000, message:'class on growl should contain eui-growl--top-center'});
    await chaiExpect(await growl1.growlSlideDirection()).equal('SlideInDown', {wait:1000, message:'growlSlideInDown is not displayed on page'});
    await (await $(growlPage.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(growlPage.positionRadiobutton('top-right'))).click();
    await (await $(growlPage.buttonByTextContains('Info growl').currentPath)).click();
    await chaiExpect(await growl1.growlPosition()).equal('top-right', {wait:1000, message:'class on growl should contain eui-growl--top-right'});
    await chaiExpect(await growl1.growlSlideDirection()).equal('SlideInDown', {wait:1000, message:'growlSlideInDown is not displayed on page'});
    await (await $(growlPage.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(growlPage.positionRadiobutton('bottom-left'))).click();
    await (await $(growlPage.buttonByTextContains('Info growl').currentPath)).click();
    await chaiExpect(await growl1.growlPosition()).equal('bottom-left', {wait:1000, message:'class on growl should contain eui-growl--bottom-left'});
    await chaiExpect(await growl1.growlSlideDirection()).equal('SlideInUp', {wait:1000, message:'growlSlideInUp is not displayed on page'});
    await (await $(growlPage.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(growlPage.positionRadiobutton('bottom-center'))).click();
    await (await $(growlPage.buttonByTextContains('Info growl').currentPath)).click();
    await chaiExpect(await growl1.growlPosition()).equal('bottom-center', {wait:1000, message:'class on growl should contain eui-growl--bottom-center'});
    await chaiExpect(await growl1.growlSlideDirection()).equal('SlideInUp', {wait:1000, message:'growlSlideInUp is not displayed on page'});
    await (await $(growlPage.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(growlPage.positionRadiobutton('bottom-right'))).click();
    await (await $(growlPage.buttonByTextContains('Info growl').currentPath)).click();
    await chaiExpect(await growlPage.growlByIndex(1).growlPosition()).equal('bottom-right', {wait:1000, message:'class on growl should contain eui-growl--bottom-right'});
    await chaiExpect(await growl1.growlSlideDirection()).equal('SlideInUp', {wait:1000, message:'growlSlideInUp is not displayed on page'});
  });
  it('should verify isSticky property',async () => {
    browser.addTestMeta({zephyrStep: "411013"});
    await (await $(growlPage.sectionById('Options'))).scrollIntoView();
    await (await $(growlPage.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(growlPage.positionRadiobutton('bottom-center'))).click();
    await (await $(growlPage.allowStickyGrowlCheckbox)).scrollIntoView();
    await (await $(growlPage.allowStickyGrowlCheckbox)).click();
    if (!(await (await $(growlPage.stickyInput)).isSelected())) {
      await (await $(growlPage.allowStickyGrowlCheckbox)).click();
    }
    await (await $(growlPage.buttonByTextContains('Info growl').currentPath)).click();
    await expect(await $(growlPage.growlByTextContains('Summary title').currentPath)).toBeDisplayedInViewport({message:'growlByTextContains is not displayed on page'});
    await chaiExpect(await growlPage.growlByTextContains('Summary title').isSticky()).equal(true, 'Growl should be sticky');
    await (await $(growlPage.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(growlPage.allowStickyGrowlCheckbox)).click();
    await (await $(growlPage.buttonByTextContains('Info growl').currentPath)).click();
    await expect(await $(growlPage.growlByTextContains('Summary title').currentPath)).toBeDisplayedInViewport({message:'growlByTextContains is not displayed on page'});
    await chaiExpect(await growlPage.growlByTextContains('Summary title').isSticky()).equal(false, 'Growl should be not be sticky');
  });

});
