mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Don't add to the same window to the atom.windows array twice
This commit is contained in:
@@ -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]
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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}"
|
||||
|
||||
Reference in New Issue
Block a user