import Routing from '../../../pages/eui/14x/routing.js'
import * as CookieBannerActions from '../../../actions/cookieBanner.js'
import EuiInputNumberPage from '../../../pages/eui/14x/eui-input-number.po.js'
import { elementAttributeContains } from '../../../core/utils.js';
import BaseActions from '../../../actions/V14/base-actions.js';

describe('eUI - <eui-input-number> Component Object ', async () => {
  let page = new EuiInputNumberPage();
  let testFolder = './/v14x//eui-input-number//';
  let pageName = 'euiInputNumber'
  it('should navigate to <eui-input-number> demo page', async () => {
    browser.addTestMeta({ uuid: "136b8db4-80cf-4071-be4e-3e4e30996672", zephyrKey: "CCQA-2004", zephyrStep: "480306", reportGroups: ["eUI.14x.eui"] });
    await page.open(Routing.getEUIDirectivesUrl('eui-input-number'));
    await CookieBannerActions.cookieBanner(true);
    await BaseActions.verifyPageTitle(pageName);
    await expect(await $(page.navigationList)).toBeDisplayedInViewport({ message: 'Navigation List -> is not displayed on page' });
    await page.selectLocalLanguage('en');
  });
  it('should verify the presence and number of component objects <eui-input-number> on page ', async () => {
    browser.addTestMeta({ zephyrStep: "480307" });
    let sectionId = 'Default';
    await BaseActions.verifySection(sectionId, pageName);
    let index = 2;
    let inputNumberByIndex1 = await (await page.inputNumberByIndex(index).element());
    await expect(inputNumberByIndex1).toExist({ message: 'inputNumber by index ' + index + ' is not existing on page' });
    await chaiExpect(await page.inputNumberByIndex(index).defaultComponentsCount()).equal(28, 'There should be 18 <eui-input-number> components on the page.');

    if (browser.config.useWdioImageComparison) {
      await inputNumberByIndex1.scrollIntoView();
      await chaiExpect(await browser.checkElement(inputNumberByIndex1, testFolder + 'img_inputNumberByIndex1', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for inputNumberByIndex1');
    }
  });
  it('should verify the <eui-input-number> read-only ', async () => {
    browser.addTestMeta({ zephyrStep: "480308" });
    let sectionId = 'readonly';
    await BaseActions.verifySection(sectionId, pageName);
    let inputNumberReadOnly = page.inputNumberFromSectionByIndex(sectionId, 1);
    await expect(await (await inputNumberReadOnly.element())).toExist({ message: 'inputNumberReadOnly is not existing on page' });
    await chaiExpect(await elementAttributeContains(inputNumberReadOnly.currentPath, 'readonly', 'true')).equal(true, 'inputNumberReadOnly is not read-only');
    if (browser.config.useWdioImageComparison) {
      await (await (await inputNumberReadOnly.element())).scrollIntoView();
      await chaiExpect(await browser.checkElement(await (await inputNumberReadOnly.element()), testFolder + 'img_inputNumberReadOnly', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for inputNumberReadOnly');
    }
  });

  it('should verify the <eui-input-number> disabled ', async () => {
    browser.addTestMeta({ zephyrStep: "480309" });
    let sectionId = 'disabled';
    await BaseActions.verifySection(sectionId, pageName);
    let inputNumberDisabled = await (await page.inputNumberFromSectionByIndex(sectionId, 1).element());

    await expect(inputNumberDisabled).toExist({ message: 'inputNumberDisabled is not existing on page' });
    await expect(inputNumberDisabled).toHaveAttrContaining('class', 'disabled');

    if (browser.config.useWdioImageComparison) {
      await inputNumberDisabled.scrollIntoView();
      await chaiExpect(await browser.checkElement(inputNumberDisabled, testFolder + 'img_inputNumberDisabled', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for inputNumberDisabled');
    }
  });
  it('should verify the <eui-input-number> invalid ', async () => {
    browser.addTestMeta({ zephyrStep: "480310" });
    let sectionId = 'invalid';
    await BaseActions.verifySection(sectionId, pageName);

    let inputNumberInvalid = await (await page.inputNumberFromSectionByIndex(sectionId, 1).element());

    await expect(inputNumberInvalid).toExist({ message: 'inputNumberInvalid is not existing on page' });
    await chaiExpect(await page.inputNumberFromSectionByIndex(sectionId, 1).isInvalid()).equal(true, 'inputNumberInvalid is not invalid');
    if (browser.config.useWdioImageComparison) {
      await chaiExpect(await browser.checkElement(inputNumberInvalid, testFolder + 'img_inputNumberInvalid', { hideElements: [await $('//eui-app-toolbar')] })).equal(0, 'Image comparison failed for inputNumberInvalid');
    }
  });

});
