-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Did the test, still working on the widget(creating a db)
- Loading branch information
Showing
19 changed files
with
415 additions
and
7 deletions.
There are no files selected for viewing
Binary file not shown.
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
34 changes: 34 additions & 0 deletions
34
app/src/androidTest/java/com/wordpress/ayo218/bakingapp/BaseTest.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,34 @@ | ||
package com.wordpress.ayo218.bakingapp; | ||
|
||
import android.support.test.espresso.IdlingRegistry; | ||
import android.support.test.espresso.IdlingResource; | ||
import android.support.test.rule.ActivityTestRule; | ||
|
||
import com.wordpress.ayo218.bakingapp.ui.activity.MainActivity; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
|
||
public abstract class BaseTest { | ||
protected BaseApplication baseApplication; | ||
protected IdlingResource idlingResource; | ||
|
||
@Rule | ||
public ActivityTestRule<MainActivity> mainActivityActivityTestRule = new ActivityTestRule<>(MainActivity.class); | ||
|
||
@Before | ||
public void registerIdlingResource() { | ||
baseApplication = (BaseApplication) mainActivityActivityTestRule.getActivity().getApplicationContext(); | ||
idlingResource = baseApplication.getIdlingResources(); | ||
// Register Idling Resources | ||
IdlingRegistry.getInstance().register(idlingResource); | ||
} | ||
|
||
@After | ||
public void unregisterIdlingResource() { | ||
if (idlingResource != null) { | ||
IdlingRegistry.getInstance().unregister(idlingResource); | ||
} | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
app/src/androidTest/java/com/wordpress/ayo218/bakingapp/RecipeTest.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,107 @@ | ||
package com.wordpress.ayo218.bakingapp; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.support.test.espresso.contrib.RecyclerViewActions; | ||
import android.support.test.espresso.intent.Intents; | ||
|
||
import static android.support.test.espresso.assertion.ViewAssertions.matches; | ||
import static android.support.test.espresso.intent.Intents.intended; | ||
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent; | ||
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasExtraWithKey; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import com.wordpress.ayo218.bakingapp.model.Recipes; | ||
import com.wordpress.ayo218.bakingapp.ui.activity.RecipeDetailActivity; | ||
import com.wordpress.ayo218.bakingapp.ui.activity.RecipeStepsDetail; | ||
import com.wordpress.ayo218.bakingapp.utils.Prefs; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static android.support.test.espresso.action.ViewActions.click; | ||
import static android.support.test.espresso.Espresso.onView; | ||
import static android.support.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed; | ||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withId; | ||
import static junit.framework.Assert.assertNotNull; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class RecipeTest extends BaseTest{ | ||
|
||
public static void getMeToRecipeInfo(int recipePosition) { | ||
onView(withId(R.id.main_recipes_recyclerview)) | ||
.perform(RecyclerViewActions.actionOnItemAtPosition(recipePosition, click())); | ||
} | ||
|
||
public static void selectRecipeStep(int recipeStep) { | ||
onView(withId(R.id.recipe_step_list_recycler)) | ||
.perform(RecyclerViewActions.actionOnItemAtPosition(recipeStep, click())); | ||
} | ||
|
||
@Test | ||
public void clickRecyclerITemWithKey(){ | ||
Intents.init(); | ||
getMeToRecipeInfo(0); | ||
|
||
intended(hasExtraWithKey(RecipeDetailActivity.RECIPE_KEY)); | ||
Intents.release(); | ||
} | ||
|
||
@Test | ||
public void clickOnRecyclerViewItem_opensRecipeInfoActivity() { | ||
|
||
getMeToRecipeInfo(0); | ||
|
||
onView(withId(R.id.ingredients_txt)) | ||
.check(matches(isDisplayed())); | ||
|
||
onView(withId(R.id.recipe_step_list_recycler)) | ||
.check(matches(isDisplayed())); | ||
} | ||
|
||
@Test | ||
public void clickOnRecyclerViewStepItem_opensRecipeStepActivity_orFragment() { | ||
getMeToRecipeInfo(0); | ||
|
||
boolean twoPaneMode = baseApplication.getResources().getBoolean(R.bool.twoPaneMode); | ||
if (!twoPaneMode) { | ||
// Checks if the keys are present and the intent launched is RecipeStepDetailActivity | ||
Intents.init(); | ||
selectRecipeStep(1); | ||
intended(hasComponent(RecipeStepsDetail.class.getName())); | ||
intended(hasExtraWithKey(RecipeDetailActivity.RECIPE_KEY)); | ||
intended(hasExtraWithKey(RecipeStepsDetail.STEP_SELECTED_KEY)); | ||
Intents.release(); | ||
|
||
// Check TabLayout | ||
onView(withId(R.id.tabs)) | ||
.check(matches(isCompletelyDisplayed())); | ||
} else { | ||
selectRecipeStep(1); | ||
|
||
onView(withId(R.id.exoplayer_view)) | ||
.check(matches(isDisplayed())); | ||
} | ||
} | ||
|
||
@Test | ||
public void checkAddWidgetButtonFunctionality() { | ||
// Clear the preferences values | ||
baseApplication.getSharedPreferences(Prefs.PREF, Context.MODE_PRIVATE).edit() | ||
.clear() | ||
.commit(); | ||
|
||
getMeToRecipeInfo(0); | ||
|
||
onView(withId(R.id.add_widget)) | ||
.check(matches(isDisplayed())) | ||
.perform(click()); | ||
|
||
// Get the recipe base64 string from the sharedPrefs | ||
Recipes recipe = Prefs.loadRecipe(baseApplication); | ||
|
||
// Assert recipe is not null | ||
assertNotNull(recipe); | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
app/src/main/java/com/wordpress/ayo218/bakingapp/AppDatabase.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,30 @@ | ||
package com.wordpress.ayo218.bakingapp; | ||
|
||
import android.arch.persistence.room.Database; | ||
import android.arch.persistence.room.Room; | ||
import android.arch.persistence.room.RoomDatabase; | ||
import android.content.Context; | ||
|
||
import com.wordpress.ayo218.bakingapp.model.Recipes; | ||
|
||
@Database(entities = Recipes.class, version = 1, exportSchema = false) | ||
public abstract class AppDatabase extends RoomDatabase { | ||
|
||
private static final Object LOCK = new Object(); | ||
private static final String DATABASE_TABLE = "favoriteDB"; | ||
private static AppDatabase database; | ||
|
||
public static AppDatabase getsInstance(Context context) { | ||
if (database == null) { | ||
synchronized (LOCK) { | ||
database = Room.databaseBuilder(context.getApplicationContext(), | ||
AppDatabase.class, AppDatabase.DATABASE_TABLE) | ||
.build(); | ||
} | ||
} | ||
|
||
return database; | ||
} | ||
|
||
public abstract FavoriteDao favoriteDao(); | ||
} |
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/wordpress/ayo218/bakingapp/AppExecutors.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,56 @@ | ||
package com.wordpress.ayo218.bakingapp; | ||
|
||
import android.os.Handler; | ||
import android.os.Looper; | ||
import android.support.annotation.NonNull; | ||
|
||
import java.util.concurrent.Executor; | ||
import java.util.concurrent.Executors; | ||
|
||
public class AppExecutors { | ||
|
||
private static final Object LOCK = new Object(); | ||
private static AppExecutors sInstance; | ||
private final Executor diskIO; | ||
private final Executor mainThread; | ||
private final Executor networkIO; | ||
|
||
|
||
public AppExecutors(Executor diskIO, Executor mainThread, Executor networkIO) { | ||
this.diskIO = diskIO; | ||
this.mainThread = mainThread; | ||
this.networkIO = networkIO; | ||
} | ||
|
||
public static AppExecutors getsInstance() { | ||
if (sInstance == null) { | ||
synchronized (LOCK) { | ||
sInstance = new AppExecutors(Executors.newSingleThreadExecutor(), | ||
Executors.newFixedThreadPool(3), | ||
new MainThreadExecutor()); | ||
} | ||
} | ||
return sInstance; | ||
} | ||
|
||
public Executor diskIO() { | ||
return diskIO; | ||
} | ||
|
||
public Executor mainThread() { | ||
return mainThread; | ||
} | ||
|
||
public Executor networkIO() { | ||
return networkIO; | ||
} | ||
|
||
private static class MainThreadExecutor implements Executor { | ||
private Handler mainThreadHandler = new Handler(Looper.getMainLooper()); | ||
|
||
@Override | ||
public void execute(@NonNull Runnable command) { | ||
mainThreadHandler.post(command); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
app/src/main/java/com/wordpress/ayo218/bakingapp/BaseApplication.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,36 @@ | ||
package com.wordpress.ayo218.bakingapp; | ||
|
||
import android.app.Application; | ||
import android.support.annotation.VisibleForTesting; | ||
import android.support.test.espresso.IdlingResource; | ||
|
||
import com.wordpress.ayo218.bakingapp.idlingResources.RecipeIdlingResources; | ||
|
||
public class BaseApplication extends Application { | ||
|
||
private RecipeIdlingResources idlingResources; | ||
|
||
@VisibleForTesting | ||
private IdlingResource initialize(){ | ||
if (idlingResources == null) { | ||
idlingResources = new RecipeIdlingResources(); | ||
} | ||
return idlingResources; | ||
} | ||
|
||
public BaseApplication(){ | ||
if (BuildConfig.DEBUG) { | ||
initialize(); | ||
} | ||
} | ||
|
||
public void setIdleState(boolean state) { | ||
if (idlingResources != null) { | ||
idlingResources.setIsdleNow(state); | ||
} | ||
} | ||
|
||
public RecipeIdlingResources getIdlingResources() { | ||
return idlingResources; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/wordpress/ayo218/bakingapp/FavoriteDao.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,16 @@ | ||
package com.wordpress.ayo218.bakingapp; | ||
|
||
import android.arch.persistence.room.Dao; | ||
import android.arch.persistence.room.Insert; | ||
import android.arch.persistence.room.OnConflictStrategy; | ||
|
||
import com.wordpress.ayo218.bakingapp.model.Recipes; | ||
|
||
@Dao | ||
public interface FavoriteDao { | ||
|
||
|
||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
void insertRecipe(Recipes recipes); | ||
} |
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
36 changes: 36 additions & 0 deletions
36
app/src/main/java/com/wordpress/ayo218/bakingapp/idlingResources/RecipeIdlingResources.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,36 @@ | ||
package com.wordpress.ayo218.bakingapp.idlingResources; | ||
|
||
import android.support.annotation.Nullable; | ||
import android.support.test.espresso.IdlingResource; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
public class RecipeIdlingResources implements IdlingResource { | ||
|
||
@Nullable | ||
private volatile ResourceCallback callback; | ||
|
||
private AtomicBoolean isdleNow = new AtomicBoolean(true); | ||
|
||
@Override | ||
public String getName() { | ||
return this.getClass().getName(); | ||
} | ||
|
||
@Override | ||
public boolean isIdleNow() { | ||
return isdleNow.get(); | ||
} | ||
|
||
@Override | ||
public void registerIdleTransitionCallback(ResourceCallback callback) { | ||
this.callback = callback; | ||
} | ||
|
||
public void setIsdleNow(boolean idleNow){ | ||
isdleNow.set(idleNow); | ||
if (idleNow && callback != null) { | ||
callback.onTransitionToIdle(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.