import {LoginPo} from '../login/login.po';
import {DashboardPo} from '../dashboard/dashboard.po';
import {NavBarPo} from '../nav-bar/nav-bar.po';
import {browser, by, element} from 'protractor';
import {UnitPo} from './unit.po';


describe('Unit Module', () => {
  let loginPo: LoginPo;
  let navBarPo: NavBarPo;
  let unitPo: UnitPo;
  let dashboardPo: DashboardPo

  beforeEach(async () => {
    unitPo = new UnitPo();
    loginPo = new LoginPo();
    navBarPo = new NavBarPo();
    dashboardPo = new DashboardPo();
    await loginPo.navigateTo();
    await loginPo.processForm();
  });

  afterEach(async () => {
    await loginPo.logout();
  });

  it('Display Unit page', async () => {
    await unitPo.clickById('test insert unit4');
    expect(await element(by.className('container graph')).isPresent()).toEqual(true);
    expect(await element(by.id('vega_container_10300')).isPresent()).toEqual(true);
    expect(await element(by.id('vega_container_12300')).isPresent()).toEqual(true);
    expect(await element(by.xpath('//div[contains(text(), \'test insert unit4\')]')).isPresent()).toEqual(true);
    expect(await element(by.xpath('//div[contains(@class, \'p-listbox-list-wrapper\')]')).isPresent()).toEqual(false);
    expect(await element(by.xpath('//span[contains(text(), \'Get data\')]')).isPresent()).toEqual(false);
    await unitPo.setDateInXpath('//*[contains(@id, \'from\')]//input');
    expect(await element(by.xpath('//div[contains(@class, \'p-listbox-list-wrapper\')]')).isPresent()).toEqual(true);
    expect(await element(by.xpath('//span[contains(text(), \'Get data\')]')).isPresent()).toEqual(true);
    expect(await element(by.id('1030001')).isPresent()).toEqual(true);
    expect(await element(by.id('1230001')).isPresent()).toEqual(true);
    await browser.sleep(500);
    await unitPo.selectSensor('1030001');
    expect(await element(by.xpath('//input[contains(@id, \'1030001\')]')).isSelected()).toEqual(true);
    await unitPo.selectSensor('1230001');
    await browser.sleep(500);
    expect(await element(by.xpath('//input[contains(@id, \'1230001\')]')).isSelected()).toEqual(true);
  });

});
