mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
🎨 organize integration spec
This commit is contained in:
@@ -53,30 +53,36 @@ buildAtomClient = (args, env) ->
|
||||
((err) -> cb(err, succeeded)))
|
||||
|
||||
.addCommand "waitForWindowCount", (count, timeout, cb) ->
|
||||
@waitUntil(
|
||||
(-> @windowHandles().then(({value}) -> value.length is count)),
|
||||
timeout)
|
||||
.then((result) -> expect(result).toBe(true))
|
||||
.windowHandles(cb)
|
||||
@waitUntil(->
|
||||
@windowHandles().then ({value}) -> value.length is count
|
||||
, timeout)
|
||||
.then (result) -> expect(result).toBe(true)
|
||||
.windowHandles(cb)
|
||||
|
||||
.addCommand "waitForPaneItemCount", (count, timeout, cb) ->
|
||||
@waitUntil((->
|
||||
@waitUntil(->
|
||||
@execute(-> atom.workspace?.getActivePane()?.getItems().length)
|
||||
.then(({value}) -> value is count)), timeout)
|
||||
.then (result) ->
|
||||
expect(result).toBe(true)
|
||||
cb(null)
|
||||
.then(({value}) -> value is count)
|
||||
, timeout)
|
||||
.then (result) ->
|
||||
expect(result).toBe(true)
|
||||
cb(null)
|
||||
|
||||
.addCommand("waitForNewWindow", (fn, timeout, done) ->
|
||||
@windowHandles()
|
||||
.then(({value}) ->
|
||||
.addCommand "treeViewRootDirectories", (cb) ->
|
||||
@execute(->
|
||||
for element in document.querySelectorAll(".tree-view .project-root > .header .name")
|
||||
element.dataset.path
|
||||
, cb)
|
||||
|
||||
.addCommand "waitForNewWindow", (fn, timeout, done) ->
|
||||
@windowHandles (err, {value: oldWindowHandles}) ->
|
||||
return done() unless isRunning
|
||||
oldWindowHandles = value
|
||||
@call(-> fn.call(this))
|
||||
.waitForWindowCount(oldWindowHandles.length + 1, 5000)
|
||||
.then(({value}) ->
|
||||
[newWindowHandle] = difference(value, oldWindowHandles)
|
||||
@window(newWindowHandle, done))))
|
||||
@call(fn)
|
||||
.waitForWindowCount(oldWindowHandles.length + 1, 5000)
|
||||
.then ({value: newWindowHandles}) ->
|
||||
[newWindowHandle] = difference(newWindowHandles, oldWindowHandles)
|
||||
return done() unless newWindowHandle
|
||||
@window(newWindowHandle, done)
|
||||
|
||||
.addCommand "startAnotherAtom", (args, env, done) ->
|
||||
@call ->
|
||||
|
||||
@@ -11,140 +11,145 @@ fs.writeFileSync(path.join(AtomHome, 'config.cson'), fs.readFileSync(path.join(_
|
||||
runAtom = require("./helpers/start-atom")
|
||||
|
||||
describe "Starting Atom", ->
|
||||
[tempDirPath, tempFilePath, otherTempDirPath] = []
|
||||
|
||||
beforeEach ->
|
||||
jasmine.useRealClock()
|
||||
|
||||
describe "opening paths via commmand-line arguments", ->
|
||||
[tempDirPath, tempFilePath, otherTempDirPath] = []
|
||||
tempDirPath = temp.mkdirSync("empty-dir")
|
||||
otherTempDirPath = temp.mkdirSync("another-temp-dir")
|
||||
tempFilePath = path.join(tempDirPath, "an-existing-file")
|
||||
fs.writeFileSync(tempFilePath, "This file was already here.")
|
||||
|
||||
beforeEach ->
|
||||
tempDirPath = temp.mkdirSync("empty-dir")
|
||||
otherTempDirPath = temp.mkdirSync("another-temp-dir")
|
||||
tempFilePath = path.join(tempDirPath, "an-existing-file")
|
||||
fs.writeFileSync(tempFilePath, "This file was already here.")
|
||||
|
||||
it "reuses existing windows when directories are reopened", ->
|
||||
describe "opening a new file", ->
|
||||
it "opens the parent directory and creates an empty text editor", ->
|
||||
runAtom [path.join(tempDirPath, "new-file")], {ATOM_HOME: AtomHome}, (client) ->
|
||||
client
|
||||
|
||||
# Opening a new file creates one window with one empty text editor.
|
||||
.waitForExist("atom-text-editor", 5000)
|
||||
.then((exists) -> expect(exists).toBe true)
|
||||
.waitForWindowCount(1, 1000)
|
||||
.waitForExist("atom-workspace", 5000)
|
||||
.waitForPaneItemCount(1, 1000)
|
||||
.execute(-> atom.project.getPaths())
|
||||
.then(({value}) -> expect(value).toEqual([tempDirPath]))
|
||||
|
||||
# Typing in the editor changes its text.
|
||||
.execute(-> atom.workspace.getActiveTextEditor().getText())
|
||||
.then(({value}) -> expect(value).toBe "")
|
||||
.treeViewRootDirectories()
|
||||
.then ({value}) -> expect(value).toEqual([tempDirPath])
|
||||
|
||||
.waitForExist("atom-text-editor", 5000)
|
||||
.then (exists) -> expect(exists).toBe true
|
||||
.click("atom-text-editor")
|
||||
.keys("Hello!")
|
||||
.execute(-> atom.workspace.getActiveTextEditor().getText())
|
||||
.then(({value}) -> expect(value).toBe "Hello!")
|
||||
.execute -> atom.workspace.getActiveTextEditor().getText()
|
||||
.then ({value}) -> expect(value).toBe "Hello!"
|
||||
|
||||
describe "opening a directory that is already open in an existing window", ->
|
||||
it "reuses that existing window", ->
|
||||
runAtom [path.join(tempDirPath, "new-file")], {ATOM_HOME: AtomHome}, (client) ->
|
||||
client
|
||||
.waitForWindowCount(1, 1000)
|
||||
.waitForExist("atom-workspace", 5000)
|
||||
.waitForPaneItemCount(1, 5000)
|
||||
|
||||
# Opening an existing file in the same directory reuses the window and
|
||||
# adds a new tab for the file.
|
||||
.startAnotherAtom([tempFilePath], ATOM_HOME: AtomHome)
|
||||
.waitForExist("atom-workspace")
|
||||
.waitForPaneItemCount(2, 5000)
|
||||
.waitForWindowCount(1, 1000)
|
||||
.execute(-> atom.workspace.getActiveTextEditor().getText())
|
||||
.then(({value}) -> expect(value).toBe "This file was already here.")
|
||||
.treeViewRootDirectories()
|
||||
.then ({value}) -> expect(value).toEqual([tempDirPath])
|
||||
.execute -> atom.workspace.getActiveTextEditor().getText()
|
||||
.then ({value: text}) -> expect(text).toBe "This file was already here."
|
||||
|
||||
# Opening a different directory creates a second window with no
|
||||
# tabs open.
|
||||
.waitForNewWindow(->
|
||||
@startAnotherAtom([otherTempDirPath], ATOM_HOME: AtomHome)
|
||||
, 5000)
|
||||
.waitForExist("atom-workspace", 5000)
|
||||
.waitForPaneItemCount(0, 1000)
|
||||
.treeViewRootDirectories()
|
||||
.then ({value}) -> expect(value).toEqual([otherTempDirPath])
|
||||
|
||||
it "saves the state of closed windows", ->
|
||||
runAtom [tempDirPath], {ATOM_HOME: AtomHome}, (client) ->
|
||||
describe "reopening a directory that was previously opened", ->
|
||||
it "remembers the state of the window", ->
|
||||
runAtom [otherTempDirPath], {ATOM_HOME: AtomHome}, (client) ->
|
||||
client
|
||||
|
||||
# In a second window, opening a new buffer creates a new tab.
|
||||
.waitForExist("atom-workspace", 5000)
|
||||
.waitForNewWindow(->
|
||||
@startAnotherAtom([otherTempDirPath], ATOM_HOME: AtomHome)
|
||||
, 5000)
|
||||
.waitForExist("atom-workspace", 5000)
|
||||
.waitForPaneItemCount(0, 3000)
|
||||
.execute(-> atom.workspace.open())
|
||||
.execute -> atom.workspace.open()
|
||||
.waitForPaneItemCount(1, 3000)
|
||||
.execute -> atom.unloadEditorWindow()
|
||||
|
||||
# Closing that window and reopening that directory shows the
|
||||
# previously-created new buffer.
|
||||
.execute(-> atom.unloadEditorWindow())
|
||||
.close()
|
||||
.waitForWindowCount(1, 5000)
|
||||
.waitForNewWindow(->
|
||||
@startAnotherAtom([otherTempDirPath], ATOM_HOME: AtomHome)
|
||||
, 5000)
|
||||
runAtom [otherTempDirPath], {ATOM_HOME: AtomHome}, (client) ->
|
||||
client
|
||||
.waitForExist("atom-workspace", 5000)
|
||||
.waitForPaneItemCount(1, 5000)
|
||||
|
||||
it "allows multiple project directories to be passed as separate arguments", ->
|
||||
describe "opening multiple directories simultaneously", ->
|
||||
it "shows them all in the tree-view", ->
|
||||
runAtom [tempDirPath, otherTempDirPath, "--multi-folder"], {ATOM_HOME: AtomHome}, (client) ->
|
||||
client
|
||||
.waitForExist("atom-workspace", 5000)
|
||||
.then((exists) -> expect(exists).toBe true)
|
||||
.execute(-> atom.project.getPaths())
|
||||
.then(({value}) -> expect(value).toEqual([tempDirPath, otherTempDirPath]))
|
||||
.treeViewRootDirectories()
|
||||
.then ({value}) -> expect(value).toEqual([tempDirPath, otherTempDirPath])
|
||||
|
||||
# Opening a file in one of the directories reuses the same window
|
||||
# and does not change the project paths.
|
||||
.startAnotherAtom([tempFilePath], ATOM_HOME: AtomHome)
|
||||
.waitForExist("atom-workspace", 5000)
|
||||
.waitForPaneItemCount(1, 5000)
|
||||
.execute(-> atom.project.getPaths())
|
||||
.then(({value}) -> expect(value).toEqual([tempDirPath, otherTempDirPath]))
|
||||
.treeViewRootDirectories()
|
||||
.then ({value}) -> expect(value).toEqual([tempDirPath, otherTempDirPath])
|
||||
|
||||
it "opens each path in its own window unless the --multi-folder flag is passed", ->
|
||||
runAtom [tempDirPath, otherTempDirPath], {ATOM_HOME: AtomHome}, (client) ->
|
||||
projectPaths = []
|
||||
treeViewDirs = []
|
||||
|
||||
client
|
||||
.waitForWindowCount(2, 5000)
|
||||
.windowHandles()
|
||||
.waitForExist("atom-workspace", 5000)
|
||||
.waitForWindowCount(2, 10000)
|
||||
.then ({value: windowHandles}) ->
|
||||
|
||||
@window(windowHandles[0])
|
||||
.execute(-> atom.project.getPaths())
|
||||
.waitForExist("atom-workspace")
|
||||
.treeViewRootDirectories()
|
||||
.then ({value}) ->
|
||||
expect(value).toHaveLength(1)
|
||||
projectPaths.push(value[0])
|
||||
treeViewDirs.push(value[0])
|
||||
|
||||
.window(windowHandles[1])
|
||||
.execute(-> atom.project.getPaths())
|
||||
.waitForExist("atom-workspace")
|
||||
.treeViewRootDirectories()
|
||||
.then ({value}) ->
|
||||
expect(value).toHaveLength(1)
|
||||
projectPaths.push(value[0])
|
||||
treeViewDirs.push(value[0])
|
||||
.then ->
|
||||
expect(projectPaths.sort()).toEqual([tempDirPath, otherTempDirPath].sort())
|
||||
expect(treeViewDirs.sort()).toEqual([tempDirPath, otherTempDirPath].sort())
|
||||
|
||||
it "opens the path in the current window if it doesn't have a project path yet", ->
|
||||
runAtom [], {ATOM_HOME: AtomHome}, (client) ->
|
||||
client
|
||||
.waitForExist("atom-workspace")
|
||||
.startAnotherAtom([tempDirPath], ATOM_HOME: AtomHome)
|
||||
.waitUntil((->
|
||||
@title()
|
||||
.then(({value}) -> value.indexOf(path.basename(tempDirPath)) >= 0)), 5000)
|
||||
.waitForWindowCount(1, 5000)
|
||||
describe "when there is an existing window with no project path", ->
|
||||
describe "opening a directory", ->
|
||||
it "opens the directory in the existing window", ->
|
||||
runAtom [], {ATOM_HOME: AtomHome}, (client) ->
|
||||
client
|
||||
.waitForExist("atom-workspace")
|
||||
.treeViewRootDirectories()
|
||||
.then ({value}) -> expect(value).toEqual([])
|
||||
|
||||
it "always opens with a single untitled buffer when launched w/ no path", ->
|
||||
runAtom [], {ATOM_HOME: AtomHome}, (client) ->
|
||||
client
|
||||
.waitForExist("atom-workspace")
|
||||
.waitForPaneItemCount(1, 5000)
|
||||
.startAnotherAtom([tempDirPath], ATOM_HOME: AtomHome)
|
||||
.waitUntil(->
|
||||
@treeViewRootDirectories()
|
||||
.then ({value}) -> value[0] is tempDirPath
|
||||
, 5000)
|
||||
.then (result) -> expect(result).toBe(true)
|
||||
.waitForWindowCount(1, 5000)
|
||||
|
||||
runAtom [], {ATOM_HOME: AtomHome}, (client) ->
|
||||
client
|
||||
.waitForExist("atom-workspace")
|
||||
.waitForPaneItemCount(1, 5000)
|
||||
describe "launching with no path", ->
|
||||
it "always opens a new window with a single untitled buffer", ->
|
||||
runAtom [], {ATOM_HOME: AtomHome}, (client) ->
|
||||
client
|
||||
.waitForExist("atom-workspace")
|
||||
.waitForPaneItemCount(1, 5000)
|
||||
|
||||
# Opening with no file paths always creates a new window, even if
|
||||
# existing windows have no project paths.
|
||||
.waitForNewWindow(->
|
||||
@startAnotherAtom([], ATOM_HOME: AtomHome)
|
||||
, 5000)
|
||||
runAtom [], {ATOM_HOME: AtomHome}, (client) ->
|
||||
client
|
||||
.waitForExist("atom-workspace")
|
||||
.waitForPaneItemCount(1, 5000)
|
||||
|
||||
# Opening with no file paths always creates a new window, even if
|
||||
# existing windows have no project paths.
|
||||
.waitForNewWindow(->
|
||||
@startAnotherAtom([], ATOM_HOME: AtomHome)
|
||||
, 5000)
|
||||
|
||||
Reference in New Issue
Block a user