import { expect } from 'chai';
import rewiremock from 'rewiremock';

import 'mocha';
import { IApplicationContext } from './main/test/i-application-context';
import { createApplication } from './main/test/spectron-util';

rewiremock.disable();

describe('Application @spectron', function () {
  this.timeout(20000);

  before(function (this: IApplicationContext) {
    this.app = createApplication();
    return this.app.start();
  });

  after(function (this: IApplicationContext) {
    if (this.app && this.app.isRunning()) {
      return this.app.stop();
    }
  });

  it('shows an initial window', function (this: IApplicationContext) {
    if (!this.app) {
      throw Error('this.app is falsy');
    }
    return this.app.client.getWindowCount().then((count: number) => {
      expect(count).to.be.gte(1);
    });
  });
});
