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


describe('Sensor Module', () => {
  let loginPo: LoginPo;
  let navBarPo: NavBarPo;
  let sensorPo: SensorPo;
  let dashboardPo: DashboardPo

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

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

  it('Display sensor page', async () => {
    await dashboardPo.clickToAccordionTab();
    await browser.sleep(500);
    await sensorPo.clickById('test sensor Temp');
    expect(await element(by.className('container graph')).isPresent()).toEqual(true);
    expect(await element(by.id('view')).isPresent()).toEqual(true);
    expect(await element(by.xpath('//div[contains(text(), \'test sensor Temp\')]')).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 sensorPo.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);
  });

});
