testing observers, refactoring some Basic Types
This commit is contained in:
@@ -20,7 +20,7 @@ class JsonTest extends Test
|
||||
type: "JsonTest"
|
||||
|
||||
getRandomRoot: (user_num, root)->
|
||||
root ?= @users[user_num].getSharedObject()
|
||||
root ?= @users[user_num]
|
||||
types = @users[user_num].types
|
||||
if _.random(0,1) is 1 # take root
|
||||
root
|
||||
@@ -98,7 +98,7 @@ describe "JsonFramework", ->
|
||||
###
|
||||
|
||||
it "has a JsonTypeWrapper", ->
|
||||
y = this.yTest.getSomeUser().getSharedObject()
|
||||
y = this.yTest.getSomeUser()
|
||||
y.val('x',"dtrn", 'immutable')
|
||||
y.val('set',{x:"x"}, 'immutable')
|
||||
w = y.value
|
||||
@@ -127,7 +127,7 @@ describe "JsonFramework", ->
|
||||
u1.engine.applyOps ops2
|
||||
u2.engine.applyOps ops1
|
||||
expect(test.getContent(0)).to.equal(@yTest.getContent(1))
|
||||
|
||||
|
||||
it "can handle creaton of complex json (1)", ->
|
||||
@yTest.users[0].val('a', 'q')
|
||||
@yTest.users[2].val('a', 't')
|
||||
|
||||
@@ -13,12 +13,12 @@ module.exports = class Test
|
||||
constructor: (@name_suffix = "")->
|
||||
@number_of_test_cases_multiplier = 1
|
||||
@repeat_this = 1 * @number_of_test_cases_multiplier
|
||||
@doSomething_amount = 50 + @number_of_test_cases_multiplier
|
||||
@number_of_engines = 5 + @number_of_test_cases_multiplier - 1
|
||||
|
||||
@time = 0
|
||||
@ops = 0
|
||||
@time_now = 0
|
||||
@doSomething_amount = 50 * @number_of_test_cases_multiplier
|
||||
@number_of_engines = 4 + @number_of_test_cases_multiplier - 1
|
||||
|
||||
@time = 0 # denotes to the time when run was started
|
||||
@ops = 0 # number of operations (used with @time)
|
||||
@time_now = 0 # current time
|
||||
|
||||
@debug = false
|
||||
|
||||
@@ -33,7 +33,7 @@ module.exports = class Test
|
||||
@users.push u
|
||||
@flushAll()
|
||||
|
||||
# is called by implementing class
|
||||
# is called by implementing class
|
||||
makeNewUser: (user)->
|
||||
user.HB.setManualGarbageCollect()
|
||||
user
|
||||
@@ -85,11 +85,6 @@ module.exports = class Test
|
||||
ops1 = y.deleteText pos, length
|
||||
undefined
|
||||
types : [types.WordType]
|
||||
,
|
||||
f : (y)=> # REPLACE TEXT
|
||||
y.replaceText @getRandomText()
|
||||
null
|
||||
types: [types.WordType]
|
||||
]
|
||||
getRandomRoot: (user_num)->
|
||||
throw new Error "overwrite me!"
|
||||
|
||||
@@ -7,7 +7,7 @@ _ = require("underscore")
|
||||
|
||||
chai.use(sinonChai)
|
||||
|
||||
Y = require "../lib/index"
|
||||
Yatta = require "../lib/Yatta"
|
||||
Connector = require "../bower_components/connector/lib/test-connector/test-connector.coffee"
|
||||
|
||||
Test = require "./TestSuite"
|
||||
@@ -15,14 +15,17 @@ class TextTest extends Test
|
||||
|
||||
type: "TextTest"
|
||||
|
||||
makeNewUser: (user, conn)->
|
||||
super new Y.TextFramework user, conn
|
||||
makeNewUser: (userId)->
|
||||
conn = new Connector userId
|
||||
y = new Yatta conn
|
||||
y.val("TextTest","","mutable")
|
||||
y
|
||||
|
||||
getRandomRoot: (user_num)->
|
||||
@users[user_num].getSharedObject()
|
||||
@users[user_num].val("TextTest")
|
||||
|
||||
getContent: (user_num)->
|
||||
@users[user_num].val()
|
||||
@users[user_num].val("TextTest").val()
|
||||
|
||||
describe "TextFramework", ->
|
||||
beforeEach (done)->
|
||||
@@ -33,15 +36,83 @@ describe "TextFramework", ->
|
||||
@test_user = @yTest.makeNewUser 'test_user', test_user_connector
|
||||
test_user_connector.join @users[0].connector
|
||||
done()
|
||||
|
||||
|
||||
it "simple multi-char insert", ->
|
||||
u = @yTest.users[0]
|
||||
u = @yTest.users[0].val("TextTest")
|
||||
u.insertText 0, "abc"
|
||||
u = @yTest.users[1]
|
||||
u = @yTest.users[1].val("TextTest")
|
||||
u.insertText 0, "xyz"
|
||||
@yTest.compareAll()
|
||||
expect(u.val()).to.equal("abcxyz")
|
||||
|
||||
it "Observers work on shared Text (insert type observers, local and foreign)", ->
|
||||
u = @yTest.users[0].val("TextTest","my awesome Text").val("TextTest")
|
||||
@yTest.flushAll()
|
||||
last_task = null
|
||||
observer1 = (changes)->
|
||||
expect(changes.length).to.equal(1)
|
||||
change = changes[0]
|
||||
expect(change.type).to.equal("insert")
|
||||
expect(change.object).to.equal(u)
|
||||
expect(change.value).to.equal("a")
|
||||
expect(change.position).to.equal(1)
|
||||
expect(change.changed_by).to.equal('0')
|
||||
last_task = "observer1"
|
||||
u.observe observer1
|
||||
u.insertText 1, "a"
|
||||
expect(last_task).to.equal("observer1")
|
||||
u.unobserve observer1
|
||||
|
||||
observer2 = (changes)->
|
||||
expect(changes.length).to.equal(1)
|
||||
change = changes[0]
|
||||
expect(change.type).to.equal("insert")
|
||||
expect(change.object).to.equal(u)
|
||||
expect(change.value).to.equal("x")
|
||||
expect(change.position).to.equal(0)
|
||||
expect(change.changed_by).to.equal('1')
|
||||
last_task = "observer2"
|
||||
u.observe observer2
|
||||
v = @yTest.users[1].val("TextTest")
|
||||
v.insertText 0, "x"
|
||||
@yTest.flushAll()
|
||||
expect(last_task).to.equal("observer2")
|
||||
u.unobserve observer2
|
||||
|
||||
it "Observers work on shared Text (delete type observers, local and foreign)", ->
|
||||
u = @yTest.users[0].val("TextTest","my awesome Text").val("TextTest")
|
||||
@yTest.flushAll()
|
||||
last_task = null
|
||||
observer1 = (changes)->
|
||||
expect(changes.length).to.equal(1)
|
||||
change = changes[0]
|
||||
expect(change.type).to.equal("delete")
|
||||
expect(change.object).to.equal(u)
|
||||
expect(change.position).to.equal(1)
|
||||
expect(change.length).to.equal(1)
|
||||
expect(change.changed_by).to.equal('0')
|
||||
last_task = "observer1"
|
||||
u.observe observer1
|
||||
u.deleteText 1
|
||||
expect(last_task).to.equal("observer1")
|
||||
u.unobserve observer1
|
||||
|
||||
observer2 = (changes)->
|
||||
expect(changes.length).to.equal(1)
|
||||
change = changes[0]
|
||||
expect(change.type).to.equal("delete")
|
||||
expect(change.object).to.equal(u)
|
||||
expect(change.position).to.equal(0)
|
||||
expect(change.length).to.equal(0)
|
||||
expect(change.changed_by).to.equal('1')
|
||||
last_task = "observer2"
|
||||
u.observe observer2
|
||||
v = @yTest.users[1].val("TextTest")
|
||||
v.deleteText 0
|
||||
@yTest.flushAll()
|
||||
expect(last_task).to.equal("observer2")
|
||||
u.unobserve observer2
|
||||
|
||||
it "can handle many engines, many operations, concurrently (random)", ->
|
||||
@yTest.run()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user