import { browser, ExpectedConditions as ec } from 'protractor';
import { NavBarPage, SignInPage } from '../../page-objects/jhi-page-objects';

import { StatisticsComponentsPage, StatisticsUpdatePage } from './statistics.page-object';

const expect = chai.expect;

describe('Statistics e2e test', () => {
  let navBarPage: NavBarPage;
  let signInPage: SignInPage;
  let statisticsComponentsPage: StatisticsComponentsPage;
  let statisticsUpdatePage: StatisticsUpdatePage;
  const username = process.env.E2E_USERNAME ?? 'admin';
  const password = process.env.E2E_PASSWORD ?? 'search@admin';

  before(async () => {
    await browser.get('/');
    await browser.sleep(2000);
    navBarPage = new NavBarPage();
    signInPage = await navBarPage.getSignInPage();
    await signInPage.autoSignInUsing(username, password);
    await browser.wait(ec.visibilityOf(navBarPage.entityMenu), 5000);
  });

  it('should load Statistics', async () => {
    await navBarPage.goToEntity('statistics');
    statisticsComponentsPage = new StatisticsComponentsPage();
    await browser.wait(ec.visibilityOf(statisticsComponentsPage.title), 5000);
    expect(await statisticsComponentsPage.getTitle()).to.eq('gitsearchApp.statistics.home.title');
    await browser.wait(ec.or(ec.visibilityOf(statisticsComponentsPage.entities), ec.visibilityOf(statisticsComponentsPage.noResult)), 1000);
  });

  it('should load create Statistics page', async () => {
    await statisticsComponentsPage.clickOnCreateButton();
    statisticsUpdatePage = new StatisticsUpdatePage();
    expect(await statisticsUpdatePage.getPageTitle()).to.eq('gitsearchApp.statistics.home.createOrEditLabel');
    await statisticsUpdatePage.cancel();
  });

  after(async () => {
    await navBarPage.autoSignOut();
  });
});