Permalink
Browse files

Add regression test for Navigator push and replace with nested dispatch

  • Loading branch information...
1 parent ed60ce1 commit 81b1f18ac669c456e80f029f105d056114b2cd39 Kristian PD committed Aug 21, 2012
Showing with 32 additions and 1 deletion.
  1. +32 −1 tests/batman/navigator/navigator_test.coffee
View
33 tests/batman/navigator/navigator_test.coffee
@@ -1,7 +1,6 @@
QUnit.module 'Batman.Navigator'
setup: ->
-
test "normalizePath(segments...) joins the segments with slashes, prepends a slash if necessary, and removes final trailing slashes", ->
equal Batman.Navigator.normalizePath(''), '/'
equal Batman.Navigator.normalizePath('','foo','','bar'), '/foo/bar'
@@ -11,3 +10,35 @@ test "normalizePath(segments...) joins the segments with slashes, prepends a sla
equal Batman.Navigator.normalizePath('foo','bar','baz'), '/foo/bar/baz'
equal Batman.Navigator.normalizePath('foo','//bar/baz/'), '/foo//bar/baz'
equal Batman.Navigator.normalizePath('foo','bar/baz//'), '/foo/bar/baz'
+
+test "push with dispatch that includes nested push only pushes inner state", ->
+ navigator = new Batman.Navigator
+ navigator.app = new Batman.Object
+ dispatcher:
+ pathFromParams: (params) -> params
+ dispatch: (params) ->
+ navigator.push '/redirected' if params is '/foo'
+ params
+
+ pushSpy = navigator.pushState = createSpy()
+ navigator.push '/foo'
+
+ ok pushSpy.callCount, 1
+ deepEqual pushSpy.lastCallArguments, [null, '', '/redirected']
+
+test "replace with dispatch that includes nested replace only replaces inner state", ->
+ navigator = new Batman.Navigator
+ navigator.app = new Batman.Object
+ dispatcher:
+ pathFromParams: (params) -> params
+ dispatch: (params) ->
+ navigator.replace '/redirected' if params is '/foo'
+ params
+
+ replaceSpy = navigator.replaceState = createSpy()
+ navigator.replace '/foo'
+
+ ok replaceSpy.callCount, 1
+ deepEqual replaceSpy.lastCallArguments, [null, '', '/redirected']
+
+

0 comments on commit 81b1f18

Please sign in to comment.