import Routing from '../../../../pages/eui/10x/routing-10x.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'
import AtagPage from '../../../../pages/eui/10x/ux/ux-a-tag.po.js.10x.js'

describe('eUI - <ux-a-tag> Component Object @CCQA-704', async() => {
  let tagPage = new AtagPage();
  let testFolder = './/ux//ux-a-tag//';
  it('should navigate to <ux-a-tag> component @354157', async() => {
    await tagPage.open(Routing.getUxComponentUrl('ux-a-tag'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(tagPage.pageTitle);
    let appDocPageId = await $(tagPage.appDocPageById('ux-a-tag'));
    let navigationList = await $(tagPage.navigationList);
    await pgTitle.scrollIntoView();
    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-a-tag> page title is not visible on page'});
    await expect(await pgTitle.getText()).toBe('ux-a-tag', '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 @354158', async() => {
    let defaultTagDiv = await $(tagPage.tagFromSectionById('Default').tagDataDiv);
    let tag1Div = await $(tagPage.tagByIndex(1).tagDataDiv);
    let tagDefault = await $(tagPage.tagByTextContains('default').tagLabel);
    let tagDefaultAnd1Label = await $(tagPage.tagByTextEqualsAndIndex('default', 1).tagLabel);

    await expect(defaultTagDiv).toBeDisplayedInViewport('<Default> section -> is not visible on page');
    await expect(tag1Div).toBeDisplayedInViewport('Tag by index "1" is not visible on page');
    await expect(tagDefault).toBeDisplayedInViewport('Tag by text " default " is not visible on page');
    await expect(tagDefaultAnd1Label).toBeDisplayedInViewport('Tag by text "default" and index 1 is not visible on page');
    await chaiExpect(await tagPage.tagByIndex(1).defaultComponentsCount()).equal(24, 'There should be 24 <ux-a-tag> components on the page.')

    // image compare
    if(browser.config.useWdioImageComparison) {
     await chaiExpect(await browser.checkElement(defaultTagDiv, testFolder+'img_defaultTagDiv', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for defaultTagDiv');
     await chaiExpect(await browser.checkElement(tag1Div, testFolder+'img_tag1Div', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for tag1Div');
     await chaiExpect(await browser.checkElement(tagDefault, testFolder+'img_tagDefault', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for tagDefault');
     await chaiExpect(await browser.checkElement(tagDefaultAnd1Label, testFolder+'img_tagDefaultAnd1Label', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for tagDefaultAnd1Label');
    }
  });

  it('should verify the tag CO properties: tagLabel, tagSubLabel, label, subLabel, typeClass, tabindex @354159 ', async() => {
    let sectionId= 'subLabel';
    let scrollIntoSection = await $(tagPage.tagFromSectionById(sectionId).tagDataDiv);
    await scrollIntoSection.scrollIntoView();

    let tag1 = tagPage.tagFromSectionWithIdByIndex(sectionId,1);
    let tag1Label = await $(tag1.tagLabel);
    let tag1SubLabel = await $(tag1.tagSubLabel);
    await expect(tag1Label).toBeDisplayedInViewport('Tag with index 1 from subLabel section is not visible on page');
    await expect(await tag1Label.getText()).toContain('default with counter');
    await expect(await tag1SubLabel.getText()).toContain('00');
    await expect(await tag1.label()).toContain('default with counter');
    await expect(await tag1.sublabel()).toContain('00');
    await expect(await tag1.tabindex()).toContain('0');

    // image compare
    if(browser.config.useWdioImageComparison) {
     await chaiExpect(await browser.checkElement(tag1Label, testFolder+'img_tag1Label', {hideElements: [await $('//eui-app-toolbar')]})).equal(0);
     await chaiExpect(await browser.checkElement(tag1SubLabel, testFolder+'img_tag1SubLabel', {hideElements: [await $('//eui-app-toolbar')]})).equal(0);
    }

    sectionId= 'label-typeClass';
    scrollIntoSection = await $(tagPage.tagFromSectionById(sectionId).tagDataDiv);
    await scrollIntoSection.scrollIntoView();

    await expect(await tagPage.tagFromSectionWithIdByIndex(sectionId,1).label()).toContain('primary');
    await expect(await tagPage.tagFromSectionWithIdByIndex(sectionId,1).typeClass()).toContain('primary');
    await expect(await tagPage.tagFromSectionWithIdByIndex(sectionId,2).typeClass()).toContain('info');
    await expect(await tagPage.tagFromSectionWithIdByIndex(sectionId,3).typeClass()).toContain('success');
    await expect(await tagPage.tagFromSectionWithIdByIndex(sectionId,4).typeClass()).toContain('warning');
    await expect(await tagPage.tagFromSectionWithIdByIndex(sectionId,5).typeClass()).toContain('danger');

    // image compare
    if(browser.config.useWdioImageComparison) {
      let tag2DataDiv = await $(tagPage.tagFromSectionWithIdByIndex(sectionId,2).tagDataDiv);
      let tag3DataDiv = await $(tagPage.tagFromSectionWithIdByIndex(sectionId,3).tagDataDiv);
      let tag4DataDiv = await $(tagPage.tagFromSectionWithIdByIndex(sectionId,4).tagDataDiv);
      let tag5DataDiv = await $(tagPage.tagFromSectionWithIdByIndex(sectionId,5).tagDataDiv);
      await expect(await browser.checkElement(tag2DataDiv, testFolder+'img_tag2DataDiv', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
      await expect(await browser.checkElement(tag3DataDiv, testFolder+'img_tag3DataDiv', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
      await expect(await browser.checkElement(tag4DataDiv, testFolder+'img_tag4DataDiv', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
      await expect(await browser.checkElement(tag5DataDiv, testFolder+'img_tag5DataDiv', {hideElements: [await $('//eui-app-toolbar')]})).toBe(0);
    }
  });

  it('should verify the tag CO properties: isRounded, isSmall @354160', async() => {
    let sectionId= 'isRounded';
    let scrollIntoSection = await $(tagPage.tagFromSectionById(sectionId).tagDataDiv);
    await scrollIntoSection.scrollIntoView();

    let tag1Rounded = tagPage.tagFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(tag1Rounded.tagDataDiv)).toBeDisplayedInViewport('Tag with index 1 from isRounded section is not visible on page');
    await expect(await tag1Rounded.isRounded()).toBe(true, 'isRounded should be true');

    sectionId= 'isSmall';
    scrollIntoSection = await $(tagPage.tagFromSectionById(sectionId).tagDataDiv);
    await scrollIntoSection.scrollIntoView();

    let tag1Small = tagPage.tagFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(tag1Small.tagDataDiv)).toBeDisplayedInViewport('Tag with index 1 from isSmall section is not visible on page');
    await expect(await tag1Small.isSmall()).toBe(true, 'isSmall should be true');

    // image compare
    if(browser.config.useWdioImageComparison) {
     await chaiExpect(await browser.checkElement(await $(tag1Rounded.tagDataDiv), testFolder+'img_tag1IsRounded', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for tag1IsRounded');
     await chaiExpect(await browser.checkElement(await $(tag1Small.tagDataDiv), testFolder+'img_tag1Small', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_tag1Small');
    }
  });
});
