Skip to content

Commit

Permalink
set up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jojo Narte authored and Jojo Narte committed May 16, 2018
1 parent 5632385 commit 3a06166
Show file tree
Hide file tree
Showing 6 changed files with 284 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* This file is part of BBCT for Android.
*
* Copyright 2018 codeguru <[email protected]>
*
* BBCT for Android is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* BBCT for Android is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package bbct.android.common.navigation.test;

import android.support.test.espresso.Espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import bbct.android.common.R;
import bbct.android.lite.provider.LiteActivity;

import static android.support.test.InstrumentationRegistry.getInstrumentation;
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.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;

@RunWith(AndroidJUnit4.class)
public class NavigateBackPressFromAboutTest {
@Rule
public ActivityTestRule<LiteActivity> activityActivityTestRule = new ActivityTestRule<LiteActivity>(LiteActivity.class);

@Before
public void setUp() throws Exception {
activityActivityTestRule.getActivity()
.getSupportFragmentManager().beginTransaction();
}

@Test
public void testNavigateToAboutFragment() {
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());

String aboutTitle = getInstrumentation().getTargetContext().getString(R.string.about_title);
Espresso.pressBack();

String expectedTitle = getInstrumentation().getTargetContext().getString(R.string.bbct_title, aboutTitle);
onView(withText(expectedTitle)).check(matches(isDisplayed()));
}

@Test
public void testNavigateBack() {
String initialTitle = (String) activityActivityTestRule.getActivity().getTitle();
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());

String aboutTitle = getInstrumentation().getTargetContext().getString(R.string.about_title);

onView(allOf(withText(aboutTitle), isDisplayed())).perform(click());
String expectedTitle = getInstrumentation().getTargetContext().getString(R.string.bbct_title, aboutTitle);
onView(withText(expectedTitle)).check(matches(isDisplayed()));

Espresso.closeSoftKeyboard();
Espresso.pressBack();
onView(withText(initialTitle)).check(matches(isDisplayed()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* This file is part of BBCT for Android.
*
* Copyright 2018 codeguru <[email protected]>
*
* BBCT for Android is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* BBCT for Android is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package bbct.android.common.navigation.test;

import android.support.test.espresso.Espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import bbct.android.common.R;
import bbct.android.lite.provider.LiteActivity;

import static android.support.test.InstrumentationRegistry.getInstrumentation;
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.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;

@RunWith(AndroidJUnit4.class)
public class NavigateBackPressFromBaseballCardDetailsTest {
@Rule
public ActivityTestRule<LiteActivity> activityActivityTestRule = new ActivityTestRule<LiteActivity>(LiteActivity.class);

@Before
public void setUp() throws Exception {
activityActivityTestRule.getActivity()
.getSupportFragmentManager().beginTransaction();
}

@Test
public void testDefaultNavigateUpWithNoData() {
String cardDetailsTitle = getInstrumentation().getTargetContext().getString(R.string.card_details_title);
String expectedTitle = getInstrumentation().getTargetContext().getString(R.string.bbct_title, cardDetailsTitle);
Espresso.closeSoftKeyboard();
onView(withText(expectedTitle)).check(matches(isDisplayed()));
Espresso.pressBack();
onView(withText(R.string.app_name)).check(matches(isDisplayed()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* This file is part of BBCT for Android.
*
* Copyright 2018 codeguru <[email protected]>
*
* BBCT for Android is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* BBCT for Android is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package bbct.android.common.navigation.test;

import android.support.test.espresso.Espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;


import bbct.android.common.R;
import bbct.android.lite.provider.LiteActivity;

import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static android.support.test.espresso.Espresso.onView;
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.withText;

@RunWith(AndroidJUnit4.class)
public class NavigateBackPressFromBaseballCardListTest {
@Rule
public ActivityTestRule<LiteActivity> activityActivityTestRule = new ActivityTestRule<LiteActivity>(LiteActivity.class);


@Before
public void setUp() throws Exception {
activityActivityTestRule.getActivity()
.getSupportFragmentManager().beginTransaction();
}

@Test
public void testBackPress() {
String expectedTitle = getInstrumentation().getTargetContext().getString(R.string.app_name);
Espresso.closeSoftKeyboard();
Espresso.pressBack();
onView(withText(expectedTitle)).check(matches(isDisplayed()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* This file is part of BBCT for Android.
*
* Copyright 2018 codeguru <[email protected]>
*
* BBCT for Android is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* BBCT for Android is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package bbct.android.common.navigation.test;

import android.support.test.espresso.Espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import bbct.android.common.R;
import bbct.android.lite.provider.LiteActivity;

import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;

@RunWith(AndroidJUnit4.class)
public class NavigateBackPressFromBaseballFilterCardsTest {
@Rule
public ActivityTestRule<LiteActivity> activityActivityTestRule = new ActivityTestRule<LiteActivity>(LiteActivity.class);

@Before
public void setUp() throws Exception {
activityActivityTestRule.getActivity()
.getSupportFragmentManager().beginTransaction();
}

@Test
public void testNavigateUp() {

String expectedTitle = getInstrumentation().getTargetContext().getString(R.string.app_name);
Espresso.pressBack();
onView(allOf(withContentDescription(R.string.filter_cards_title), isDisplayed())).perform(click());
Espresso.pressBack();
onView(allOf(withText(expectedTitle), isDisplayed()));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
Expand Down Expand Up @@ -106,6 +108,17 @@ public void onCreate(Bundle savedInstanceState) {
this.setHasOptionsMenu(true);
}

@Override
public void onResume() {
super.onResume();
getActivity().setTitle(R.string.app_name);

ActionBar actionBar = ((AppCompatActivity)getActivity()).getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(false);
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,16 @@ public void onCreate(Bundle savedInstanceState) {
BaseballCardContract.PROJECTION, null, null, null);

FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();
ft.add(R.id.fragment_holder, new BaseballCardList(), FragmentTags.CARD_LIST)
.addToBackStack(null)
.commit();

if (cursor == null || cursor.getCount() == 0) {
ft.add(R.id.fragment_holder, new BaseballCardDetails(), FragmentTags.EDIT_CARD);
} else {
ft.add(R.id.fragment_holder, new BaseballCardList(), FragmentTags.CARD_LIST);
cursor.close();
this.getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_holder, new BaseballCardDetails(), FragmentTags.EDIT_CARD)
.addToBackStack(FragmentTags.EDIT_CARD).commit();
}
ft.commit();
cursor.close();

ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
Expand Down

0 comments on commit 3a06166

Please sign in to comment.