diff --git a/project/app/src/main/java/org/owntracks/android/ui/welcome/WelcomeActivity.java b/project/app/src/main/java/org/owntracks/android/ui/welcome/WelcomeActivity.java index 123c817bc8..9ab5be895f 100644 --- a/project/app/src/main/java/org/owntracks/android/ui/welcome/WelcomeActivity.java +++ b/project/app/src/main/java/org/owntracks/android/ui/welcome/WelcomeActivity.java @@ -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() { diff --git a/project/app/src/test/java/org/owntracks/android/robolectric/WelcomeActivityTest.java b/project/app/src/test/java/org/owntracks/android/robolectric/WelcomeActivityTest.java index 359991ee7f..6cc8b508ae 100644 --- a/project/app/src/test/java/org/owntracks/android/robolectric/WelcomeActivityTest.java +++ b/project/app/src/test/java/org/owntracks/android/robolectric/WelcomeActivityTest.java @@ -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; @@ -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(); @@ -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());