Don't add to the same window to the atom.windows array twice

This commit is contained in:
Nathan Sobo
2012-03-15 16:10:55 -06:00
parent 60056e57fb
commit 6bdba313d1
2 changed files with 26 additions and 13 deletions

View File

@@ -2,13 +2,20 @@ App = require 'app'
fs = require 'fs'
describe "App", ->
afterEach ->
closeAllWindows = ->
window.close() for window in atom.windows
waitsFor "there to be no windows", ->
atom.windows.length == 0
describe "open", ->
describe "when opening a filePath", ->
describe ".open(path)", ->
beforeEach ->
closeAllWindows()
afterEach ->
closeAllWindows()
describe "when opening a file", ->
it "displays it in a new window with the contents of the file loaded", ->
filePath = null
@@ -18,10 +25,24 @@ describe "App", ->
atom.open filePath
waitsFor "window to open", ->
atom.windows.length > 0
atom.windows.length > 0
runs ->
expect(atom.windows.length).toBe 1
newWindow = atom.windows[0]
expect(newWindow.rootView.editor.buffer.url).toEqual filePath
expect(newWindow.rootView.editor.buffer.getText()).toEqual fs.read(filePath)
describe ".windowOpened(window)", ->
app = null
beforeEach ->
app = new App
it "adds the window to the windows array if it isn't already present", ->
app.windowOpened window
app.windowOpened window
expect(app.windows).toEqual [window]

View File

@@ -25,16 +25,8 @@ class App
quit: ->
$native.terminate null
windowIdCounter: 1
windowOpened: (window) ->
id = @windowIdCounter++
console.log "window opened! #{id}"
window.id = id
@windows.push window
@windows.push(window) unless _.contains(@windows, window)
windowClosed: (window) ->
console.log "windowClosed #{window.id}"
console.log "windows length before #{@windows.length}"
_.remove(@windows, window)
console.log "windows length after #{@windows.length}"