Use Editor.deserialize in Editor.prototype.copy and add a spec for it

This commit is contained in:
Corey Johnson & Nathan Sobo 2012-04-13 11:39:16 -06:00
parent da53fa1ba3
commit 54a15856bb
2 changed files with 15 additions and 1 deletions

View File

@ -26,6 +26,20 @@ describe "Editor", ->
editor.insertText('x')
expect(editor.lines.find('.line').length).toBe 1
describe ".copy()", ->
it "builds a new editor with the same edit sessions, cursor position, and scroll position as the receiver", ->
editor.setCursorScreenPosition([1, 1])
# prove this test covers serialization and deserialization
spyOn(editor, 'serialize').andCallThrough()
spyOn(Editor, 'deserialize').andCallThrough()
newEditor = editor.copy()
expect(editor.serialize).toHaveBeenCalled()
expect(Editor.deserialize).toHaveBeenCalled()
expect(newEditor.buffer).toBe editor.buffer
expect(newEditor.getCursorScreenPosition()).toEqual editor.getCursorScreenPosition()
describe "text rendering", ->
it "creates a line element for each line in the buffer with the html-escaped text of the line", ->
expect(editor.lines.find('.line').length).toEqual(buffer.numLines())

View File

@ -67,7 +67,7 @@ class Editor extends View
{ viewClass: "Editor", @editSessions, @activeEditSessionIndex, @isFocused }
copy: ->
new Editor(@serialize())
Editor.deserialize(@serialize())
bindKeys: ->
@on 'save', => @save()