Skip to content

Commit

Permalink
fix functional tests for batcher
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 24, 2013
1 parent c7b2d9c commit 7fc537a
Show file tree
Hide file tree
Showing 17 changed files with 203 additions and 130 deletions.
8 changes: 5 additions & 3 deletions examples/todomvc/js/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ function runBenchmark () {
function toggle () {
addTime = now() - last
var checkboxes = document.querySelectorAll('.toggle')
for (var i = 0; i < checkboxes.length; i++) {
checkboxes[i].click()
}
//for (var j = 0; j < 5; j++) {
for (var i = 0; i < checkboxes.length; i++) {
checkboxes[i].click()
}
//}
last = now()
setTimeout(remove, 0)
}
Expand Down
8 changes: 5 additions & 3 deletions src/batcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ exports.queue = function (binding, method) {

function flush () {
for (var i = 0; i < queue.length; i++) {
var task = queue[i]
task.binding['_' + task.method]()
has[task.binding.id] = false
var task = queue[i],
b = task.binding
if (b.unbound) continue
b['_' + task.method]()
has[b.id] = false
}
reset()
}
Expand Down
6 changes: 6 additions & 0 deletions src/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function Binding (compiler, key, isExp, isFn) {
this.instances = []
this.subs = []
this.deps = []
this.unbound = false
}

var BindingProto = Binding.prototype
Expand Down Expand Up @@ -70,6 +71,11 @@ BindingProto.pub = function () {
* Unbind the binding, remove itself from all of its dependencies
*/
BindingProto.unbind = function () {
// Indicate this has been unbound.
// It's possible this binding will be in
// the batcher's flush queue when its owner
// compiler has already been destroyed.
this.unbound = true
var i = this.instances.length
while (i--) {
this.instances[i].unbind()
Expand Down
15 changes: 7 additions & 8 deletions src/directives/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ module.exports = {
try {
cursorPos = el.selectionStart
} catch (e) {}
// `input` event has weird updating issue with
// International (e.g. Chinese) input methods,
// have to use a Timeout to hack around it...
setTimeout(function () {
self.vm.$set(self.key, el[attr])
self.vm.$set(self.key, el[attr])
// since updates are async
// we need to reset cursor position async too
utils.nextTick(function () {
if (cursorPos !== undefined) {
el.setSelectionRange(cursorPos, cursorPos)
}
}, 0)
})
}
: function () {
// no filters, don't let it trigger update()
Expand All @@ -63,9 +62,9 @@ module.exports = {
if (isIE9) {
self.onCut = function () {
// cut event fires before the value actually changes
setTimeout(function () {
utils.nextTick(function () {
self.set()
}, 0)
})
}
self.onDel = function (e) {
if (e.keyCode === 46 || e.keyCode === 8) {
Expand Down
21 changes: 10 additions & 11 deletions test/functional/specs/extend.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
casper.test.begin('Encapsulation & Inheritance', 8, function (test) {

casper
.start('./fixtures/extend.html', function () {

.start('./fixtures/extend.html')
.then(function () {
test.assertSelectorHasText('.dir', 'directive works')
test.assertSelectorHasText('.filter', 'filter works')
test.assertSelectorHasText('.partial', 'partial works')
test.assertSelectorHasText('.vm', 'component works')
test.assertSelectorHasText('.vm-w-model', 'component with model works')

test.assertSelectorHasText('#log', 'T created T ready T created C created T ready C ready', 'hook inheritance works')
test.assertSelectorHasText('.cvm', 'component works', 'Child should have access to Parent options')

this.evaluate(function () {
test.vmData = {
selfMsg: 'replacing $data ',
msg: 'also works'
}
})

})
.thenEvaluate(function () {
test.vmData = {
selfMsg: 'replacing $data ',
msg: 'also works'
}
})
.then(function () {
test.assertSelectorHasText('.vm-w-model', 'replacing $data also works')
})
.run(function () {
Expand Down
10 changes: 6 additions & 4 deletions test/functional/specs/forms.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
casper.test.begin('Forms', 10, function (test) {

casper
.start('./fixtures/forms.html', function () {

.start('./fixtures/forms.html')
.then(function () {
// test initial value binding
test.assertField('text', 'some text')
test.assertField('checkbox', true)
test.assertField('radio', 'b')
test.assertField('select', 'b')
test.assertField('textarea', 'more text')

})
.then(function () {
this.fill('#forms', {
'text': 'changed text',
'checkbox': false,
'radio': 'a',
'select': 'a',
'textarea': 'more changed text'
})

})
.then(function () {
test.assertSelectorHasText('.text', 'changed text')
test.assertSelectorHasText('.checkbox', 'false')
test.assertSelectorHasText('.radio', 'a')
Expand Down
46 changes: 25 additions & 21 deletions test/functional/specs/nested-props.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,54 @@
casper.test.begin('Nested Properties', 20, function (test) {

casper
.start('./fixtures/nested-props.html', function () {

.start('./fixtures/nested-props.html')
.then(function () {
test.assertSelectorHasText('h1 span', '')
test.assertSelectorHasText('h2 span', '555')
test.assertSelectorHasText('h3 span', 'Yoyoyo555')

this.click('.one')
})
.thenClick('.one', function () {
test.assertSelectorHasText('h1 span', 'one')
test.assertSelectorHasText('h2 span', '1')
test.assertSelectorHasText('h3 span', 'Yoyoyoone1')

this.click('.two')
})
.thenClick('.two', function () {
test.assertSelectorHasText('h1 span', 'two')
test.assertSelectorHasText('h2 span', '2')
test.assertSelectorHasText('h3 span', 'Yoyoyotwo2')

this.click('.three')
})
.thenClick('.three', function () {
test.assertSelectorHasText('h1 span', 'three')
test.assertSelectorHasText('h2 span', '3')
test.assertSelectorHasText('h3 span', 'Yoyoyothree3')

})
.then(function () {
this.fill('#form', {
msg: 'Oh yeah '
})
})
.then(function () {
test.assertSelectorHasText('h3 span', 'Oh yeah three3')

// hidden data variables
// i.e. nested under an object, not explicitly
// bound in the template, but is depended upon
// by an expression or a computed property
})
// hidden data variables
// i.e. nested under an object, not explicitly
// bound in the template, but is depended upon
// by an expression or a computed property
.then(function () {
test.assertSelectorHasText('.hidden', '3')
this.click('.four')
})
.thenClick('.four', function () {
test.assertSelectorHasText('.hidden', '4')

// set a nested object to {}
this.click('.empty1')
})
// set a nested object to {}
.thenClick('.empty1', function () {
test.assertSelectorHasText('h1 span', '')
test.assertSelectorHasText('h3 span', 'Oh yeah 3')

this.click('.empty2')
})
.thenClick('.empty2', function () {
test.assertSelectorHasText('h1 span', '')
test.assertSelectorHasText('h2 span', '')
test.assertSelectorHasText('h3 span', 'Oh yeah ')

})
.run(function () {
test.done()
Expand Down
24 changes: 17 additions & 7 deletions test/functional/specs/nested-repeat.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
casper.test.begin('Nested Repeat', 12, function (test) {

casper
.start('./fixtures/nested-repeat.html', function () {

.start('./fixtures/nested-repeat.html')
.then(function () {
var i, j

for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
test.assertSelectorHasText(
Expand All @@ -13,10 +12,13 @@ casper.test.begin('Nested Repeat', 12, function (test) {
)
}
}

})
.then(function () {
this.click('#b0')
this.click('#b1')

})
.then(function () {
var i, j
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
test.assertSelectorHasText(
Expand All @@ -25,17 +27,25 @@ casper.test.begin('Nested Repeat', 12, function (test) {
)
}
}

})
.then(function () {
var i, j
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
this.click('#b' + i + '-' + j)
}
}
})
.then(function () {
var i, j
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
test.assertSelectorHasText(
'.list-' + i + ' .list-' + j,
i + '.' + j + ' : hi<-hi'
)
}
}

})
.run(function () {
test.done()
Expand Down
3 changes: 2 additions & 1 deletion test/functional/specs/nested-vms.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
casper.test.begin('Nested Viewmodels', 7, function (test) {

casper
.start('./fixtures/nested-vms.html', function () {
.start('./fixtures/nested-vms.html')
.then(function () {

test.assertSelectorHasText('.ancestor', 'Andy Johnson')
test.assertSelectorHasText('.jack', 'Jack, son of Andy')
Expand Down
44 changes: 24 additions & 20 deletions test/functional/specs/repeated-items.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,69 @@
casper.test.begin('Repeated Items', 41, function (test) {

casper
.start('./fixtures/repeated-items.html', function () {
.start('./fixtures/repeated-items.html')
.then(function () {

// initial values
test.assertSelectorHasText('.count', '3')
test.assertSelectorHasText('.item:nth-child(1)', '0 A')
test.assertSelectorHasText('.item:nth-child(2)', '1 B')
test.assertSelectorHasText('.item:nth-child(3)', '2 C')

this.click('.push')
})
.thenClick('.push', function () {
test.assertSelectorHasText('.count', '4')
test.assertSelectorHasText('.item:nth-child(4)', '3 0')

this.click('.shift')
})
.thenClick('.shift', function () {
test.assertSelectorHasText('.count', '3')
test.assertSelectorHasText('.item:nth-child(1)', '0 B')
test.assertSelectorHasText('.item:nth-child(2)', '1 C')
test.assertSelectorHasText('.item:nth-child(3)', '2 0')

this.click('.pop')
})
.thenClick('.pop', function () {
test.assertSelectorHasText('.count', '2')
test.assertSelectorHasText('.item:nth-child(1)', '0 B')
test.assertSelectorHasText('.item:nth-child(2)', '1 C')

this.click('.unshift')
})
.thenClick('.unshift', function () {
test.assertSelectorHasText('.count', '3')
test.assertSelectorHasText('.item:nth-child(1)', '0 1')
test.assertSelectorHasText('.item:nth-child(2)', '1 B')
test.assertSelectorHasText('.item:nth-child(3)', '2 C')

this.click('.splice')
})
.thenClick('.splice', function () {
test.assertSelectorHasText('.count', '4')
test.assertSelectorHasText('.item:nth-child(1)', '0 1')
test.assertSelectorHasText('.item:nth-child(2)', '1 2')
test.assertSelectorHasText('.item:nth-child(3)', '2 3')
test.assertSelectorHasText('.item:nth-child(4)', '3 C')

this.click('.remove')
})
.thenClick('.remove', function () {
test.assertSelectorHasText('.count', '3')
test.assertSelectorHasText('.item:nth-child(1)', '0 1')
test.assertSelectorHasText('.item:nth-child(2)', '1 2')
test.assertSelectorHasText('.item:nth-child(3)', '2 3')

this.click('.replace')
})
.thenClick('.replace', function () {
test.assertSelectorHasText('.count', '3')
test.assertSelectorHasText('.item:nth-child(1)', '0 1')
test.assertSelectorHasText('.item:nth-child(2)', '1 2')
test.assertSelectorHasText('.item:nth-child(3)', '2 4')

this.click('.reverse')
})
.thenClick('.reverse', function () {
test.assertSelectorHasText('.count', '3')
test.assertSelectorHasText('.item:nth-child(1)', '0 4')
test.assertSelectorHasText('.item:nth-child(2)', '1 2')
test.assertSelectorHasText('.item:nth-child(3)', '2 1')

this.click('.sort')
})
.thenClick('.sort', function () {
test.assertSelectorHasText('.count', '3')
test.assertSelectorHasText('.item:nth-child(1)', '0 1')
test.assertSelectorHasText('.item:nth-child(2)', '1 2')
test.assertSelectorHasText('.item:nth-child(3)', '2 4')

})
.then(function () {
// make sure things work on empty array
this.click('.pop')
this.click('.pop')
Expand All @@ -72,10 +75,11 @@ casper.test.begin('Repeated Items', 41, function (test) {
this.click('.sort')
this.click('.reverse')
this.click('.splice')
})
.then(function () {
test.assertSelectorHasText('.count', '2')
test.assertSelectorHasText('.item:nth-child(1)', '0 6')
test.assertSelectorHasText('.item:nth-child(2)', '1 7')

})
.run(function () {
test.done()
Expand Down
Loading

0 comments on commit 7fc537a

Please sign in to comment.