diff --git a/shoeboxes/src/main/java/info/juanmendez/shoeboxes/shoes/ShoeRack.java b/shoeboxes/src/main/java/info/juanmendez/shoeboxes/shoes/ShoeRack.java index 75f6c0a..e4ead7b 100644 --- a/shoeboxes/src/main/java/info/juanmendez/shoeboxes/shoes/ShoeRack.java +++ b/shoeboxes/src/main/java/info/juanmendez/shoeboxes/shoes/ShoeRack.java @@ -43,33 +43,27 @@ public boolean request(String route) { //going forward can mean also stepping back to a previous shoeModel if( ShoeUtils.isTagInRouteList(tag, history)){ - /** - * setting a shoeBox active twice means to refresh - */ - String lastRoute = history.get( history.size()-1); - - if( shoeBox.isActive() && ShoeUtils.isTagInRoute( tag, lastRoute ) ){ - - shoeBox.setActive(false); - - //lets update the route - history.set( history.size()-1, route ); - shoeBox.setActive(true); - return true; - } - for( int i = history.size()-1; i>= 0; i--){ if( !ShoeUtils.isTagInRoute( tag, history.get(i) ) ){ history.remove( i ); }else{ - //lets update the route history.set(i, route ); break; } } + /** + * setting a shoeBox active twice means to refresh + */ + if( shoeBox.isActive() && !ShoeUtils.getRouteParams(route).isEmpty() ){ + + shoeBox.setActive(false); + shoeBox.setActive(true); + return true; + } + }else{ //if parent is a Flow, then also include previous siblings diff --git a/shoeboxes/src/test/java/info/juanmendez/shoeboxes/BasicChildFragmentTest.java b/shoeboxes/src/test/java/info/juanmendez/shoeboxes/BasicChildFragmentTest.java index ae8d1d0..1b5e2e2 100644 --- a/shoeboxes/src/test/java/info/juanmendez/shoeboxes/BasicChildFragmentTest.java +++ b/shoeboxes/src/test/java/info/juanmendez/shoeboxes/BasicChildFragmentTest.java @@ -166,7 +166,8 @@ public void refreshTest() { shoeRack.suggest(tagB); shoeRack.request(tagB); - verify(shoeBoxB, times(1)).setActive(eq(false)); - verify(shoeBoxB, times(2)).setActive(eq(true)); + //we don't need to refresh if the same item is first suggested and then requested. + //unless there is a route then we refresh. ;) + verify(shoeBoxB, times(1)).setActive(eq(true)); } } \ No newline at end of file diff --git a/shoeboxes/src/test/java/info/juanmendez/shoeboxes/RoutesTest.java b/shoeboxes/src/test/java/info/juanmendez/shoeboxes/RoutesTest.java index b16b68b..0c45733 100644 --- a/shoeboxes/src/test/java/info/juanmendez/shoeboxes/RoutesTest.java +++ b/shoeboxes/src/test/java/info/juanmendez/shoeboxes/RoutesTest.java @@ -18,6 +18,9 @@ import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.powermock.api.mockito.PowerMockito.spy; /** @@ -184,16 +187,33 @@ public void testRouteFromPreviousShoeBox(){ ShoeBox shoeBoxC = ShoeBox.build(fragmentC); shoeRack = ShoeStorage.getRack( "test" ); + shoeRack.clearHistory(); shoeRack.populate(ShoeStack.build(shoeBoxA, shoeBoxB, shoeBoxC)); shoeRack.request( tagA ); shoeRack.request( tagB ); shoeRack.request( tagA + "/hello-world"); - assertEquals( shoeRack.getRouteParamsOnce(tagA), "hello-world"); - shoeRack.request( tagB + "/hello-world"); - assertEquals( shoeRack.getRouteParamsOnce(tagB), "hello-world"); + verify(fragmentA, times(2)).setActive(eq(true) ); + } + + @Test + public void testRoutesInShoeFlow(){ + + ShoeBox shoeBoxA = ShoeBox.build(fragmentA); + ShoeBox shoeBoxB = ShoeBox.build(fragmentB); + ShoeBox shoeBoxC = ShoeBox.build(fragmentC); + + shoeRack = ShoeStorage.getRack( "test" ); + shoeRack.clearHistory(); + shoeRack.populate(shoeBoxA, shoeBoxB, shoeBoxC); + + shoeRack.request( tagA ); + shoeRack.request( tagB ); + + shoeRack.request( tagA + "/hello-world"); + verify(fragmentA, times(2)).setActive(eq(true) ); } } \ No newline at end of file