import Routing from '../../../../pages/eui/10x/routing-10x.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'
import EuiSlideTogglePage from '../../../../pages/eui/10x/eui/eui-slide-toggle-10x.po.js'

describe('eUI - <eui-slide-toggle> Component Object ', async () => {
  let page = new EuiSlideTogglePage();
  let testFolder = './/eui-slide-toggle//';
  it('should navigate to <eui-slide-toggle> demo page', async () => {
    browser.addTestMeta({uuid:"c08c1dce-7063-460b-8526-4fc9e4d4531a", zephyrKey: "CCQA-1412", zephyrStep: "414414", reportGroups: ["eUI.10x.eui"]});
    await page.open(Routing.getEUIComponentUrl('eui-slide-toggle'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    await pgTitle.scrollIntoView();
    await expect(await $(pgTitle)).toBeDisplayed({wait:3000,message:'<eui-slide-toggle> page title is not displayed on page'});
    await expect(await $(page.appDocPageById('eui-slide-toggle'))).toExist({message:'Page Id is not existing on page'});
    await expect(pgTitle).toHaveText('eui-slide-toggle', {wait:1000,message:'Page title text is not as expected'});
    await expect(await $(page.navigationList)).toBeDisplayed({wait:3000,message:'Navigation List -> is not displayed on page'});
  });
  it('should verify the presence and number of <eui-slide-toggle> componenets on page', async () => {
    browser.addTestMeta({zephyrStep: "414415"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let slideToggleByIndex = await (await page.slideToggleByIndex(1).element());
    await expect(await $(page.sectionById(sectionId))).toBeDisplayedInViewport({message:''+ sectionId +' section -> is not visible on page'});
    await expect(slideToggleByIndex).toBeDisplayed({wait:3000,message:'slide toggle by Index "1" is not displayed on page'});
    await chaiExpect(await page.slideToggleByIndex(1).defaultComponentsCount()).equal(17, 'There should be 17 <eui-slide-toggle> components on the page.');
    if(browser.config.useWdioImageComparison) {
      await slideToggleByIndex.scrollIntoView();
      await chaiExpect(await browser.checkElement(slideToggleByIndex, testFolder+'img_slideToggleByIndex', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for slideToggleByIndex');
    }
  });
  it('should verify the component check ability', async () => {
    browser.addTestMeta({zephyrStep: "414416"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let slideToggle = page.slideToggleByIndex(1);
    await chaiExpect(await slideToggle.matSlideToggle.isSelected()).equal(false, 'isSelected should be false');
    await slideToggle.matSlideToggle.select();
    await chaiExpect(await slideToggle.matSlideToggle.isSelected()).equal(true, 'isSelected should be true');
  });
  it('should verify if component is disabled', async () => {
    browser.addTestMeta({zephyrStep: "414420"});
    let sectionId = 'disabled';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let slideToggle = page.slideToggleFromSectionByIndex(sectionId, 1);
    await chaiExpect(await slideToggle.matSlideToggle.toggleInput.isDisabled()).equal(true, '<eui-slide-toggle> from Disabled section is not disabled');
  });
  it('should verify if component is checked by default', async () => {
    browser.addTestMeta({zephyrStep: "414417"});
    let sectionId= 'checked-by-default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let slideToggle = page.slideToggleFromSectionByIndex(sectionId, 1);
    await chaiExpect(await slideToggle.matSlideToggle.isSelected()).equal(true, '<eui-slide-toggle> from Check by default section is not selected by default');
  });
  it('should verify the sizes', async () => {
    browser.addTestMeta({zephyrStep: "414418"});
    let sectionId = 'sizes';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let slideToggleSizeS = await $(page.slideToggleFromSectionByIndex(sectionId, 1).currentPath);
    let slideToggleSizeM = await $(page.slideToggleFromSectionByIndex(sectionId, 2).currentPath);
    let slideToggleSizeL = await $(page.slideToggleFromSectionByIndex(sectionId, 3).currentPath);
    let slideToggleSizeXl = await $(page.slideToggleFromSectionByIndex(sectionId, 4).currentPath);
    let slideToggleSize2Xl = await $(page.slideToggleFromSectionByIndex(sectionId, 5).currentPath);
    await expect(slideToggleSizeS).toHaveAttrContaining('class', 'eui-slide-toggle--size-s');
    await expect(slideToggleSizeM).toHaveAttrContaining('class', 'eui-slide-toggle--size-m');
    await expect(slideToggleSizeL).toHaveAttrContaining('class', 'eui-slide-toggle--size-l');
    await expect(slideToggleSizeXl).toHaveAttrContaining('class', 'eui-slide-toggle--size-xl');
    await expect(slideToggleSize2Xl).toHaveAttrContaining('class', 'eui-slide-toggle--size-2xl');
    if(browser.config.useWdioImageComparison) {
      await slideToggleSizeS.scrollIntoView();
      await chaiExpect(await browser.checkElement(slideToggleSizeS, testFolder+'img_slideToggleSizeS', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for slideToggleSizeS');
      await slideToggleSizeM.scrollIntoView();
      await chaiExpect(await browser.checkElement(slideToggleSizeM, testFolder+'img_slideToggleSizeM', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for slideToggleSizeM');
      await slideToggleSizeL.scrollIntoView();
      await chaiExpect(await browser.checkElement(slideToggleSizeL, testFolder+'img_slideToggleSizeL', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for slideToggleSizeL');
      await slideToggleSizeXl.scrollIntoView();
      await chaiExpect(await browser.checkElement(slideToggleSizeXl, testFolder+'img_slideToggleSizeXl', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for slideToggleSizeXl');
      await slideToggleSize2Xl.scrollIntoView();
      await chaiExpect(await browser.checkElement(slideToggleSize2Xl, testFolder+'img_slideToggleSize2Xl', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for slideToggleSize2Xl');
    }

  });
  it('should verify the Typeclass', async () => {
    browser.addTestMeta({zephyrStep: "414419"});
    let sectionId= 'typeclass';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let slideToggleTypeSecondary = await $(page.slideToggleFromSectionByIndex(sectionId, 1).currentPath);
    let slideToggleTypePrimary = await $(page.slideToggleFromSectionByIndex(sectionId, 2).currentPath);
    let slideToggleTypeInfo = await $(page.slideToggleFromSectionByIndex(sectionId, 3).currentPath);
    let slideToggleTypeSuccess = await $(page.slideToggleFromSectionByIndex(sectionId, 4).currentPath);
    let slideToggleTypeWarning = await $(page.slideToggleFromSectionByIndex(sectionId, 5).currentPath);
    let slideToggleTypeDanger = await $(page.slideToggleFromSectionByIndex(sectionId, 6).currentPath);
    let slideToggleTypeAccent = await $(page.slideToggleFromSectionByIndex(sectionId, 7).currentPath);
    await expect(slideToggleTypeSecondary).toHaveAttrContaining('class', 'eui-slide-toggle--secondary');
    await expect(slideToggleTypePrimary).toHaveAttrContaining('class', 'eui-slide-toggle--primary');
    await expect(slideToggleTypeInfo).toHaveAttrContaining('class', 'eui-slide-toggle--info');
    await expect(slideToggleTypeSuccess).toHaveAttrContaining('class', 'eui-slide-toggle--success');
    await expect(slideToggleTypeWarning).toHaveAttrContaining('class', 'eui-slide-toggle--warning');
    await expect(slideToggleTypeDanger).toHaveAttrContaining('class', 'eui-slide-toggle--danger');
    await expect(slideToggleTypeAccent).toHaveAttrContaining('class', 'eui-slide-toggle--accent');
    if(browser.config.useWdioImageComparison) {
      await slideToggleTypeSecondary.scrollIntoView();
      await chaiExpect(await browser.checkElement(slideToggleTypeSecondary, testFolder+'img_slideToggleTypeSecondary', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for slideToggleTypeSecondary');
      await slideToggleTypePrimary.scrollIntoView();
      await chaiExpect(await browser.checkElement(slideToggleTypePrimary, testFolder+'img_slideToggleTypePrimary', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for slideToggleTypePrimary');
      await slideToggleTypeInfo.scrollIntoView();
      await chaiExpect(await browser.checkElement(slideToggleTypeInfo, testFolder+'img_slideToggleTypeInfo', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for slideToggleTypeInfo');
      await slideToggleTypeSuccess.scrollIntoView();
      await chaiExpect(await browser.checkElement(slideToggleTypeSuccess, testFolder+'img_slideToggleTypeSuccess', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for slideToggleTypeSuccess');
      await slideToggleTypeWarning.scrollIntoView();
      await chaiExpect(await browser.checkElement(slideToggleTypeWarning, testFolder+'img_slideToggleTypeWarning', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for slideToggleTypeWarning');
      await slideToggleTypeDanger.scrollIntoView();
      await chaiExpect(await browser.checkElement(slideToggleTypeDanger, testFolder+'img_slideToggleTypeDanger', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for slideToggleTypeDanger');
      await slideToggleTypeAccent.scrollIntoView();
      await chaiExpect(await browser.checkElement(slideToggleTypeAccent, testFolder+'img_slideToggleTypeAccent', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for slideToggleTypeAccent');
    }
  });
});
