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 ->
|
2013-02-20 00:12:29 +04:00
|
|
|
window.handleWindowEvents()
|
|
|
|
spyOn(atom, 'getPathToOpen').andReturn(project.getPath())
|
|
|
|
window.buildProjectAndRootView()
|
2013-01-08 02:26:53 +04:00
|
|
|
rootView = window.rootView
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
afterEach ->
|
2013-02-20 22:02:16 +04:00
|
|
|
window.shutdown()
|
2013-02-20 02:15:11 +04:00
|
|
|
atom.setRootViewStateForPath(project.getPath(), null)
|
2012-08-28 02:36:36 +04:00
|
|
|
$(window).off 'beforeunload'
|
|
|
|
|
2013-02-06 00:03:56 +04:00
|
|
|
describe "when the window is loaded", ->
|
2013-02-05 04:02:09 +04:00
|
|
|
it "doesn't have .is-blurred on the body tag", ->
|
2013-02-06 00:03:56 +04:00
|
|
|
expect($("body")).not.toHaveClass("is-blurred")
|
2013-02-02 03:40:53 +04:00
|
|
|
|
2013-02-06 00:59:26 +04:00
|
|
|
describe "when the window is blurred", ->
|
2013-02-06 00:03:56 +04:00
|
|
|
beforeEach ->
|
|
|
|
$(window).trigger 'blur'
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
$('body').removeClass('is-blurred')
|
|
|
|
|
|
|
|
it "adds the .is-blurred class on the body", ->
|
|
|
|
expect($("body")).toHaveClass("is-blurred")
|
|
|
|
|
|
|
|
describe "when the window is focused again", ->
|
|
|
|
it "removes the .is-blurred class from the body", ->
|
|
|
|
$(window).trigger 'focus'
|
|
|
|
expect($("body")).not.toHaveClass("is-blurred")
|
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")
|
|
|
|
|
2013-02-20 22:02:16 +04:00
|
|
|
describe "shutdown()", ->
|
2013-02-20 00:12:29 +04:00
|
|
|
it "saves the serialized state of the project and root view to the atom object so it can be rehydrated after reload", ->
|
2013-02-20 02:15:11 +04:00
|
|
|
expect(atom.getRootViewStateForPath(project.getPath())).toBeUndefined()
|
2013-02-20 00:12:29 +04:00
|
|
|
# JSON.stringify removes keys with undefined values
|
|
|
|
rootViewState = JSON.parse(JSON.stringify(rootView.serialize()))
|
|
|
|
projectState = JSON.parse(JSON.stringify(project.serialize()))
|
|
|
|
|
2013-02-20 22:02:16 +04:00
|
|
|
shutdown()
|
2013-02-20 00:12:29 +04:00
|
|
|
|
|
|
|
expect(atom.getRootViewStateForPath(project.getPath())).toEqual
|
|
|
|
project: projectState
|
|
|
|
rootView: rootViewState
|
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
|
|
|
|
|
2013-02-20 22:02:16 +04:00
|
|
|
shutdown()
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
expect(editor1.getBuffer().subscriptionCount()).toBe 0
|