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

describe('eUI - <ux-timepicker> Component Object', async () => {
  let page = new CoUxTimepicker();
  it('should navigate to <ux-timepicker> component', async () => {
    browser.addTestMeta({uuid:"968b6f2c-b95a-11eb-8529-0242ac130003", zephyrKey: "CCQA-792", zephyrStep: "368379", reportGroups: ["eUI.10x.ux"]});
    await page.open(Routing.getUxComponentUrl('ux-timepicker'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    let appDocPageId = await $(page.appDocPageById('ux-timepicker'));
    let navigationList = await $(page.navigationList);
    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-timepicker> page title is not visible on page'});
    await expect(pgTitle).toHaveText('ux-timepicker', {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 component object in page', async () => {
    browser.addTestMeta({zephyrStep: "368380"});
    await expect(await $(page.timepickerFromSectionById('Default').timepicker)).toBeDisplayedInViewport({message: '<Default> section -> is not visible on page'});
    let timepicker = page.timepickerByIndex(1);
    await expect(await $(timepicker.timepicker)). toBeDisplayedInViewport({message: 'Timepicker by index "1" is not visible on page'});
    await expect(await timepicker.defaultComponentsCount()).toBe(1,'There should be 1 <ux-timepicker> components on the page.');
  });
  it('should verify the <ux-timepicker> CO elements and methods', async () => {
    browser.addTestMeta({zephyrStep: "368381"});
    await expect(await $(page.timepickerFromSectionById('Default').timepicker)).toBeDisplayedInViewport({message: '<Default> section -> is not visible on page'});
    let timepicker = page.timepickerByIndex(1);
    await expect(await $(timepicker.hourInputContainer)).toBeDisplayedInViewport({message: 'hourInputContainer is not visible on page'});
    await expect(await $(timepicker.hourChevron)).toBeDisplayedInViewport({message: 'hourChevron is not visible on page'});
    await expect(await $(timepicker.hourIconChevronUp)).toBeDisplayedInViewport({message: 'hourIconChevronUp is not visible on page'});
    await expect(await $(timepicker.hourInput)).toBeDisplayedInViewport({message: 'hourInput is not visible on page'});
    await expect(await $(timepicker.hourIconChevronDown)).toBeDisplayedInViewport({message: 'hourIconChevronDown is not visible on page'});
    await expect(await $(timepicker.spacer)).toBeDisplayedInViewport({message: 'spacer is not visible on page'});
    await expect(await $(timepicker.minuteInputContainer)).toBeDisplayedInViewport({message: 'minuteInputContainer is not visible on page'});
    await expect(await $(timepicker.minuteChevron)).toBeDisplayedInViewport({message: 'minuteChevron is not visible on page'});
    await expect(await $(timepicker.minuteIconChevronUp)).toBeDisplayedInViewport({message: 'minuteIconChevronUp is not visible on page'});
    await expect(await $(timepicker.minuteInput)).toBeDisplayedInViewport({message: 'minuteInput is not visible on page'});
    await expect(await $(timepicker.minuteIconChevronDown)).toBeDisplayedInViewport({message: 'minuteIconChevronDown is not visible on page'});
    await expect(await timepicker.isDatetimepicker()).toBe(false, 'isDatetimepicker timepicker should be false' );
  });
  it('should verify default hour and minute', async () => {
    browser.addTestMeta({zephyrStep: "368382"});
    await expect(await $(page.timepickerFromSectionById('Default').timepicker)).toBeDisplayedInViewport({message: '<Default> section -> is not visible on page'});
    let timepicker = page.timepickerByIndex(1);
    await expect(await $(timepicker.hourInput)).toHaveValue('00',{message: 'hourInput is not 00'});
    await expect(await $(timepicker.minuteInput)).toHaveValue('00',{message: 'minuteInput is not 00'});
  });
  it('should set a specific hour and verify the results', async () => {
    browser.addTestMeta({zephyrStep: "368383"});
    await expect(await $(page.timepickerFromSectionById('Default').timepicker)).toBeDisplayedInViewport({message: '<Default> section -> is not visible on page'});
    let timepicker = page.timepickerByIndex(1);

    await (await $(timepicker.hourIconChevronUp)).click();
    await (await $(timepicker.hourIconChevronUp)).click();
    await (await $(timepicker.hourIconChevronUp)).click();

    await expect(await $(timepicker.hourInput)).toHaveValue('03',{message: 'hourInput is not 03'});
    await expect(await $(timepicker.minuteInput)).toHaveValue('00',{message: 'minuteInput is not 00'});

    await (await $(timepicker.minuteIconChevronDown)).click();
    await (await $(timepicker.minuteIconChevronDown)).click();
    await (await $(timepicker.minuteIconChevronDown)).click();

    await expect(await $(timepicker.hourInput)).toHaveValue('02',{message: 'hourInput is not 02'});
    await expect(await $(timepicker.minuteInput)).toHaveValue('57',{message: 'minuteInput is not 57'});
  });
  it('should set a specific hour and verify the results test 2', async () => {
    browser.addTestMeta({zephyrStep: "368384"});
    await expect(await $(page.timepickerFromSectionById('Default').timepicker)).toBeDisplayedInViewport({message: '<Default> section -> is not visible on page'});
    let timepicker = page.timepickerByIndex(1);

    await (await $(timepicker.hourIconChevronDown)).click();

    await expect(await $(timepicker.hourInput)).toHaveValue('01',{message: 'hourInput is not 01'});
    await expect(await $(timepicker.minuteInput)).toHaveValue('57',{message: 'minuteInput is not 57'});

    await (await $(timepicker.minuteIconChevronUp)).click();
    await (await $(timepicker.minuteIconChevronUp)).click();

    await expect(await $(timepicker.hourInput)).toHaveValue('01',{message: 'hourInput is not 01'});
    await expect(await $(timepicker.minuteInput)).toHaveValue('59',{message: 'minuteInput is not 59'});

    await (await $(timepicker.minuteIconChevronUp)).click();
    await (await $(timepicker.minuteIconChevronUp)).click();

    await expect(await $(timepicker.hourInput)).toHaveValue('02',{message: 'hourInput is not 02'});
    await expect(await $(timepicker.minuteInput)).toHaveValue('01',{message: 'minuteInput is not 01'});
  });
});
