2014-11-25 23:55:50 +03:00
|
|
|
{$, $$} = require '../src/space-pen-extensions'
|
2013-06-13 03:20:40 +04:00
|
|
|
path = require 'path'
|
2014-09-23 01:35:13 +04:00
|
|
|
TextEditor = require '../src/text-editor'
|
2013-09-18 05:58:41 +04:00
|
|
|
WindowEventHandler = require '../src/window-event-handler'
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
describe "Window", ->
|
2013-05-17 01:13:25 +04:00
|
|
|
[projectPath, windowEventHandler] = []
|
2013-01-08 02:26:53 +04:00
|
|
|
|
2012-08-28 02:36:36 +04:00
|
|
|
beforeEach ->
|
2013-09-17 22:11:01 +04:00
|
|
|
spyOn(atom, 'hide')
|
2014-10-01 20:37:27 +04:00
|
|
|
initialPath = atom.project.getPaths()[0]
|
2013-12-14 00:02:48 +04:00
|
|
|
spyOn(atom, 'getLoadSettings').andCallFake ->
|
|
|
|
loadSettings = atom.getLoadSettings.originalValue.call(atom)
|
|
|
|
loadSettings.initialPath = initialPath
|
|
|
|
loadSettings
|
2013-11-21 03:35:49 +04:00
|
|
|
atom.project.destroy()
|
2013-05-17 01:13:25 +04:00
|
|
|
windowEventHandler = new WindowEventHandler()
|
2013-11-22 21:48:57 +04:00
|
|
|
atom.deserializeEditorWindow()
|
2014-10-01 20:37:27 +04:00
|
|
|
projectPath = atom.project.getPaths()[0]
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
afterEach ->
|
2013-05-17 01:13:25 +04:00
|
|
|
windowEventHandler.unsubscribe()
|
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 ->
|
2013-10-17 01:41:38 +04:00
|
|
|
$(window).triggerHandler 'blur'
|
2013-02-06 00:03:56 +04:00
|
|
|
|
|
|
|
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", ->
|
2013-10-17 01:41:38 +04:00
|
|
|
$(window).triggerHandler 'focus'
|
2013-02-06 00:03:56 +04:00
|
|
|
expect($("body")).not.toHaveClass("is-blurred")
|
2013-02-02 03:40:53 +04:00
|
|
|
|
2013-03-13 02:54:07 +04:00
|
|
|
describe "window:close event", ->
|
2013-06-27 17:31:07 +04:00
|
|
|
it "closes the window", ->
|
2013-08-28 21:42:56 +04:00
|
|
|
spyOn(atom, 'close')
|
2013-06-27 17:31:07 +04:00
|
|
|
$(window).trigger 'window:close'
|
2013-08-28 21:42:56 +04:00
|
|
|
expect(atom.close).toHaveBeenCalled()
|
2013-01-08 01:15:33 +04:00
|
|
|
|
2013-06-27 17:31:07 +04:00
|
|
|
describe "beforeunload event", ->
|
2013-10-16 21:44:00 +04:00
|
|
|
[beforeUnloadEvent] = []
|
|
|
|
|
|
|
|
beforeEach ->
|
2014-09-23 01:35:13 +04:00
|
|
|
jasmine.unspy(TextEditor.prototype, "shouldPromptToSave")
|
2013-10-16 21:44:00 +04:00
|
|
|
beforeUnloadEvent = $.Event(new Event('beforeunload'))
|
|
|
|
|
2013-03-13 02:54:07 +04:00
|
|
|
describe "when pane items are are modified", ->
|
2014-09-25 22:44:06 +04:00
|
|
|
it "prompts user to save and calls atom.workspace.confirmClose", ->
|
2014-04-23 01:19:13 +04:00
|
|
|
editor = null
|
2014-09-25 01:46:01 +04:00
|
|
|
spyOn(atom.workspace, 'confirmClose').andCallThrough()
|
2013-11-23 03:09:47 +04:00
|
|
|
spyOn(atom, "confirm").andReturn(2)
|
2014-04-23 01:19:13 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.open("sample.js").then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
editor.insertText("I look different, I feel different.")
|
|
|
|
$(window).trigger(beforeUnloadEvent)
|
2014-09-25 01:46:01 +04:00
|
|
|
expect(atom.workspace.confirmClose).toHaveBeenCalled()
|
2014-04-23 01:19:13 +04:00
|
|
|
expect(atom.confirm).toHaveBeenCalled()
|
2013-06-27 17:31:07 +04:00
|
|
|
|
|
|
|
it "prompts user to save and handler returns true if don't save", ->
|
2014-04-23 01:19:13 +04:00
|
|
|
editor = null
|
2013-11-23 03:09:47 +04:00
|
|
|
spyOn(atom, "confirm").andReturn(2)
|
2014-04-23 01:19:13 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.open("sample.js").then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
editor.insertText("I look different, I feel different.")
|
|
|
|
$(window).trigger(beforeUnloadEvent)
|
|
|
|
expect(atom.confirm).toHaveBeenCalled()
|
2013-03-13 02:43:37 +04:00
|
|
|
|
2013-06-27 17:31:07 +04:00
|
|
|
it "prompts user to save and handler returns false if dialog is canceled", ->
|
2014-04-23 01:19:13 +04:00
|
|
|
editor = null
|
2013-11-23 03:09:47 +04:00
|
|
|
spyOn(atom, "confirm").andReturn(1)
|
2014-04-23 01:19:13 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.open("sample.js").then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
editor.insertText("I look different, I feel different.")
|
|
|
|
$(window).trigger(beforeUnloadEvent)
|
|
|
|
expect(atom.confirm).toHaveBeenCalled()
|
2013-01-08 01:15:33 +04:00
|
|
|
|
2013-04-11 03:27:35 +04:00
|
|
|
describe ".unloadEditorWindow()", ->
|
2013-03-22 04:23:37 +04:00
|
|
|
it "saves the serialized state of the window so it can be deserialized after reload", ->
|
2014-01-14 22:36:51 +04:00
|
|
|
workspaceState = atom.workspace.serialize()
|
2014-11-20 21:42:49 +03:00
|
|
|
syntaxState = atom.grammars.serialize()
|
2014-03-05 04:21:08 +04:00
|
|
|
projectState = atom.project.serialize()
|
2013-02-20 00:12:29 +04:00
|
|
|
|
2013-11-22 21:58:23 +04:00
|
|
|
atom.unloadEditorWindow()
|
2013-02-20 00:12:29 +04:00
|
|
|
|
2014-01-14 22:36:51 +04:00
|
|
|
expect(atom.state.workspace).toEqual workspaceState
|
2014-11-20 23:12:17 +03:00
|
|
|
expect(atom.state.grammars).toEqual syntaxState
|
2014-03-05 04:21:08 +04:00
|
|
|
expect(atom.state.project).toEqual projectState
|
2013-12-13 04:35:56 +04:00
|
|
|
expect(atom.saveSync).toHaveBeenCalled()
|
2013-03-22 04:23:37 +04:00
|
|
|
|
2014-08-12 00:08:31 +04:00
|
|
|
describe ".removeEditorWindow()", ->
|
2012-08-28 02:36:36 +04:00
|
|
|
it "unsubscribes from all buffers", ->
|
2014-04-23 01:19:13 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.open("sample.js")
|
2012-08-28 02:36:36 +04:00
|
|
|
|
2014-04-23 01:19:13 +04:00
|
|
|
runs ->
|
|
|
|
buffer = atom.workspace.getActivePaneItem().buffer
|
2014-11-20 03:58:52 +03:00
|
|
|
pane = atom.workspace.getActivePane()
|
|
|
|
pane.splitRight(copyActiveItem: true)
|
|
|
|
expect(atom.workspace.getTextEditors().length).toBe 2
|
2014-04-23 01:19:13 +04:00
|
|
|
|
2014-08-12 00:08:31 +04:00
|
|
|
atom.removeEditorWindow()
|
2012-08-28 02:36:36 +04:00
|
|
|
|
2014-04-23 01:19:13 +04:00
|
|
|
expect(buffer.getSubscriptionCount()).toBe 0
|
2013-02-20 22:18:19 +04:00
|
|
|
|
2013-04-08 16:17:40 +04:00
|
|
|
describe "drag and drop", ->
|
|
|
|
buildDragEvent = (type, files) ->
|
|
|
|
dataTransfer =
|
|
|
|
files: files
|
|
|
|
data: {}
|
|
|
|
setData: (key, value) -> @data[key] = value
|
|
|
|
getData: (key) -> @data[key]
|
|
|
|
|
2014-12-04 07:25:42 +03:00
|
|
|
event = new CustomEvent("drop")
|
|
|
|
event.dataTransfer = dataTransfer
|
2013-04-08 16:17:40 +04:00
|
|
|
event
|
|
|
|
|
|
|
|
describe "when a file is dragged to window", ->
|
|
|
|
it "opens it", ->
|
|
|
|
spyOn(atom, "open")
|
|
|
|
event = buildDragEvent("drop", [ {path: "/fake1"}, {path: "/fake2"} ])
|
2014-12-04 07:25:42 +03:00
|
|
|
document.dispatchEvent(event)
|
2013-08-21 02:24:30 +04:00
|
|
|
expect(atom.open.callCount).toBe 1
|
|
|
|
expect(atom.open.argsForCall[0][0]).toEqual pathsToOpen: ['/fake1', '/fake2']
|
2013-04-08 16:17:40 +04:00
|
|
|
|
|
|
|
describe "when a non-file is dragged to window", ->
|
|
|
|
it "does nothing", ->
|
|
|
|
spyOn(atom, "open")
|
|
|
|
event = buildDragEvent("drop", [])
|
2014-12-04 07:25:42 +03:00
|
|
|
document.dispatchEvent(event)
|
2013-04-08 16:17:40 +04:00
|
|
|
expect(atom.open).not.toHaveBeenCalled()
|
2013-05-02 08:35:29 +04:00
|
|
|
|
|
|
|
describe "when a link is clicked", ->
|
|
|
|
it "opens the http/https links in an external application", ->
|
2013-05-20 06:05:19 +04:00
|
|
|
shell = require 'shell'
|
|
|
|
spyOn(shell, 'openExternal')
|
2013-05-02 08:35:29 +04:00
|
|
|
|
|
|
|
$("<a href='http://github.com'>the website</a>").appendTo(document.body).click().remove()
|
2013-05-20 06:05:19 +04:00
|
|
|
expect(shell.openExternal).toHaveBeenCalled()
|
2013-05-23 10:50:21 +04:00
|
|
|
expect(shell.openExternal.argsForCall[0][0]).toBe "http://github.com"
|
2013-05-02 08:35:29 +04:00
|
|
|
|
2013-05-20 06:05:19 +04:00
|
|
|
shell.openExternal.reset()
|
2013-05-02 08:35:29 +04:00
|
|
|
$("<a href='https://github.com'>the website</a>").appendTo(document.body).click().remove()
|
2013-05-20 06:05:19 +04:00
|
|
|
expect(shell.openExternal).toHaveBeenCalled()
|
2013-05-23 10:50:21 +04:00
|
|
|
expect(shell.openExternal.argsForCall[0][0]).toBe "https://github.com"
|
2013-05-02 08:35:29 +04:00
|
|
|
|
2013-05-20 06:05:19 +04:00
|
|
|
shell.openExternal.reset()
|
2013-05-02 08:35:29 +04:00
|
|
|
$("<a href=''>the website</a>").appendTo(document.body).click().remove()
|
2013-05-20 06:05:19 +04:00
|
|
|
expect(shell.openExternal).not.toHaveBeenCalled()
|
2013-05-02 08:35:29 +04:00
|
|
|
|
2013-05-20 06:05:19 +04:00
|
|
|
shell.openExternal.reset()
|
2013-05-02 08:35:29 +04:00
|
|
|
$("<a href='#scroll-me'>link</a>").appendTo(document.body).click().remove()
|
2013-05-20 06:05:19 +04:00
|
|
|
expect(shell.openExternal).not.toHaveBeenCalled()
|
2013-05-17 02:00:55 +04:00
|
|
|
|
2015-01-14 03:01:24 +03:00
|
|
|
describe "when a form is submitted", ->
|
|
|
|
it "prevents the default so that the window's URL isn't changed", ->
|
|
|
|
submitSpy = jasmine.createSpy('submit')
|
|
|
|
$(document).on('submit', 'form', submitSpy)
|
|
|
|
$("<form>foo</form>").appendTo(document.body).submit().remove()
|
|
|
|
expect(submitSpy.callCount).toBe 1
|
|
|
|
expect(submitSpy.argsForCall[0][0].isDefaultPrevented()).toBe true
|
|
|
|
|
2013-05-17 02:00:55 +04:00
|
|
|
describe "core:focus-next and core:focus-previous", ->
|
|
|
|
describe "when there is no currently focused element", ->
|
|
|
|
it "focuses the element with the lowest/highest tabindex", ->
|
|
|
|
elements = $$ ->
|
|
|
|
@div =>
|
|
|
|
@button tabindex: 2
|
|
|
|
@input tabindex: 1
|
|
|
|
|
|
|
|
elements.attachToDom()
|
|
|
|
|
|
|
|
elements.trigger "core:focus-next"
|
|
|
|
expect(elements.find("[tabindex=1]:focus")).toExist()
|
|
|
|
|
|
|
|
$(":focus").blur()
|
|
|
|
|
|
|
|
elements.trigger "core:focus-previous"
|
|
|
|
expect(elements.find("[tabindex=2]:focus")).toExist()
|
|
|
|
|
|
|
|
describe "when a tabindex is set on the currently focused element", ->
|
|
|
|
it "focuses the element with the next highest tabindex", ->
|
|
|
|
elements = $$ ->
|
|
|
|
@div =>
|
|
|
|
@input tabindex: 1
|
|
|
|
@button tabindex: 2
|
|
|
|
@button tabindex: 5
|
|
|
|
@input tabindex: -1
|
|
|
|
@input tabindex: 3
|
|
|
|
@button tabindex: 7
|
|
|
|
|
|
|
|
elements.attachToDom()
|
|
|
|
elements.find("[tabindex=1]").focus()
|
|
|
|
|
|
|
|
elements.trigger "core:focus-next"
|
|
|
|
expect(elements.find("[tabindex=2]:focus")).toExist()
|
|
|
|
|
|
|
|
elements.trigger "core:focus-next"
|
|
|
|
expect(elements.find("[tabindex=3]:focus")).toExist()
|
|
|
|
|
|
|
|
elements.focus().trigger "core:focus-next"
|
|
|
|
expect(elements.find("[tabindex=5]:focus")).toExist()
|
|
|
|
|
|
|
|
elements.focus().trigger "core:focus-next"
|
|
|
|
expect(elements.find("[tabindex=7]:focus")).toExist()
|
|
|
|
|
|
|
|
elements.focus().trigger "core:focus-next"
|
|
|
|
expect(elements.find("[tabindex=1]:focus")).toExist()
|
|
|
|
|
|
|
|
elements.trigger "core:focus-previous"
|
|
|
|
expect(elements.find("[tabindex=7]:focus")).toExist()
|
|
|
|
|
|
|
|
elements.trigger "core:focus-previous"
|
|
|
|
expect(elements.find("[tabindex=5]:focus")).toExist()
|
|
|
|
|
|
|
|
elements.focus().trigger "core:focus-previous"
|
|
|
|
expect(elements.find("[tabindex=3]:focus")).toExist()
|
|
|
|
|
|
|
|
elements.focus().trigger "core:focus-previous"
|
|
|
|
expect(elements.find("[tabindex=2]:focus")).toExist()
|
|
|
|
|
|
|
|
elements.focus().trigger "core:focus-previous"
|
|
|
|
expect(elements.find("[tabindex=1]:focus")).toExist()
|
|
|
|
|
|
|
|
it "skips disabled elements", ->
|
|
|
|
elements = $$ ->
|
|
|
|
@div =>
|
|
|
|
@input tabindex: 1
|
|
|
|
@button tabindex: 2, disabled: 'disabled'
|
|
|
|
@input tabindex: 3
|
|
|
|
|
|
|
|
elements.attachToDom()
|
|
|
|
elements.find("[tabindex=1]").focus()
|
|
|
|
|
|
|
|
elements.trigger "core:focus-next"
|
|
|
|
expect(elements.find("[tabindex=3]:focus")).toExist()
|
|
|
|
|
|
|
|
elements.trigger "core:focus-previous"
|
|
|
|
expect(elements.find("[tabindex=1]:focus")).toExist()
|
2014-09-09 20:55:31 +04:00
|
|
|
|
|
|
|
describe "the window:open-path event", ->
|
|
|
|
beforeEach ->
|
|
|
|
spyOn(atom.workspace, 'open')
|
|
|
|
|
|
|
|
describe "when the project does not have a path", ->
|
|
|
|
beforeEach ->
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.setPaths([])
|
2014-09-09 20:55:31 +04:00
|
|
|
|
|
|
|
describe "when the opened path exists", ->
|
|
|
|
it "sets the project path to the opened path", ->
|
2014-11-27 20:30:50 +03:00
|
|
|
atom.getCurrentWindow().send 'message', 'open-path', pathToOpen: __filename
|
2014-10-01 20:37:27 +04:00
|
|
|
expect(atom.project.getPaths()[0]).toBe __dirname
|
2014-09-09 20:55:31 +04:00
|
|
|
|
|
|
|
describe "when the opened path does not exist but its parent directory does", ->
|
|
|
|
it "sets the project path to the opened path's parent directory", ->
|
2014-11-27 20:30:50 +03:00
|
|
|
pathToOpen = path.join(__dirname, 'this-path-does-not-exist.txt')
|
|
|
|
atom.getCurrentWindow().send 'message', 'open-path', {pathToOpen}
|
2014-10-01 20:37:27 +04:00
|
|
|
expect(atom.project.getPaths()[0]).toBe __dirname
|
2014-09-09 20:55:31 +04:00
|
|
|
|
|
|
|
describe "when the opened path is a file", ->
|
|
|
|
it "opens it in the workspace", ->
|
2014-11-27 20:30:50 +03:00
|
|
|
atom.getCurrentWindow().send 'message', 'open-path', pathToOpen: __filename
|
2014-09-09 20:55:31 +04:00
|
|
|
|
|
|
|
expect(atom.workspace.open.mostRecentCall.args[0]).toBe __filename
|
|
|
|
|
|
|
|
describe "when the opened path is a directory", ->
|
|
|
|
it "does not open it in the workspace", ->
|
2014-11-27 20:30:50 +03:00
|
|
|
atom.getCurrentWindow().send 'message', 'open-path', pathToOpen: __dirname
|
2014-09-09 20:55:31 +04:00
|
|
|
|
|
|
|
expect(atom.workspace.open.callCount).toBe 0
|