Skip to content

Commit

Permalink
refresh fragment if active
Browse files Browse the repository at this point in the history
this is needed not just for the last fragment in history, but for any other which is already active, and this time there is a route. we want to do this and update the fragment.
  • Loading branch information
Juan Mendez committed Nov 25, 2017
1 parent ee85f2f commit 1e0150e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
26 changes: 23 additions & 3 deletions shoeboxes/src/test/java/info/juanmendez/shoeboxes/RoutesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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) );
}
}

0 comments on commit 1e0150e

Please sign in to comment.