import Routing from '../../../pages/eui/14x/routing.js'
import * as CookieBannerActions from '../../../actions/cookieBanner.js'
import EuiFeedbackMessagePage from '../../../pages/eui/14x/eui-timepicker.po.js';
import BaseActions from '../../../actions/V14/base-actions.js';

describe('eUI - <eui-timepicker> Component Object ', async () => {
  let page = new EuiFeedbackMessagePage();
  let testFolder = './/v14x//eui-timepicker//'
  let pageName = 'eui-timepicker'
  it('should navigate to <eui-timepicker> demo page', async () => {
    browser.addTestMeta({uuid:"1ce60361-09da-4618-adc7-0c6b829cba60", zephyrKey: "CCQA-1820", zephyrStep: "446593", reportGroups: ["eUI.14x.eui"]});
    await page.open(Routing.getEUIComponentUrl('eui-timepicker'));
    await CookieBannerActions.cookieBanner(true);
    await BaseActions.verifyPageTitle(pageName);
    await expect(await $(page.navigationList)).toBeDisplayedInViewport ({message:'Navigation List -> is not displayed on page'});
  });
  it('should verify the presence and number of components <eui-timepicker> on page ', async () => {
    browser.addTestMeta({zephyrStep: "446594"});
    let sectionId= 'Default';
    let timepicker = page.timepickerFromSectionWithIdByIndex(sectionId, 1);
    await expect(await (await timepicker.element())).toBeDisplayed({wait:2000, message:'Timepicker in default section -> is not displayed on page'});
    await chaiExpect(await page.euiTimepickerCo.defaultComponentsCount()).equal(6, 'There should be 6 <eui-timepicker> components on the page.');

    if(browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(await (await page.euiTimepickerCo.element()), testFolder + 'img_defaultTimepicker',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_defaultTimepicker');
    }
    await chaiExpect(await timepicker.hasSeconds()).equal(false, "Timepicker should not have seconds");
  });
  it('should verify the the presence <eui-timepicker> with seconds', async () => {
    browser.addTestMeta({zephyrStep: "446595"});
    let sectionId = 'with-seconds';
    await BaseActions.verifySection(sectionId, pageName);
    let timepicker = page.timepickerFromSectionWithIdByIndex(sectionId, 1);

    await expect(await (await timepicker.element())).toBeDisplayed({wait:2000, message:'Timepicker in "' + sectionId + '" section -> is not displayed on page'});
    await expect(await $(timepicker.hourMinuteSpacer)).toBeDisplayed({wait:2000, message:'Hour - minute separator -> is not displayed on page'});
    await expect(await $(timepicker.minutesSecondsSpacer)).toBeDisplayed({wait:2000, message:'Minute - seconds separator -> is not displayed on page'});
    if(browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(await (await timepicker.element()), testFolder + 'img_withSecondsTimepicker',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_withSecondsTimepicker');
    }
  });
  it('should verify the the functionality of <eui-timepicker>', async () => {
    browser.addTestMeta({zephyrStep: "446596"});
    let sectionId = 'Default';
    await BaseActions.verifySection(sectionId, pageName);
    let timepicker = page.timepickerFromSectionWithIdByIndex(sectionId, 1);
    await chaiExpect(await timepicker.hasSeconds()).equal(false, 'Timepicker should not have seconds');
    await chaiExpect(await timepicker.isDatetimepicker()).equal(false, 'Timepicker should not be DateTime picker')

    let hourBottomChevron = await $(timepicker.hourBottomChevronIcon);
    await (hourBottomChevron).click();
    await chaiExpect(await (await $(timepicker.hourInput)).getValue()).equal('23', 'Timepicker hour input should have value 23.');

    await (await $(timepicker.minutesBottomChevronIcon)).click();
    await chaiExpect(await (await $(timepicker.minutesInput)).getValue()).equal('59', 'Timepicker minute input should have value 59.');
  });
  it('should verify the the functionality of <eui-timepicker> with seconds', async () => {
    browser.addTestMeta({zephyrStep: "446597"});
    let sectionId = 'with-seconds';
    await BaseActions.verifySection(sectionId, pageName);
    let timepicker = page.timepickerFromSectionWithIdByIndex(sectionId, 1);

    await chaiExpect(await timepicker.hasSeconds()).equal(true, 'Timepicker should have seconds');
    await chaiExpect(await timepicker.isDatetimepicker()).equal(false, 'Timepicker should not be DateTime picker')

    await (await $(timepicker.hourTopChevronIcon)).click();
    await chaiExpect(await (await $(timepicker.hourInput)).getValue()).equal('01', 'Timepicker hour input should have value 01.');

    await (await $(timepicker.minutesTopChevronIcon)).click();
    await chaiExpect(await (await $(timepicker.minutesInput)).getValue()).equal('01', 'Timepicker minute input should have value 01.');

    await (await $(timepicker.secondsTopChevronIcon)).click();
    await chaiExpect(await (await $(timepicker.secondsInput)).getValue()).equal('01', 'Timepicker minute input should have value 01.');
  });
  it('should verify the the functionality of <eui-timepicker> reactive form', async () => {
    browser.addTestMeta({zephyrStep: "446598"});
    let sectionId = 'reactive-forms';
    await BaseActions.verifySection(sectionId, pageName);
    let timepicker = page.timepickerFromSectionWithIdByIndex(sectionId, 2);

    await chaiExpect(await timepicker.hasSeconds()).equal(true, 'Timepicker should have seconds');
    await chaiExpect(await timepicker.isDatetimepicker()).equal(false, 'Timepicker should not be DateTime picker')

    await (await $(timepicker.hourBottomChevronIcon)).click();
    await chaiExpect(await (await $(timepicker.hourInput)).getValue()).equal('10', 'Timepicker hour input should have value 10.');

    await (await $(timepicker.minutesBottomChevronIcon)).click();
    await chaiExpect(await (await $(timepicker.minutesInput)).getValue()).equal('29', 'Timepicker minute input should have value 29.');

    await (await $(timepicker.secondsBottomChevronIcon)).click();
    await chaiExpect(await (await $(timepicker.secondsInput)).getValue()).equal('44', 'Timepicker minute input should have value 44.');

    if(browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(await (await timepicker.element()), testFolder + 'img_reactiveFormsWithSecondsTimepicker',
      {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for img_reactiveFormsWithSecondsTimepicker');
    }
   await expect(await $(timepicker.hourMinuteSpacer)).toBeDisplayed({wait:2000, message:'Hour - minute separator -> is not displayed on page'});
   await expect(await $(timepicker.minutesSecondsSpacer)).toBeDisplayed({wait:2000, message:'Minute - seconds separator -> is not displayed on page'});
  });
});
