import Routing from '../../../../pages/eui/10x/routing-10x.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'
import BadgePage from '../../../../pages/eui/10x/ux/ux-badge-10x.po.js'

describe('eUI - <ux-badge> Component Object', async () => {
  let badgePage = new BadgePage();
  let testFolder = './/ux//ux-badge//';
  it('should navigate to <ux-badge> component', async () => {
    browser.addTestMeta({uuid:"4f1a60d4-71f8-11eb-9439-0242ac130002", zephyrKey: "CCQA-719", zephyrStep: "361286", reportGroups: ["eUI.10x.ux"]});
    await badgePage.open(Routing.getUxComponentUrl('ux-badge'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(badgePage.pageTitle);
    let appDocPageId = await $(badgePage.appDocPageById('ux-badge'));
    let navigationList = await $(badgePage.navigationList);

    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-badge> page title is not visible on page'});
    await expect(pgTitle).toHaveText('ux-badge', {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 the Component Object on the page', async () => {
    browser.addTestMeta({zephyrStep: "361287"});
    let index = 1;
    let badgeByIndex1 = await (await badgePage.badgeByIndex(index).element());
    await expect(badgeByIndex1).toExist('Badge with index "' + index + '" not existing on page');
    await badgeByIndex1.scrollIntoView();

    // image compare
    if(browser.config.useWdioImageComparison) {
     await expect(await browser.checkElement(badgeByIndex1, testFolder+'img_badgeByIndex1', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
    }

    let textContent = 'Outline badge';
    let badgeByTextContains = await (await badgePage.badgeByTextContains(textContent).element());
    await expect(badgeByTextContains).toExist('<ux-badge> containing text: "' + textContent + '" not existing on page');
    await badgeByTextContains.scrollIntoView();

    // image compare
    if(browser.config.useWdioImageComparison) {
     await expect(await browser.checkElement(badgeByTextContains, testFolder+'img_badgeByTextContains', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
    }

    let badgeByTextAndIndex1 = await (await badgePage.badgeByTextEqualsAndIndex(textContent, index).element());
    await expect(badgeByTextAndIndex1).toExist('<ux-badge> with text: "' + textContent + '" and index: ' + index + ' does not exist on page');
    await badgeByTextAndIndex1.scrollIntoView();

    // image compare
    if(browser.config.useWdioImageComparison) {
     await expect(await browser.checkElement(badgeByTextAndIndex1, testFolder+'img_badgeByTextAndIndex1', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
    }
  });
  it('should verify the <ux-badge> isPill method', async () => {
    browser.addTestMeta({zephyrStep: "361289"});
    let sectionId = 'isPill';
    let sectionElement = await $(badgePage.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();

    let badge = badgePage.badgeFromSectionByIndex(sectionId, 1);
    await expect(await (await badge.element())).toBeDisplayedInViewport({message:'<ux-badge> isPill is not visible on page'});
    await expect(await badge.isPill()).toBe(true);

    // image compare
    if(browser.config.useWdioImageComparison) {
     await expect(await browser.checkElement(await (await badge.element()), testFolder+'img_badgeIsPill', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
    }
  });
  it('should verify the <ux-badge> isOutline method', async () => {
    browser.addTestMeta({zephyrStep: "361288"});
    let sectionId = 'isOutline';
    let sectionElement = await $(badgePage.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();

    let badge = badgePage.badgeFromSectionByIndex(sectionId, 1);
    await expect(await (await badge.element())).toBeDisplayedInViewport({message:'<ux-badge> isOutline is not visible on page'});
    await expect(await badge.isOutline()).toBe(true);

    // image compare
    if(browser.config.useWdioImageComparison) {
     await expect(await browser.checkElement(await (await badge.element()), testFolder+'img_badgeIsOutline', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
    }
  });
  it('should verify the <ux-badge> typeClass method', async () => {
    browser.addTestMeta({zephyrStep: "376748"});
    let sectionId = 'typeClass';
    let sectionElement = await $(badgePage.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();

    let badgeSection2 = await $(badgePage.badgeFromSectionByIndex(sectionId, 2).currentPath);
    let badgeSection3 = await $(badgePage.badgeFromSectionByIndex(sectionId, 3).currentPath);
    let badgeSection4 = await $(badgePage.badgeFromSectionByIndex(sectionId, 4).currentPath);
    let badgeSection5 = await $(badgePage.badgeFromSectionByIndex(sectionId, 5).currentPath);
    let badgeSection6 = await $(badgePage.badgeFromSectionByIndex(sectionId, 6).currentPath);
    let badgeSection7 = await $(badgePage.badgeFromSectionByIndex(sectionId, 7).currentPath);
    let badgeSection8 = await $(badgePage.badgeFromSectionByIndex(sectionId, 8).currentPath);

    await expect(await badgeSection2.getAttribute('typeclass')).toBe('primary');
    await expect(await badgeSection3.getAttribute('typeclass')).toBe('secondary');
    await expect(await badgeSection4.getAttribute('typeclass')).toBe('info');
    await expect(await badgeSection5.getAttribute('typeclass')).toBe('success');
    await expect(await badgeSection6.getAttribute('typeclass')).toBe('warning');
    await expect(await badgeSection7.getAttribute('typeclass')).toBe('danger');
    await expect(await badgeSection8.getAttribute('typeclass')).toBe('accent');

    await expect(await badgePage.badgeFromSectionByIndex(sectionId, 9).isPill()).toBe(true);

    // image compare
    if(browser.config.useWdioImageComparison) {
     await expect(await browser.checkElement(badgeSection2, testFolder+'img_badgeSection2', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
     await expect(await browser.checkElement(badgeSection3, testFolder+'img_badgeSection3', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
     await expect(await browser.checkElement(badgeSection4, testFolder+'img_badgeSection4', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
     await expect(await browser.checkElement(badgeSection5, testFolder+'img_badgeSection5', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
     await expect(await browser.checkElement(badgeSection6, testFolder+'img_badgeSection6', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
     await expect(await browser.checkElement(badgeSection7, testFolder+'img_badgeSection7', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
     await expect(await browser.checkElement(badgeSection8, testFolder+'img_badgeSection8', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
    }
  });
  it('should verify the <ux-badge> isTinier method', async () => {
    browser.addTestMeta({zephyrStep: "361294"});
    let sectionId = 'isTinier';
    let section = await $(badgePage.sectionById(sectionId));
    await expect(section).toExist('<' + sectionId + '> section -> does not exist on page');
    await section.scrollIntoView();

    let badge1 = badgePage.badgeFromSectionByIndex(sectionId, 1);
    await expect(await badge1.isTinier()).toBe(true);

    let badge2 = badgePage.badgeFromSectionByIndex(sectionId, 2);
    await expect(await (await $(badge2.currentPath)).getAttribute('typeclass')).toBe('primary');
    await expect(await badge2.isTinier()).toBe(true);

    // rounded badges
    let badge9 = badgePage.badgeFromSectionByIndex(sectionId, 9);
    await expect(await badge9.isTinier()).toBe(true);
    await expect(await badge9.isPill()).toBe(true);

    let badge10 = badgePage.badgeFromSectionByIndex(sectionId, 10);
    await expect(await (await $(badge10.currentPath)).getAttribute('typeclass')).toBe('primary');
    await expect(await badge10.isTinier()).toBe(true);
    await expect(await badge10.isPill()).toBe(true);

    // image compare
    if(browser.config.useWdioImageComparison) {
     await expect(await browser.checkElement(await (await badge1.element()), testFolder+'img_badge1IsTinier', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
     await expect(await browser.checkElement(await (await badge2.element()), testFolder+'img_badge2IsTinier', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
     await expect(await browser.checkElement(await (await badge9.element()), testFolder+'img_badge9IsTinier', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
     await expect(await browser.checkElement(await (await badge10.element()), testFolder+'img_badge10IsTinier', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
    }
  });
  it('should verify the <ux-badge> isTiny method', async () => {
    browser.addTestMeta({zephyrStep: "361292"});
    let sectionId = 'isTiny';
    let section = await $(badgePage.sectionById(sectionId));
    await expect(section).toExist('<' + sectionId + '> section -> does not exist on page');
    await section.scrollIntoView();

    let badge1IsTiny = badgePage.badgeFromSectionByIndex(sectionId, 1);
    await expect(await badge1IsTiny.isTiny()).toBe(true);

    let badge2IsTiny = badgePage.badgeFromSectionByIndex(sectionId, 2);
    await expect(await (await $(badge2IsTiny.currentPath)).getAttribute('typeclass')).toBe('primary');
    await expect(await badge2IsTiny.isTiny()).toBe(true);

    // rounded badges
    let badge9IsTiny = badgePage.badgeFromSectionByIndex(sectionId, 9);
    await expect(await badge9IsTiny.isTiny()).toBe(true);
    await expect(await badge9IsTiny.isPill()).toBe(true);

    let badge10IsTiny = badgePage.badgeFromSectionByIndex(sectionId, 10);
    await expect(await (await $(badge10IsTiny.currentPath)).getAttribute('typeclass')).toBe('primary');
    await expect(await badge10IsTiny.isTiny()).toBe(true);
    await expect(await badge10IsTiny.isPill()).toBe(true);

    // image compare
    if(browser.config.useWdioImageComparison) {
     await expect(await browser.checkElement(await (await badge1IsTiny.element()), testFolder+'img_badge1IsTiny', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
     await expect(await browser.checkElement(await (await badge2IsTiny.element()), testFolder+'img_badge2IsTiny', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
     await expect(await browser.checkElement(await (await badge9IsTiny.element()), testFolder+'img_badge9IsTiny', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
     await expect(await browser.checkElement(await (await badge10IsTiny.element()), testFolder+'img_badge10IsTiny', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
    }
  });
  it('should verify the <ux-badge> isSmall method', async () => {
    browser.addTestMeta({zephyrStep: "361291"});
    let sectionId = 'isSmall';
    let section = await $(badgePage.sectionById(sectionId));
    await expect(section).toExist('<' + sectionId + '> section -> does not exist on page');
    await section.scrollIntoView();

    let badge1IsSmall = badgePage.badgeFromSectionByIndex(sectionId, 1);
    await expect(await badge1IsSmall.isSmall()).toBe(true);

    let badge2IsSmall = badgePage.badgeFromSectionByIndex(sectionId, 2);
    await expect(await (await $(badge2IsSmall.currentPath)).getAttribute('typeclass')).toBe('primary');
    await expect(await badge2IsSmall.isSmall()).toBe(true);

    // rounded badges
    let badge9IsSmall = badgePage.badgeFromSectionByIndex(sectionId, 9);
    await expect(await badge9IsSmall.isSmall()).toBe(true);
    await expect(await badge9IsSmall.isPill()).toBe(true);

    let badge10IsSmall = badgePage.badgeFromSectionByIndex(sectionId, 10);
    await expect(await (await $(badge10IsSmall.currentPath)).getAttribute('typeclass')).toBe('primary');
    await expect(await badge10IsSmall.isSmall()).toBe(true);
    await expect(await badge10IsSmall.isPill()).toBe(true);

    // image compare
    if(browser.config.useWdioImageComparison) {
     await expect(await browser.checkElement(await (await badge1IsSmall.element()), testFolder+'img_badge1IsSmall', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
     await expect(await browser.checkElement(await (await badge2IsSmall.element()), testFolder+'img_badge2IsSmall', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
     await expect(await browser.checkElement(await (await badge9IsSmall.element()), testFolder+'img_badge9IsSmall', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
     await expect(await browser.checkElement(await (await badge10IsSmall.element()), testFolder+'img_badge10IsSmall', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
    }
  });
  it('should verify the <ux-badge> isLarge method', async () => {
    browser.addTestMeta({zephyrStep: "361290"});
    let sectionId = 'isLarge';
    let section = await $(badgePage.sectionById(sectionId));
    await expect(section).toExist('<' + sectionId + '> section -> does not exist on page');
    await section.scrollIntoView();

    let badge1IsLarge = badgePage.badgeFromSectionByIndex(sectionId, 1);
    await expect(await badge1IsLarge.isLarge()).toBe(true);

    let badge2IsLarge = badgePage.badgeFromSectionByIndex(sectionId, 2);
    await expect(await (await $(badge2IsLarge.currentPath)).getAttribute('typeclass')).toBe('primary');
    await expect(await badge2IsLarge.isLarge()).toBe(true);

    // rounded badges
    let badge9IsLarge = badgePage.badgeFromSectionByIndex(sectionId, 9);
    await expect(await badge9IsLarge.isLarge()).toBe(true);
    await expect(await badge9IsLarge.isPill()).toBe(true);

    let badge10IsLarge = badgePage.badgeFromSectionByIndex(sectionId, 10);
    await expect(await (await $(badge10IsLarge.currentPath)).getAttribute('typeclass')).toBe('primary');
    await expect(await badge10IsLarge.isLarge()).toBe(true);
    await expect(await badge10IsLarge.isPill()).toBe(true);

    // image compare
    if(browser.config.useWdioImageComparison) {
     await expect(await browser.checkElement(await (await badge1IsLarge.element()), testFolder+'img_badge1IsLarge', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
     await expect(await browser.checkElement(await (await badge2IsLarge.element()), testFolder+'img_badge2IsLarge', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
     await expect(await browser.checkElement(await (await badge9IsLarge.element()), testFolder+'img_badge9IsLarge', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
     await expect(await browser.checkElement(await (await badge10IsLarge.element()), testFolder+'img_badge10IsLarge', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
    }
  });
});
