const { expect } = require("chai")
const path = require("path")

const Application = require("spectron").Application

describe("ui", function () {
  this.timeout(10000)

  console.log(require("electron"), __dirname, path.join(__dirname, "..", "main.js"))

  beforeEach(function () {
    this.app = new Application({
      path: require("electron"),
      args: [path.join(__dirname, "..", "main.js")]
    })
    return this.app.start()
  })

  afterEach(function () {
    if (this.app && this.app.isRunning()) {
      return this.app.stop()
    }
  })

  it("shows an initial window", function() {
    return this.app.client.getWindowCount().then(function(windowCount) {
      expect(windowCount).to.equal(1)
    })
  })

  it("tab navigation works", function() {
    this.app.webContents.on("did-finish-load", function(event) {
      let client = this.app.client
      client.element(".header_nav a:nth-child(2)").click()
      let classesFirst = client.getAttribute(".content-container .content:nth-of-type(1)", "class").split(" ")
      let classesSecond = client.getAttribute(".content-container .content:nth-of-type(2)", "class").split(" ")
      expect(classesFirst).to.not.include("current")
      expect(classesFirst).to.include("left")
      expect(classesSecond).to.not.include("right")
      expect(classesSecond).to.include("current")
    })
  })
})

@@ -134,22 +134,21 @@
 function
- 
 () %7B%0A
+
   this.t
@@ -261,33 +261,32 @@
 oreEach(function
- 
 () %7B%0A    this.ap
@@ -453,17 +453,16 @@
 function
- 
 () %7B%0A   
@@ -556,10 +556,16 @@
 %22sho
+uld sho
 w
-s
  an 
@@ -743,13 +743,19 @@
 ion 
+should 
 work
-s
 %22, f
@@ -766,81 +766,20 @@
 ion(
-) %7B%0A    this.app.webContents.on(%22did-finish-load%22, function(event
+done
 ) %7B%0A    
   le
@@ -770,26 +770,24 @@
 done) %7B%0A    
-  
 let client =
@@ -802,19 +802,19 @@
 p.client
-%0A  
+;%0A%0A
     clie
@@ -869,29 +869,8 @@
 %0A   
-   let classesFirst =
  cli
@@ -945,44 +945,91 @@
 s%22).
-split(%22 %22)%0A      let classesSecond =
+then(classesFirstStr =%3E %7B%0A      var classesFirst = classesFirstStr.split(%22 %22)%0A     
  cli
@@ -1100,16 +1100,88 @@
 class%22).
+then(classesSecondStr =%3E %7B%0A        var classesSecond = classesSecondStr.
 split(%22 
@@ -1179,24 +1179,27 @@
 .split(%22 %22)%0A
+%0A  
       expect
@@ -1235,24 +1235,26 @@
 (%22current%22)%0A
+  
       expect
@@ -1285,32 +1285,34 @@
 e(%22left%22)%0A      
+  
 expect(classesSe
@@ -1337,24 +1337,26 @@
 de(%22right%22)%0A
+  
       expect
@@ -1393,23 +1393,48 @@
 rrent%22)%0A    
-%7D)
+    done()%0A      %7D)%0A    %7D)%0A
 %0A  %7D)%0A%7D)%0A

Make the tab nav test actually test something