let Application = require('spectron').Application;
let assert = require('chai').assert;
let expect = require('chai').expect;
const path = require('path');
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');

let electronPath = path.join(__dirname, '..', 'node_modules', '.bin', 'electron');
let appPath = path.join(__dirname, '..');

global.before(() => {
  chai.should();
  chai.use(chaiAsPromised);
});

describe('App starts and has correct title and buttons', () => {

  let app = null;

  beforeEach(() => {
    app = new Application({ path: electronPath, args: [appPath]});
    return app.start();
  });

  afterEach(() => {
    return app.stop();
  });

  it('opens a window', () => {
    return app.client.waitUntilWindowLoaded()
      .getWindowCount().should.eventually.equal(1);
  });

  it('tests the title', () => {
    return app.client.waitUntilWindowLoaded()
      .getTitle().should.eventually.equal('&#129472; Good Food');
  });

  it('tests the search button is disabled on page load', () => {
    $('#header').should.have.prop('disabled');
    expect($('body')).to.have.prop('disabled', false);
    expect($('body')).to.have.prop('value').match(/bar/);
  });
});

  // it('tests the Open File button text is not disabled', () => {
  //   return app.client.waitUntilWindowLoaded().getText('#open-file')
  //   .then(function (buttonText) {
  //     assert(buttonText === 'Open File');
  //   });
  // });



describe('Test accessibility', () => {
  let app = null;

  beforeEach(() => {
    app = new Application({ path: electronPath, args: [appPath]});
    return app.start();
  });

  afterEach(() => {
    return app.stop;
  });

  it('console log audit errors', () => {
    app.client.auditAccessibility().then((audit) => {
      if (audit.failed) {
        console.error(audit.message);
      }
    });
  });
});

@@ -44,16 +44,19 @@
 cation;%0A
+// 
 let asse
@@ -815,32 +815,35 @@
 ual(1);%0A  %7D);%0A%0A 
+ //
  it('tests the t
@@ -850,32 +850,35 @@
 itle', () =%3E %7B%0A 
+ //
    return app.cl
@@ -899,32 +899,35 @@
 WindowLoaded()%0A 
+ //
      .getTitle()
@@ -972,24 +972,27 @@
 od Food');%0A 
+ //
  %7D);%0A%0A  it('
@@ -1061,15 +1061,22 @@
  $('
-#header
+.search-button
 ').s
@@ -1110,36 +1110,46 @@
 ;%0A    expect($('
-body
+.search-button
 ')).to.have.prop
@@ -1165,71 +1165,12 @@
 d', 
-false);%0A    expect($('body')).to.have.prop('value').match(/bar/
+true
 );%0A 
@@ -1638,16 +1638,18 @@
 app.stop
+()
 ;%0A  %7D);%0A

TEst not recognizing $ for jquery. Pulling master and merge since MJ has jquery working on the app end.