Skip to content

Commit

Permalink
Improved unit tests to cover button states for #630
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Rust committed Dec 9, 2018
1 parent edb78fb commit d7fc7cd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public void showFragment(int position) {
binding.viewPager.setCurrentItem(position);

welcomeAdapter.getFragment(position).onShowFragment();
viewModel.setNextEnabled(welcomeAdapter.getFragment(position).isNextEnabled());
viewModel.setDoneEnabled(position == welcomeAdapter.getLastItemPosition());
setNextEnabled(welcomeAdapter.getFragment(position).isNextEnabled());
setDoneEnabled(position == welcomeAdapter.getLastItemPosition());
}

private void buildPagerIndicator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static android.os.Build.VERSION_CODES.M;
import static android.os.Build.VERSION_CODES.P;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.robolectric.shadows.ShadowView.clickOn;
Expand Down Expand Up @@ -82,19 +83,24 @@ public void setup() {
@Test
@Config(minSdk = M)
public void DoneButtonShouldStartMapActivityOnVersionWithBackgroundRestriction() {
// Shows welcome
assertEquals(View.VISIBLE, welcomeActivity.findViewById(R.id.btn_next).getVisibility());
assertEquals(View.GONE, welcomeActivity.findViewById(R.id.done).getVisibility());
assertTrue(welcomeActivity.findViewById(R.id.btn_next).isEnabled());
clickOn(welcomeActivity.findViewById(R.id.btn_next));

// Shows Restrictions
assertEquals(View.VISIBLE, welcomeActivity.findViewById(R.id.btn_next).getVisibility());
assertEquals(View.GONE, welcomeActivity.findViewById(R.id.done).getVisibility());
assertTrue(welcomeActivity.findViewById(R.id.btn_next).isEnabled());
clickOn(welcomeActivity.findViewById(R.id.btn_next));

// Shows done
assertEquals(View.GONE, welcomeActivity.findViewById(R.id.btn_next).getVisibility());
assertEquals(View.VISIBLE, welcomeActivity.findViewById(R.id.done).getVisibility());

assertFalse(welcomeActivity.findViewById(R.id.btn_next).isEnabled());
assertTrue(welcomeActivity.findViewById(R.id.done).isEnabled());

//Pager is at the end. Next button should be hidden
assertEquals(View.GONE, welcomeActivity.findViewById(R.id.btn_next).getVisibility());

clickOn(welcomeActivity.findViewById(R.id.done));
Intent expectedIntent = new Intent(welcomeActivity, MapActivity.class);
Intent actualIntent = ShadowApplication.getInstance().getNextStartedActivity();
Expand All @@ -104,16 +110,19 @@ public void DoneButtonShouldStartMapActivityOnVersionWithBackgroundRestriction()
@Test
@Config(maxSdk = LOLLIPOP_MR1)
public void DoneButtonShouldStartMapActivityOnVersionWithoutBackgroundRestriction() {
// Shows welcome
assertEquals(View.VISIBLE, welcomeActivity.findViewById(R.id.btn_next).getVisibility());
assertEquals(View.GONE, welcomeActivity.findViewById(R.id.done).getVisibility());
assertTrue(welcomeActivity.findViewById(R.id.btn_next).isEnabled());
clickOn(welcomeActivity.findViewById(R.id.btn_next));

// Shows Done
assertEquals(View.GONE, welcomeActivity.findViewById(R.id.btn_next).getVisibility());
assertEquals(View.VISIBLE, welcomeActivity.findViewById(R.id.done).getVisibility());
assertFalse(welcomeActivity.findViewById(R.id.btn_next).isEnabled());
assertTrue(welcomeActivity.findViewById(R.id.done).isEnabled());

//Pager is at the end. Next button should be hidden
assertEquals(View.GONE, welcomeActivity.findViewById(R.id.btn_next).getVisibility());

clickOn(welcomeActivity.findViewById(R.id.done));

Intent expectedIntent = new Intent(welcomeActivity, MapActivity.class);
Intent actualIntent = ShadowApplication.getInstance().getNextStartedActivity();
assertEquals(expectedIntent.getComponent(), actualIntent.getComponent());
Expand Down

0 comments on commit d7fc7cd

Please sign in to comment.