This repository has been archived by the owner on Jan 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Available until API level 16 * Introduce Espresso tests * sign in flow * category display * quiz solving end to end * Improve animation behavior * Update README and screenshots
- Loading branch information
1 parent
ec66d1c
commit 79d6010
Showing
97 changed files
with
1,780 additions
and
378 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...droidTest/java/com/google/samples/apps/topeka/activity/CategorySelectionActivityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright 2015 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.samples.apps.topeka.activity; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
import android.test.suitebuilder.annotation.LargeTest; | ||
|
||
import com.google.samples.apps.topeka.R; | ||
import com.google.samples.apps.topeka.helper.PreferencesHelper; | ||
import com.google.samples.apps.topeka.model.Avatar; | ||
import com.google.samples.apps.topeka.model.Category; | ||
import com.google.samples.apps.topeka.model.Player; | ||
import com.google.samples.apps.topeka.persistence.TopekaDatabaseHelper; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import java.util.List; | ||
|
||
import static android.support.test.espresso.Espresso.onData; | ||
import static android.support.test.espresso.Espresso.onView; | ||
import static android.support.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu; | ||
import static android.support.test.espresso.action.ViewActions.click; | ||
import static android.support.test.espresso.assertion.ViewAssertions.matches; | ||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withId; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withText; | ||
import static junit.framework.Assert.assertFalse; | ||
import static org.hamcrest.Matchers.allOf; | ||
import static org.hamcrest.Matchers.instanceOf; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
@LargeTest | ||
public class CategorySelectionActivityTest { | ||
|
||
private Context mTargetContext; | ||
private List<Category> mCategories; | ||
|
||
@Rule | ||
public ActivityTestRule<CategorySelectionActivity> mActivityRule = | ||
new ActivityTestRule<CategorySelectionActivity>(CategorySelectionActivity.class) { | ||
|
||
@Override | ||
protected void beforeActivityLaunched() { | ||
PreferencesHelper.signOut(InstrumentationRegistry.getTargetContext()); | ||
} | ||
|
||
@Override | ||
protected Intent getActivityIntent() { | ||
mTargetContext = InstrumentationRegistry.getTargetContext(); | ||
final Player player = new Player("Zaphod", "B", Avatar.EIGHT); | ||
return CategorySelectionActivity.getStartIntent(mTargetContext, player); | ||
} | ||
}; | ||
|
||
@Before | ||
public void loadCategories() { | ||
mCategories = TopekaDatabaseHelper.getCategories(mTargetContext, false); | ||
} | ||
|
||
@Test | ||
public void allCategories_areDisplayed() { | ||
for (Category category : mCategories) { | ||
onData(allOf(is(instanceOf(Category.class)), is(category))) | ||
.inAdapterView(withId(R.id.categories)) | ||
.check(matches(isDisplayed())); | ||
} | ||
} | ||
|
||
@Test | ||
public void signOut() { | ||
openActionBarOverflowOrOptionsMenu(mTargetContext); | ||
onView(withText(R.string.sign_out)).perform(click()); | ||
assertFalse(PreferencesHelper.isSignedIn(mTargetContext)); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
app/src/androidTest/java/com/google/samples/apps/topeka/activity/SignInActivityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 2015 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.samples.apps.topeka.activity; | ||
|
||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
import android.test.suitebuilder.annotation.LargeTest; | ||
|
||
import com.google.samples.apps.topeka.R; | ||
import com.google.samples.apps.topeka.helper.PreferencesHelper; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static android.support.test.espresso.Espresso.onView; | ||
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard; | ||
import static android.support.test.espresso.action.ViewActions.typeText; | ||
import static android.support.test.espresso.assertion.ViewAssertions.matches; | ||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withId; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withText; | ||
import static org.hamcrest.Matchers.not; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
@LargeTest | ||
public class SignInActivityTest { | ||
|
||
private static final String TEST_FIRST_NAME = "Zaphod"; | ||
private static final String TEST_LAST_INITIAL = "B"; | ||
|
||
@Rule | ||
public ActivityTestRule<SignInActivity> mActivityRule = | ||
new ActivityTestRule<SignInActivity>(SignInActivity.class) { | ||
@Override | ||
protected void beforeActivityLaunched() { | ||
PreferencesHelper.signOut(InstrumentationRegistry.getTargetContext()); | ||
} | ||
}; | ||
|
||
@Before | ||
public void clearPreferences() throws Exception { | ||
PreferencesHelper.signOut(InstrumentationRegistry.getTargetContext()); | ||
} | ||
|
||
@Test | ||
public void checkFab_initiallyNotDisplayed() { | ||
onView(withId(R.id.done)).check(matches(not(isDisplayed()))); | ||
} | ||
|
||
@Test | ||
public void signIn_performSuccessful() { | ||
inputData(); | ||
onView(withId(R.id.done)).check(matches(isDisplayed())); | ||
} | ||
|
||
@Test | ||
public void signIn_withLongLastName() { | ||
inputData(); | ||
onView(withId(R.id.last_initial)).perform(typeText("somelongtext"), closeSoftKeyboard()); | ||
onView(withId(R.id.last_initial)).check(matches(withText(TEST_LAST_INITIAL))); | ||
} | ||
|
||
private void inputData() { | ||
onView(withId(R.id.first_name)).perform(typeText(TEST_FIRST_NAME), closeSoftKeyboard()); | ||
onView(withId(R.id.last_initial)).perform(typeText(TEST_LAST_INITIAL), closeSoftKeyboard()); | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
...c/androidTest/java/com/google/samples/apps/topeka/activity/quiz/BaseQuizActivityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* Copyright 2015 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.samples.apps.topeka.activity.quiz; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.espresso.Espresso; | ||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
import android.test.suitebuilder.annotation.LargeTest; | ||
|
||
import com.google.samples.apps.topeka.R; | ||
import com.google.samples.apps.topeka.activity.QuizActivity; | ||
import com.google.samples.apps.topeka.helper.PreferencesHelper; | ||
import com.google.samples.apps.topeka.helper.SolveQuizHelper; | ||
import com.google.samples.apps.topeka.model.Avatar; | ||
import com.google.samples.apps.topeka.model.Category; | ||
import com.google.samples.apps.topeka.model.Player; | ||
import com.google.samples.apps.topeka.model.quiz.Quiz; | ||
import com.google.samples.apps.topeka.persistence.TopekaDatabaseHelper; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import java.util.List; | ||
|
||
import static android.support.test.espresso.Espresso.onView; | ||
import static android.support.test.espresso.action.ViewActions.click; | ||
import static android.support.test.espresso.assertion.ViewAssertions.matches; | ||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withId; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withText; | ||
import static org.hamcrest.Matchers.allOf; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
@LargeTest | ||
public abstract class BaseQuizActivityTest { | ||
|
||
private List<Category> mCategories; | ||
@Rule | ||
public ActivityTestRule<QuizActivity> mActivityRule = | ||
new ActivityTestRule<QuizActivity>(QuizActivity.class) { | ||
@Override | ||
protected void beforeActivityLaunched() { | ||
Context targetContext = InstrumentationRegistry.getTargetContext(); | ||
PreferencesHelper.signOut(targetContext); | ||
TopekaDatabaseHelper.reset(targetContext); | ||
PreferencesHelper.writeToPreferences(targetContext, | ||
new Player("Zaphod", "B", Avatar.FIVE)); | ||
} | ||
|
||
@Override | ||
protected Intent getActivityIntent() { | ||
Context targetContext = InstrumentationRegistry.getTargetContext(); | ||
mCategories = TopekaDatabaseHelper.getCategories(targetContext, false); | ||
return QuizActivity.getStartIntent(targetContext, | ||
getCurrentCategory()); | ||
} | ||
}; | ||
|
||
abstract int getCategory(); | ||
|
||
@Before | ||
public void registerIdlingResources() { | ||
Espresso.registerIdlingResources(mActivityRule.getActivity().getCountingIdlingResource()); | ||
} | ||
|
||
@Test | ||
public void categoryName_isDisplayed() { | ||
onView(withText(getCurrentCategory().getName())).check(matches(isDisplayed())); | ||
} | ||
|
||
@Test | ||
public void category_solveCorrectly() { | ||
testCategory(); | ||
} | ||
|
||
protected void testCategory() { | ||
final Category category = getCurrentCategory(); | ||
onView(withId(R.id.fab_quiz)).perform(click()); | ||
for (Quiz quiz : category.getQuizzes()) { | ||
SolveQuizHelper.solveQuiz(quiz); | ||
onView(allOf(withId(R.id.submitAnswer), isDisplayed())) | ||
.check(matches(isDisplayed())) | ||
.perform(click()); | ||
} | ||
} | ||
|
||
private Category getCurrentCategory() { | ||
return mCategories.get(getCategory()); | ||
} | ||
|
||
@After | ||
public void unregisterIdlingResources() { | ||
Espresso.unregisterIdlingResources(mActivityRule.getActivity().getCountingIdlingResource()); | ||
} | ||
|
||
} |
Oops, something went wrong.