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

describe('eUI - <ux-switch> Component Object', async () => {
  let switchPage = new SwitchPage();
  it('should navigate to <ux-switch> component', async () => {
    browser.addTestMeta({uuid:"251918b0-71f9-11eb-9439-0242ac130002", zephyrKey: "CCQA-789", zephyrStep: "368206", reportGroups: ["eUI.10x.ux"]});
    await switchPage.open(Routing.getUxComponentUrl('ux-switch'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(switchPage.pageTitle);
    let appDocPageId = await $(switchPage.appDocPageById('ux-switch'));
    let navigationList = await $(switchPage.navigationList);
    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-switch> page title is not visible on page'});
    await expect(pgTitle).toHaveText('ux-switch', {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 and number of component objects <ux-switch> on page', async () => {
    browser.addTestMeta({zephyrStep: "368207"});
    // identify ux-switch as Default section
    await expect(await $(switchPage.sectionById('Default'))).toBeDisplayed({wait: 3000, message:'<Default> section -> is not displayed on page'});

    let switchByIndex = switchPage.switchByIndex(1);
    await expect(await (await switchByIndex.element())).toBeDisplayed({wait: 3000, message:'Switch 1 not displayed on page'});
    await expect(await (await $$(switchByIndex.byDefault().currentPath)).length).toBe(11);
  });
  it('should verify the switch CO method: isChecked', async () => {
    browser.addTestMeta({zephyrStep: "368208"});
    let switchIsCheckedTrue = switchPage.switchFromSectionWithIdByIndex('isChecked', '1');
    await expect(await switchIsCheckedTrue.isChecked()).toBe(true);
    let switchIsCheckedFalse = switchPage.switchFromSectionWithIdByIndex('Default', '1');
    await expect(await switchIsCheckedFalse.isChecked()).toBe(false);
  });
  it('should verify the switch CO method: isDisabled', async () => {
    browser.addTestMeta({zephyrStep: "368209"});
    let switchIsDisabledTrue = switchPage.switchFromSectionWithIdByIndex('isDisabled', '1');
    await expect(await switchIsDisabledTrue.isDisabled()).toBe(true);
    let switchIsDisabledFalse = switchPage.switchFromSectionWithIdByIndex('isChecked', '1');
    await expect(await switchIsDisabledFalse.isDisabled()).toBe(false);
  });
  it('should verify the switch CO method: isSmall', async () => {
    browser.addTestMeta({zephyrStep: "368210"});
    let switchIsSmallTrue = switchPage.switchFromSectionWithIdByIndex('sizes', '1');
    await expect(await switchIsSmallTrue.isSmall()).toBe(true);
    let switchIsSmallFalse = switchPage.switchFromSectionWithIdByIndex('sizes', '3');
    await expect(await switchIsSmallFalse.isSmall()).toBe(false);
  });
  it('should verify the switch CO method: isLarge', async () => {
    browser.addTestMeta({zephyrStep: "368211"});
    let switchIsLargeTrue = switchPage.switchFromSectionWithIdByIndex('sizes', '3');
    await expect(await switchIsLargeTrue.isLarge()).toBe(true);
    let switchIsLargeFalse = switchPage.switchFromSectionWithIdByIndex('sizes', '1');
    await expect(await switchIsLargeFalse.isLarge()).toBe(false);
  });
  it('should verify the switch CO change state of switch', async () => {
    browser.addTestMeta({zephyrStep: "368212"});
    let switch1 = switchPage.switchFromSectionWithIdByIndex('isChecked', '1');
    await expect(await switch1.isChecked()).toBe(true);
    await (await $(switch1.currentPath)).click();
    await expect(await switch1.isChecked()).toBe(false);
    await (await $(switch1.currentPath)).click();
    await expect(await switch1.isChecked()).toBe(true);
  });
});
