2011-12-16 02:13:34 +04:00
|
|
|
Editor = require 'editor'
|
|
|
|
$ = require 'jquery'
|
|
|
|
ck = require 'coffeekup'
|
2011-12-17 02:42:38 +04:00
|
|
|
fs = require 'fs'
|
2011-12-16 02:13:34 +04:00
|
|
|
|
|
|
|
describe "Editor", ->
|
2011-12-17 02:42:38 +04:00
|
|
|
mainDiv = null; editor = null
|
|
|
|
filePath = null; tempFilePath = null
|
2011-12-16 02:13:34 +04:00
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
filePath = require.resolve 'fixtures/sample.txt'
|
2011-12-17 02:42:38 +04:00
|
|
|
tempFilePath = '/tmp/temp.txt'
|
2011-12-16 02:13:34 +04:00
|
|
|
mainDiv = $("<div id='main'>")
|
|
|
|
$("#jasmine-content").append(mainDiv)
|
|
|
|
editor = new Editor filePath
|
|
|
|
|
|
|
|
afterEach ->
|
2011-12-17 02:42:38 +04:00
|
|
|
fs.remove tempFilePath
|
2011-12-16 02:13:34 +04:00
|
|
|
editor.destroy()
|
|
|
|
|
|
|
|
describe "constructor", ->
|
|
|
|
it "attaches itself to the #main element and opens a buffer with the given url", ->
|
|
|
|
expect(editor.buffer.url).toEqual filePath
|
2011-12-16 03:06:34 +04:00
|
|
|
expect(mainDiv.children('.editor').html()).not.toBe ''
|
2011-12-16 02:13:34 +04:00
|
|
|
|
|
|
|
it "populates the editor with the contents of the buffer", ->
|
2011-12-16 03:06:34 +04:00
|
|
|
expect(editor.aceEditor.getSession().getValue()).toBe editor.buffer.getText()
|
2011-12-16 02:13:34 +04:00
|
|
|
|
|
|
|
describe 'destroy', ->
|
|
|
|
it 'destroys the ace editor and removes #editor from the dom.', ->
|
|
|
|
spyOn editor.aceEditor, 'destroy'
|
|
|
|
|
|
|
|
editor.destroy()
|
|
|
|
expect(editor.aceEditor.destroy).toHaveBeenCalled()
|
2011-12-16 03:06:34 +04:00
|
|
|
expect(mainDiv.children('.editor').length).toBe 0
|
2011-12-16 02:13:34 +04:00
|
|
|
|
|
|
|
describe "when the text is changed via the ace editor", ->
|
|
|
|
it "updates the buffer text", ->
|
2011-12-16 03:06:34 +04:00
|
|
|
expect(editor.buffer.getText()).not.toMatch /^.ooo/
|
|
|
|
editor.aceEditor.getSession().insert {row: 0, column: 1}, 'ooo'
|
|
|
|
expect(editor.buffer.getText()).toMatch /^.ooo/
|
2011-12-17 02:42:38 +04:00
|
|
|
|
|
|
|
|
|
|
|
describe "on key down", ->
|
|
|
|
describe "meta+s", ->
|
|
|
|
tempEditor = null
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
tempEditor = new Editor tempFilePath
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
tempEditor.destroy()
|
|
|
|
|
|
|
|
describe "when the current buffer has a url", ->
|
|
|
|
it "saves the current buffer to disk", ->
|
|
|
|
tempEditor.buffer.setText 'Edited buffer!'
|
|
|
|
expect(fs.exists(tempFilePath)).toBeFalsy()
|
|
|
|
|
|
|
|
$(document).trigger(keydown 'meta+s')
|
|
|
|
|
|
|
|
expect(fs.exists(tempFilePath)).toBeTruthy()
|
|
|
|
expect(fs.read(tempFilePath)).toBe 'Edited buffer!'
|
|
|
|
|
|
|
|
describe "when the current buffer has no url", ->
|
|
|
|
it "presents a save as dialog", ->
|
|
|
|
|
|
|
|
describe "when a url is chosen", ->
|
|
|
|
|
|
|
|
describe "when dialog is cancelled", ->
|
|
|
|
|