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

describe('should navigate to  <eui-growl> Component Object', async () => {
  let page = new GrowlPage();
  it('should navigate to <eui-growl> component ', async () => {
    browser.addTestMeta({uuid:"670b8d6c-a36c-11eb-bcbc-0242ac130002", zephyrKey: "CCQA-753", zephyrStep: "365104", reportGroups: ["eUI.10x.ux"]});
    await page.open(Routing.getUxComponentUrl('ux-growl'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    let appDocPageId = await $(page.appDocPageById('ux-growl'));
    let navigationList = await $(page.navigationList);

    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-growl> page title is not visible on page'});
    await expect(pgTitle).toHaveText('ux-growl', {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 the presence of component object in page ', async () => {
    browser.addTestMeta({zephyrStep: "365105"});
    let section = await $(page.sectionById('Options'));
    await expect(section).toBeDisplayed({wait:1000, message:'<Options> section -> is not visible on page'});
    await (await $('//options//input[@type="number"]')).setValue(6000);
    await (await $(page.buttonByTextContains('Info growl').currentPath)).click();
    let growl1 =page.growlByIndex(1);
    await expect(await $(growl1.growlDataDiv)).toBeDisplayedInViewport({message:'growlDataDiv is not visible on page'});
    await expect(await growl1.growlSeverity()).toContain('info', 'growlSeverity should be info');
    await expect(await $(growl1.growlClose)).toBeDisplayedInViewport({message:'growlClose is not visible on page'});

    if (!(await(await $(growl1.growlClose)).isExisting() && await (await $(growl1.growlClose)).isDisplayed())){
      await (await $(page.buttonByTextContains('Info growl').currentPath)).click();
    }
    await (await $(growl1.growlClose)).click()
  });
  it('should verify severity levels', async () => {
    browser.addTestMeta({zephyrStep: "365106"});
    await (await $(page.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(page.buttonByTextContains('Warning growl').currentPath)).click();
    let growl1 = page.growlByIndex(1);
    await expect(await growl1.growlSeverity()).toContain('warning', 'growlSeverity should be warning');
    await expect(await $(growl1.growlClose)).
      toBeDisplayedInViewport({message:'growlClose is not visible on page'});
    if (!(await (await $(growl1.growlClose)).isExisting() && await (await $(growl1.growlClose)).isDisplayed())){
      await (await $(page.buttonByTextContains('Warning growl').currentPath)).click();
    }
    await (await $(growl1.growlClose)).click()

    await (await $(page.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(page.buttonByTextContains('Danger growl').currentPath)).click();
    await expect(await growl1.growlSeverity()).toContain('danger', 'growlSeverity should be danger');
  });
  it('should verify isSticky property', async () => {
    browser.addTestMeta({zephyrStep: "378355"});
    await (await $(page.sectionById('Options'))).scrollIntoView();
    await (await $(page.buttonByTextContains('Clear growls').currentPath)).click();
    await browser.waitUntil(async () => await (await $(page.allowStickyGrowlCheckbox())).isClickable() === true, { timeout: 3000, timeoutMsg: 'StickyGrowlCheckbox is not clickable.' });
    await (await $(page.allowStickyGrowlCheckbox())).click();
    await (await $(page.buttonByTextContains('Info growl').currentPath)).click();
    await expect(await $(page.growlByTextContains('Summary title').currentPath)).toBeDisplayedInViewport({message:'growlByTextContains is not visible on page'});
    await expect(await page.growlByTextContains('Summary title').isSticky()).toBe(true, 'Growl should be sticky');
    await (await $(page.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(page.allowStickyGrowlCheckbox())).click();
    await (await $(page.buttonByTextContains('Info growl').currentPath)).click();
    await expect(await $(page.growlByTextContains('Summary title').currentPath)).
      toBeDisplayedInViewport({message:'growlByTextContains is not visible on page'});
    await expect(await page.growlByTextContains('Summary title').isSticky()).toBe(false, 'Growl should be not be sticky');
  });
  it('should verify the Growl CO Title and Details', async () => {
    browser.addTestMeta({zephyrStep: "365107"});
    await (await $(page.sectionById('Options'))).scrollIntoView();
    await (await $(page.allowStickyGrowlCheckbox())).click();
    await (await $(page.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(page.buttonByTextContains('Success growl').currentPath)).click();
    let growl1 = page.growlByIndex(1);
    await expect(await $(growl1.growlItemContainer)).toBeDisplayedInViewport({message: ' growlItemContainer is not visible on page'});
    await expect(await page.growlByIndex(1).growlSeverity()).toContain('success', 'growlSeverity should be success');
    await expect(await $(growl1.growlMessagetitle)).toBeDisplayedInViewport({message:
      ' growlMessagetitle is not visible on page'});
    await (await $(page.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(page.buttonByTextContains('Success growl').currentPath)).click();
    await expect(await (await $(growl1.growlMessagetitle)).getText()).toBe('Summary title', 'Summary title should be "Summary title"');
    await expect(await $(growl1.growlMessageDetail)).toBeDisplayedInViewport({message:' growlMessageDetail is not visible on page'});
    await expect(await (await $(growl1.growlMessageDetail)).getText()).toBe('Message details','Growl Message Details should be "Message details');
    await expect(await $(growl1.growlClose)).toBeDisplayedInViewport({message:'growlClose is not visible on page'});
    await (await $(growl1.growlClose)).click();
    await (await $(page.allowStickyGrowlCheckbox())).click();
  });
  it('should verify the apperance of multiple Growls on screen', async () => {
    browser.addTestMeta({zephyrStep: "365108"});
    await (await $(page.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(page.allowMultipleGrowlsCheckbox())).click();
    await (await $(page.buttonByTextContains('Info growl').currentPath)).click();
    await (await $(page.buttonByTextContains('Success growl').currentPath)).click();
    await (await $(page.buttonByTextContains('Warning growl').currentPath)).click();
    await (await $(page.buttonByTextContains('Danger growl').currentPath)).click();
    await expect(await (await $$(page.growlByTextContains("growl").byDefault().growlItemContainer)).length).toBe(4);
    await (await $(page.allowMultipleGrowlsCheckbox())).click();
  });
  it('should verify icon severity levels', async () => {
    browser.addTestMeta({zephyrStep: "378353"});
    await (await $(page.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(page.buttonByTextContains('Info growl').currentPath)).click();
    let growl1 = page.growlByIndex(1);
    await expect(await $(growl1.IconBySeverity('info-circle'))).toBeDisplayed({message:'info-circle icon is not displayed on Info growl'})
    await (await $(page.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(page.buttonByTextContains('Warning growl').currentPath)).click();
    await expect(await $(growl1.IconBySeverity('exclamation-circle'))).toBeDisplayed({message:'exclamation-circle icon is not displayed on Warning growl'})
    await (await $(page.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(page.buttonByTextContains('Success growl').currentPath)).click();
    await expect(await $(growl1.IconBySeverity('check-circle'))).toBeDisplayed({message:'check-circle icon is not displayed on Success growl'});
    await (await $(page.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(page.buttonByTextContains('Danger growl').currentPath)).click();
    await expect(await $(growl1.IconBySeverity('ecl-error'))).toBeDisplayed({message:'ecl-error icon is not displayed on Danger growl'});
  });
  it('should verify position', async () => {
    browser.addTestMeta({zephyrStep: "378354"});
    await (await $(page.sectionById('Options'))).scrollIntoView();
    await (await $(page.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(page.positionRadiobutton('top-left'))).click();
    await (await $(page.buttonByTextContains('Info growl').currentPath)).click();
    await expect(await $(page.growlByTextContains('Summary title').growlDataDiv)).
      toHaveAttrContaining('class', 'eui-growl--top-left', {message:'class on growl should contain eui-growl--top-left'});
    let growl1= page.growlByIndex(1);
    await expect(await $(growl1.growlSlideInDown)).toBeDisplayedInViewport({message:'growlSlideInDown is not visible on page'});
    await (await $(page.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(page.positionRadiobutton('top-center'))).click();
    await (await $(page.buttonByTextContains('Info growl').currentPath)).click();
    await expect(await $(page.growlByTextContains('Summary title').growlDataDiv)).
      toHaveAttrContaining('class', 'eui-growl--top-center', {message:'class on growl should contain eui-growl--top-center'});
    await expect(await $(growl1.growlSlideInDown)).toBeDisplayedInViewport({message:'growlSlideInDown is not visible on page'});
    await (await $(page.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(page.positionRadiobutton('top-right'))).click();
    await (await $(page.buttonByTextContains('Info growl').currentPath)).click();
    await expect(await $(page.growlByTextContains('Summary title').growlDataDiv)).
     toHaveAttrContaining('class', 'eui-growl--top-right', {message:'class on growl should contain eui-growl--top-right'});
    await expect(await $(growl1.growlSlideInDown)).toBeDisplayedInViewport({message:'growlSlideInDown is not visible on page'});
    await (await $(page.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(page.positionRadiobutton('bottom-left'))).click();
    await (await $(page.buttonByTextContains('Info growl').currentPath)).click();
    await expect(await $(page.growlByTextContains('Summary title').growlDataDiv)).
      toHaveAttrContaining('class', 'bottom-left', {message:'class on growl should contain bottom-left'});
    await expect(await $(growl1.growlSlideInUp)). toBeDisplayedInViewport({message:'growlSlideInUp is not visible on page'});
    await (await $(page.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(page.positionRadiobutton('bottom-center'))).click();
    await (await $(page.buttonByTextContains('Info growl').currentPath)).click();
    await expect(await $(page.growlByTextContains('Summary title').growlDataDiv)).
      toHaveAttrContaining('class', 'eui-growl--bottom-center', {message:'class on growl should contain eui-growl--bottom-center'});
    await expect(await $(growl1.growlSlideInUp)).toBeDisplayedInViewport({message:'growlSlideInUp is not visible on page'});
    await (await $(page.buttonByTextContains('Clear growls').currentPath)).click();
    await (await $(page.positionRadiobutton('bottom-right'))).click();
    await (await $(page.buttonByTextContains('Info growl').currentPath)).click();
    await expect(await $(page.growlByTextContains('Summary title').growlDataDiv)).
     toHaveAttrContaining('class', 'bottom-right', {message:'class on growl should contain bottom-right'});
    await expect(await $(growl1.growlSlideInUp)).toBeDisplayedInViewport({message:'growlSlideInUp is not visible on page'});
  });
 });
