mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-21 16:08:24 +03:00
buffer triggers a 'path-change' event when a file is moved or removed
This commit is contained in:
parent
eafd007c39
commit
239fd2f9e6
@ -42,14 +42,40 @@ describe 'Buffer', ->
|
||||
expect(buffer.getText()).toBe ""
|
||||
|
||||
describe "path-change event", ->
|
||||
afterEach ->
|
||||
fs.remove("/tmp/moo.text") if fs.exists("/tmp/moo.text")
|
||||
[path, newPath, bufferToChange, eventHandler] = []
|
||||
|
||||
it "emits path-change event when path is changed", ->
|
||||
beforeEach ->
|
||||
path = fs.join(require.resolve("fixtures/"), "tmp/atom-manipulate-me")
|
||||
newPath = "#{path}-i-moved"
|
||||
fs.write(path, "")
|
||||
bufferToChange = new Buffer(path)
|
||||
eventHandler = jasmine.createSpy('eventHandler')
|
||||
buffer.on 'path-change', eventHandler
|
||||
buffer.saveAs("/tmp/moo.text")
|
||||
expect(eventHandler).toHaveBeenCalledWith(buffer)
|
||||
bufferToChange.on 'path-change', eventHandler
|
||||
|
||||
afterEach ->
|
||||
bufferToChange.destroy()
|
||||
fs.remove(path) if fs.exists(path)
|
||||
fs.remove(newPath) if fs.exists(newPath)
|
||||
|
||||
it "triggers a `path-change` event when path is changed", ->
|
||||
bufferToChange.saveAs(newPath)
|
||||
expect(eventHandler).toHaveBeenCalledWith(bufferToChange)
|
||||
|
||||
it "triggers a `path-change` event when the file is moved", ->
|
||||
fs.remove(newPath) if fs.exists(newPath)
|
||||
fs.move(path, newPath)
|
||||
|
||||
waitsFor "buffer path change", ->
|
||||
eventHandler.callCount > 0
|
||||
|
||||
runs ->
|
||||
expect(eventHandler).toHaveBeenCalledWith(bufferToChange)
|
||||
|
||||
it "triggers a `path-change` event when the file is removed", ->
|
||||
fs.remove(path)
|
||||
|
||||
waitsFor "buffer path change", ->
|
||||
eventHandler.callCount > 0
|
||||
|
||||
describe "when the buffer's file is modified (via another process)", ->
|
||||
path = null
|
||||
|
@ -56,6 +56,10 @@ class Buffer
|
||||
|
||||
@file.on "remove", =>
|
||||
@file = null
|
||||
@trigger "path-change", this
|
||||
|
||||
@file.on "move", =>
|
||||
@trigger "path-change", this
|
||||
|
||||
@trigger "path-change", this
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user