import Routing from '../../../../pages/eui/10x/routing-10x.js'
import EuiFeedbackMessagePage from '../../../../pages/eui/10x/eui/eui-feedback-message-10x.po.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'

describe('eUI - <eui-feedback-message> Component Object ',async () => {
  let page = new EuiFeedbackMessagePage();
  let testFolder = './/eui-feedback-message//'
  it('should navigate to <eui-feedback-message> demo page',async () => {
    browser.addTestMeta({uuid:"34c1a98e-4170-11ec-81d3-0242ac130003", zephyrKey: "CCQA-1787", zephyrStep: "442855", reportGroups: ["eUI.14x.eui"]});
    await page.open(Routing.getEUIComponentUrl('eui-feedback-message'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    await pgTitle.scrollIntoView();
    await expect(await $(pgTitle)).toBeDisplayedInViewport({message:'<eui-feedback-message> page title is not visible on page'});
    await expect(await $(page.appDocPageById('eui-feedback-message'))).toExist({message:'Page Id is not existing on page'});
    await expect(pgTitle).toHaveText('eui-feedback-message', {wait:1000,message:'Page title text is not as expected'});
    await expect(await $(page.navigationList)).toBeDisplayedInViewport({message:'Navigation List -> is not visible on page'});
  });

  it('should verify the presence and number of components <eui-feedback-message> on page ',async () => {
    browser.addTestMeta({zephyrStep: "442857"});
    let sectionId= 'Default';
    let index = 1;
    let text = 'This is default control feedback';
    let feedbackMessageByIndex = await (await page.feedbackMessageByIndex(index).element());
    let feedbackMessageByText = await (await page.feedbackMessageByTextContains(text).element());
    let feedbackMessageByTextAndIndex = await (await page.feedbackMessageByTextEqualsAndIndex(text,index).element());
    await expect(await $(page.sectionById(sectionId))).toBeDisplayed({message:''+sectionId+' section -> is not displayed on page'});
    await expect(feedbackMessageByIndex).toBeDisplayed({message:'feedbackMessage by index '+ index +' is not displayed on page'});
    await expect(feedbackMessageByText).toBeDisplayed({message:'feedbackMessage by text '+ text +' is not displayed on page'});
    await expect(feedbackMessageByTextAndIndex).toBeDisplayed({message:'feedbackMessage by text '+ text +'and by index '+ index +' is not displayed on page'});
    await chaiExpect(await page.feedbackMessageByIndex(index).defaultComponentsCount()).equal(10, 'There should be 10 <eui-feedback-message> components on the page.');

    if(browser.config.useWdioImageComparison) {
      await feedbackMessageByIndex.scrollIntoView();
      await chaiExpect(await browser.checkElement(feedbackMessageByIndex, testFolder+'img_feedbackMessageByIndex', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for feedbackMessageByIndex');
      await feedbackMessageByText.scrollIntoView();
      await chaiExpect(await browser.checkElement(feedbackMessageByText, testFolder+'img_feedbackMessageByText', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for feedbackMessageByText');
      await feedbackMessageByTextAndIndex.scrollIntoView();
      await chaiExpect(await browser.checkElement(feedbackMessageByTextAndIndex, testFolder+'img_feedbackMessageByTextAndIndex', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for feedbackMessageByTextAndIndex');
    }
  });

  it('should verify the <eui-feedback-message> message-types',async () => {
    browser.addTestMeta({zephyrStep: "442858"});
    let sectionId = 'type';
    await (await $(page.sectionById(sectionId))).scrollIntoView();
    let feedbackMessageColor1 = await (await page.feedbackMessageFromSectionWithIdByIndex(sectionId, 1).element());
    let feedbackMessageColor2 = await (await page.feedbackMessageFromSectionWithIdByIndex(sectionId, 2).element());
    let feedbackMessageColor3 = await (await page.feedbackMessageFromSectionWithIdByIndex(sectionId, 3).element());
    let feedbackMessageColor4 = await (await page.feedbackMessageFromSectionWithIdByIndex(sectionId, 4).element());

   await expect(feedbackMessageColor1).toHaveAttrContaining('class', 'eui-feedback-message--info');
   await expect(feedbackMessageColor2).toHaveAttrContaining('class', 'eui-feedback-message--success');
   await expect(feedbackMessageColor3).toHaveAttrContaining('class', 'eui-feedback-message--warning');
   await expect(feedbackMessageColor4).toHaveAttrContaining('class', 'eui-feedback-message--danger');

    if(browser.config.useWdioImageComparison) {
      await feedbackMessageColor1.scrollIntoView();
      await chaiExpect(await browser.checkElement(feedbackMessageColor1, testFolder+'img_feedbackMessageColor1', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for feedbackMessageColor1');
      await feedbackMessageColor2.scrollIntoView();
      await chaiExpect(await browser.checkElement(feedbackMessageColor2, testFolder+'img_feedbackMessageColor2', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for feedbackMessageColor2');
      await feedbackMessageColor3.scrollIntoView();
      await chaiExpect(await browser.checkElement(feedbackMessageColor3, testFolder+'img_feedbackMessageColor3', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for feedbackMessageColor3');
      await feedbackMessageColor4.scrollIntoView();
      await chaiExpect(await browser.checkElement(feedbackMessageColor4, testFolder+'img_feedbackMessageColor4', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for feedbackMessageColor4');
    }
  });
});
