2013-07-24 03:41:38 +04:00
|
|
|
{Site} = require 'telepath'
|
2013-09-18 05:58:41 +04:00
|
|
|
Editor = require '../src/editor'
|
2013-09-18 01:54:33 +04:00
|
|
|
Environment = require './environment'
|
2013-07-24 03:41:38 +04:00
|
|
|
|
|
|
|
describe "Editor replication", ->
|
|
|
|
[env1, env2, editSession1, editSession2, editor1, editor2] = []
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
env1 = new Environment(siteId: 1)
|
|
|
|
env2 = env1.clone(siteId: 2)
|
|
|
|
envConnection = env1.connect(env2)
|
|
|
|
doc2 = null
|
|
|
|
|
|
|
|
env1.run ->
|
|
|
|
editSession1 = project.open('sample.js')
|
|
|
|
editSession1.setSelectedBufferRange([[1, 2], [3, 4]])
|
|
|
|
doc1 = editSession1.getState()
|
|
|
|
doc2 = doc1.clone(env2.site)
|
|
|
|
envConnection.connect(doc1, doc2)
|
|
|
|
editor1 = new Editor(editSession1)
|
|
|
|
editor1.attachToDom()
|
|
|
|
|
|
|
|
env2.run ->
|
|
|
|
editSession2 = deserialize(doc2)
|
|
|
|
editor2 = new Editor(editSession2)
|
|
|
|
editor2.attachToDom()
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
env1.destroy()
|
|
|
|
env2.destroy()
|
|
|
|
|
2013-07-24 03:44:51 +04:00
|
|
|
it "displays the cursors and selections from all replicas", ->
|
2013-07-24 03:41:38 +04:00
|
|
|
expect(editor1.getSelectionViews().length).toBe 2
|
|
|
|
expect(editor2.getSelectionViews().length).toBe 2
|
2013-07-24 03:44:51 +04:00
|
|
|
|
|
|
|
expect(editor1.getCursorViews().length).toBe 2
|
|
|
|
expect(editor2.getCursorViews().length).toBe 2
|