Skip to content

Commit

Permalink
fix: cerebral@0.34 event object support for predefined signals
Browse files Browse the repository at this point in the history
fixes #95
  • Loading branch information
Guria committed Jun 21, 2016
1 parent 37eeb03 commit a69b327
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 12 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function Router (routesConfig, options) {
if (!rememberedUrl) setTimeout(setRememberedUrl)

var route = signal.route
var input = event.signal.input || {}
var input = event.signal.input || event.payload || {}
rememberedUrl = options.baseUrl + urlMapper.stringify(route, input)
}
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"pretest": "standard",
"test": "nodeunit tests && npm i cerebral@^0.34.0-rc.5 && nodeunit tests",
"test": "nodeunit tests && npm i cerebral@^0.34.0 && nodeunit tests",
"posttest": "npm i",
"coverage": "nyc --reporter=lcov --reporter=text npm run test",
"postcoverage": "cat ./coverage/lcov.info | coveralls",
Expand Down Expand Up @@ -64,7 +64,7 @@
"validate-commit-msg": "^2.5.0"
},
"peerDependencies": {
"cerebral": "^0.33.31 || ^0.34.0-0"
"cerebral": "^0.33.31 || ^0.34.0"
},
"nyc": {
"exclude": [
Expand Down
69 changes: 60 additions & 9 deletions tests/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,64 @@ module.exports = {
this.controller.getSignals().test()
},

'should not trigger on modulesLoaded if url was remembered': function (test) {
'should restore url if remembering occured cerebral@0.33': function (test) {
test.expect(1)
var controller = this.controller

controller.addSignals({
foo: [ function checkAction () { test.ok(true) } ],
bar: [ function checkAction () { test.ok(true) } ],
baz: [ function checkAction () { test.ok(true) } ]
foo: [ function checkAction () { test.ok(false) } ]
})

controller.on('modulesLoaded', function () {
setTimeout(function () {
test.equals(addressbar.value.replace(addressbar.origin, ''), '/foo/bar?baz=baz')
test.done()
})
})

controller.addModules({
router: Router({
'/foo/:bar': 'foo'
}, { mapper: { query: true } }),
devtools: function () {
controller.emit('predefinedSignal', { signal: { name: 'foo', input: { bar: 'bar', baz: 'baz' } } })
}
})
},

'should restore url if remembering occured cerebral@0.34': function (test) {
test.expect(1)
var controller = this.controller

controller.addSignals({
foo: [ function checkAction () { test.ok(false) } ]
})

controller.on('modulesLoaded', function () {
setTimeout(function () {
test.equals(addressbar.value.replace(addressbar.origin, ''), '/foo/bar?baz=baz')
test.done()
})
})

controller.addModules({
router: Router({
'/foo/:bar': 'foo'
}, { mapper: { query: true } }),
devtools: function () {
controller.emit('predefinedSignal', { signal: { name: 'foo' }, payload: { bar: 'bar', baz: 'baz' } })
}
})
},

'should not run initial trigger on modulesLoaded if there was remembering': function (test) {
test.expect(1)
var controller = this.controller

controller.addSignals({
foo: [ function checkAction () { test.ok(false) } ],
bar: [ function checkAction () { test.ok(false) } ],
baz: [ function checkAction () { test.ok(false) } ]
})

controller.on('modulesLoaded', function () {
Expand All @@ -248,22 +298,23 @@ module.exports = {
}),
devtools: function () {
controller.emit('predefinedSignal', { signal: { name: 'foo' } })
controller.emit('predefinedSignal', { signal: { name: 'baz' } })
controller.emit('predefinedSignal', { signal: { name: 'bar' } })
controller.emit('predefinedSignal', { signal: { name: 'baz' } })
}
})
},

'should not run delayed trigger if url was remembered': function (test) {
test.expect(1)
'should not run delayed initial trigger if there was remembering': function (test) {
test.expect(2)
var controller = this.controller

controller.addSignals({
test: [ function checkAction () { test.ok(true) } ],
foo: [ function checkAction () { test.ok(true) } ],
test: [ function checkAction () { test.ok(false) } ],
foo: [ function checkAction () { test.ok(false) } ],
init1: [
[ function asyncAction (args) {
setTimeout(function () {
test.ok(true)
args.output()
}, 50)
} ]
Expand Down

0 comments on commit a69b327

Please sign in to comment.