Reintroduce editor serialization specs

I added some features to telepath that make it easier to test model
objects.

- First, you can now call replicate on any telepath document/model
  object. The entire underlying database will be replicated and you will
  be handed the equivalent of that object in the replicated world. This
  is easier than forcing you to attach the model to the window state 
  and then call replicate there. However, remember that the entire
  window state is actually being replicated so any references the model
  has will also be replicated.

- Second, you can also replicate orphaned objects. Most objects in these
  specs we're converting are orphans because there's no reason to attach
  them to the root document just to test them in isolation.
This commit is contained in:
Nathan Sobo
2013-12-10 19:07:50 -08:00
parent 425c076221
commit c4fc75215b
2 changed files with 20 additions and 1 deletions

View File

@@ -43,7 +43,7 @@
"season": "0.14.0",
"semver": "1.1.4",
"space-pen": "2.0.1",
"telepath": "0.65.0",
"telepath": "0.66.0",
"temp": "0.5.0",
"underscore-plus": "0.3.0"
},

View File

@@ -21,6 +21,25 @@ describe "Editor", ->
buffer = editor.buffer
lineLengths = buffer.getLines().map (line) -> line.length
describe "when the editor is deserialized", ->
it "restores selections and folds based on markers in the buffer", ->
editor.setSelectedBufferRange([[1, 2], [3, 4]])
editor.addSelectionForBufferRange([[5, 6], [7, 5]], isReversed: true)
editor.foldBufferRow(4)
expect(editor.isFoldedAtBufferRow(4)).toBeTruthy()
# Simulate serialization with replicate
editor2 = editor.replicate()
# FIXME: The created hook is called manually on deserialization because globals aren't ready otherwise
editor2.created()
expect(editor2.id).toBe editor.id
expect(editor2.getBuffer().getPath()).toBe editor.getBuffer().getPath()
expect(editor2.getSelectedBufferRanges()).toEqual [[[1, 2], [3, 4]], [[5, 6], [7, 5]]]
expect(editor2.getSelection(1).isReversed()).toBeTruthy()
expect(editor2.isFoldedAtBufferRow(4)).toBeTruthy()
editor2.destroy()
describe ".copy()", ->
it "returns a different edit session with the same initial state", ->
editor.setSelectedBufferRange([[1, 2], [3, 4]])