2012-08-28 02:36:36 +04:00
|
|
|
$ = require 'jquery'
|
|
|
|
fs = require 'fs'
|
|
|
|
|
|
|
|
describe "Window", ->
|
2013-01-08 02:26:53 +04:00
|
|
|
[rootView] = []
|
|
|
|
|
2012-08-28 02:36:36 +04:00
|
|
|
beforeEach ->
|
2012-10-24 22:34:45 +04:00
|
|
|
window.attachRootView(require.resolve('fixtures'))
|
2013-01-08 02:26:53 +04:00
|
|
|
rootView = window.rootView
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
window.shutdown()
|
2012-08-29 21:59:45 +04:00
|
|
|
atom.setRootViewStateForPath(rootView.project.getPath(), null)
|
2012-08-28 02:36:36 +04:00
|
|
|
$(window).off 'beforeunload'
|
|
|
|
|
2013-02-02 03:40:53 +04:00
|
|
|
describe "window is loaded", ->
|
2013-02-05 04:02:09 +04:00
|
|
|
it "doesn't have .is-blurred on the body tag", ->
|
2013-02-05 22:53:35 +04:00
|
|
|
$(window).trigger 'window:focus'
|
2013-02-05 04:02:09 +04:00
|
|
|
expect($("body").hasClass("is-blurred")).toBe false
|
2013-02-02 03:40:53 +04:00
|
|
|
|
2013-02-05 04:02:09 +04:00
|
|
|
it "does have .is-blurred on the window blur event", ->
|
2013-02-05 22:53:35 +04:00
|
|
|
$(window).trigger 'window:blur'
|
2013-02-05 04:02:09 +04:00
|
|
|
expect($("body").hasClass("is-blurred")).toBe true
|
2013-02-02 03:40:53 +04:00
|
|
|
|
2012-08-28 02:36:36 +04:00
|
|
|
describe ".close()", ->
|
2013-01-08 01:15:33 +04:00
|
|
|
it "is triggered by the 'core:close' event", ->
|
2012-08-28 02:36:36 +04:00
|
|
|
spyOn window, 'close'
|
2012-10-24 22:35:31 +04:00
|
|
|
$(window).trigger 'core:close'
|
2012-08-28 02:36:36 +04:00
|
|
|
expect(window.close).toHaveBeenCalled()
|
|
|
|
|
2013-01-08 01:15:33 +04:00
|
|
|
it "is triggered by the 'window:close event'", ->
|
|
|
|
spyOn window, 'close'
|
|
|
|
$(window).trigger 'window:close'
|
|
|
|
expect(window.close).toHaveBeenCalled()
|
|
|
|
|
2012-08-28 02:36:36 +04:00
|
|
|
describe ".reload()", ->
|
|
|
|
it "returns false when no buffers are modified", ->
|
|
|
|
spyOn($native, "reload")
|
|
|
|
window.reload()
|
|
|
|
expect($native.reload).toHaveBeenCalled()
|
|
|
|
|
|
|
|
it "shows alert when a modifed buffer exists", ->
|
2012-08-31 02:19:38 +04:00
|
|
|
rootView.open('sample.js')
|
2012-08-28 02:36:36 +04:00
|
|
|
rootView.getActiveEditor().insertText("hi")
|
2012-08-30 05:54:39 +04:00
|
|
|
spyOn(atom, "confirm")
|
2012-08-28 02:36:36 +04:00
|
|
|
spyOn($native, "reload")
|
|
|
|
window.reload()
|
|
|
|
expect($native.reload).not.toHaveBeenCalled()
|
2012-08-30 05:54:39 +04:00
|
|
|
expect(atom.confirm).toHaveBeenCalled()
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
describe "requireStylesheet(path)", ->
|
|
|
|
it "synchronously loads the stylesheet at the given path and installs a style tag for it in the head", ->
|
|
|
|
$('head style[id*="atom.css"]').remove()
|
|
|
|
lengthBefore = $('head style').length
|
|
|
|
requireStylesheet('atom.css')
|
|
|
|
expect($('head style').length).toBe lengthBefore + 1
|
|
|
|
|
|
|
|
styleElt = $('head style[id*="atom.css"]')
|
|
|
|
|
|
|
|
fullPath = require.resolve('atom.css')
|
|
|
|
expect(styleElt.attr('id')).toBe fullPath
|
|
|
|
expect(styleElt.text()).toBe fs.read(fullPath)
|
|
|
|
|
|
|
|
# doesn't append twice
|
|
|
|
requireStylesheet('atom.css')
|
|
|
|
expect($('head style').length).toBe lengthBefore + 1
|
|
|
|
|
2012-12-27 05:35:19 +04:00
|
|
|
describe ".disableStyleSheet(path)", ->
|
|
|
|
it "removes styling applied by given stylesheet path", ->
|
|
|
|
cssPath = require.resolve(fs.join("fixtures", "css.css"))
|
|
|
|
|
|
|
|
expect($(document.body).css('font-weight')).not.toBe("bold")
|
|
|
|
requireStylesheet(cssPath)
|
|
|
|
expect($(document.body).css('font-weight')).toBe("bold")
|
|
|
|
removeStylesheet(cssPath)
|
|
|
|
expect($(document.body).css('font-weight')).not.toBe("bold")
|
|
|
|
|
2012-08-28 02:36:36 +04:00
|
|
|
describe "before the window is unloaded", ->
|
|
|
|
it "saves the serialized state of the root view to the atom object so it can be rehydrated after reload", ->
|
2012-08-29 21:59:45 +04:00
|
|
|
expect(atom.getRootViewStateForPath(window.rootView.project.getPath())).toBeUndefined()
|
|
|
|
expectedState = JSON.parse(JSON.stringify(window.rootView.serialize())) # JSON.stringify removes keys with undefined values
|
2012-08-28 02:36:36 +04:00
|
|
|
$(window).trigger 'beforeunload'
|
2013-01-08 02:26:53 +04:00
|
|
|
expect(atom.getRootViewStateForPath(rootView.project.getPath())).toEqual expectedState
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
it "unsubscribes from all buffers", ->
|
2012-08-31 02:19:38 +04:00
|
|
|
rootView.open('sample.js')
|
2012-08-28 02:36:36 +04:00
|
|
|
editor1 = rootView.getActiveEditor()
|
|
|
|
editor2 = editor1.splitRight()
|
|
|
|
expect(window.rootView.getEditors().length).toBe 2
|
|
|
|
|
|
|
|
$(window).trigger 'beforeunload'
|
|
|
|
|
|
|
|
expect(editor1.getBuffer().subscriptionCount()).toBe 0
|
2013-01-08 02:26:53 +04:00
|
|
|
|
|
|
|
describe ".shutdown()", ->
|
|
|
|
it "only deactivates the RootView the first time it is called", ->
|
|
|
|
deactivateSpy = spyOn(rootView, "deactivate").andCallThrough()
|
|
|
|
window.shutdown()
|
|
|
|
expect(rootView.deactivate).toHaveBeenCalled()
|
|
|
|
deactivateSpy.reset()
|
|
|
|
window.shutdown()
|
|
|
|
expect(rootView.deactivate).not.toHaveBeenCalled()
|