-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tests and code to make navigation work. this fixes #7.
- Loading branch information
Jonas Jurczok
committed
Jan 3, 2016
1 parent
5704dea
commit b88728a
Showing
6 changed files
with
182 additions
and
20 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
105 changes: 105 additions & 0 deletions
105
app/src/androidTest/java/org/linesofcode/alltrack/NavigationUITest.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,105 @@ | ||
package org.linesofcode.alltrack; | ||
|
||
import android.support.design.internal.NavigationMenuItemView; | ||
import android.support.test.espresso.UiController; | ||
import android.support.test.espresso.ViewAction; | ||
import android.support.test.espresso.action.GeneralSwipeAction; | ||
import android.support.test.rule.ActivityTestRule; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
|
||
import org.hamcrest.Matcher; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import static android.support.test.espresso.Espresso.onData; | ||
import static android.support.test.espresso.Espresso.onView; | ||
import static android.support.test.espresso.action.GeneralLocation.BOTTOM_CENTER; | ||
import static android.support.test.espresso.action.GeneralLocation.CENTER_LEFT; | ||
import static android.support.test.espresso.action.GeneralLocation.CENTER_RIGHT; | ||
import static android.support.test.espresso.action.GeneralLocation.TOP_CENTER; | ||
import static android.support.test.espresso.action.Press.FINGER; | ||
import static android.support.test.espresso.action.Swipe.FAST; | ||
import static android.support.test.espresso.action.ViewActions.click; | ||
import static android.support.test.espresso.action.ViewActions.swipeLeft; | ||
import static android.support.test.espresso.assertion.ViewAssertions.matches; | ||
import static android.support.test.espresso.matcher.ViewMatchers.assertThat; | ||
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.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.not; | ||
|
||
/** | ||
* Copyright 2015 Jonas Jurczok (jonasjurczok@gmail.com) | ||
* | ||
* 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. | ||
*/ | ||
public class NavigationUITest { | ||
public static final GeneralSwipeAction SWIPE_OPEN = new GeneralSwipeAction(FAST, CENTER_LEFT, CENTER_RIGHT, FINGER); | ||
|
||
@Rule | ||
@SuppressWarnings("unchecked") | ||
public ActivityTestRule<MainActivity> rule = new ActivityTestRule(MainActivity.class); | ||
|
||
@Before | ||
public void setUp() { | ||
rule.getActivity(); | ||
} | ||
|
||
@Test | ||
public void navigationViewShouldBeRendered() { | ||
onView(withId(R.id.mainLayout)).perform(SWIPE_OPEN); | ||
onView(withId(R.id.navigation)).check(matches(isDisplayed())); | ||
} | ||
|
||
@Test | ||
public void navigationViewShouldBeClosable() { | ||
onView(withId(R.id.mainLayout)).perform(SWIPE_OPEN); | ||
onView(withId(R.id.mainLayout)).perform(swipeLeft()); | ||
onView(withId(R.id.navigation)).check(matches(not(isDisplayed()))); | ||
} | ||
|
||
@Test | ||
public void openNavFromMainShouldHaveMainChecked() { | ||
onView(withId(R.id.mainLayout)).perform(SWIPE_OPEN); | ||
|
||
onView(withText(R.string.navigation_series)).perform(new ViewAction() { | ||
@Override | ||
public Matcher<View> getConstraints() { | ||
return isDisplayed(); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Check if menu item is checked."; | ||
} | ||
|
||
@Override | ||
public void perform(UiController uiController, View view) { | ||
NavigationMenuItemView menuItem = (NavigationMenuItemView) view; | ||
assertThat(menuItem.getItemData().isChecked(), is(true)); | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
public void clickOnDataSeriesShouldCloseNavigation() { | ||
onView(withId(R.id.mainLayout)).perform(SWIPE_OPEN); | ||
onView(withText(R.string.navigation_series)).perform(click()); | ||
|
||
onView(withId(R.id.navigation)).check(matches(not(isDisplayed()))); | ||
onView(withId(R.id.mainLayout)).check(matches(isDisplayed())); | ||
} | ||
} |
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
63 changes: 63 additions & 0 deletions
63
app/src/main/java/org/linesofcode/alltrack/NavigatableBaseActivity.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,63 @@ | ||
package org.linesofcode.alltrack; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.design.widget.NavigationView; | ||
import android.support.v4.widget.DrawerLayout; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.MenuItem; | ||
|
||
/** | ||
* Copyright 2015 Jonas Jurczok (jonasjurczok@gmail.com) | ||
* | ||
* 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. | ||
*/public class NavigatableBaseActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { | ||
|
||
private NavigationView navigationView; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
} | ||
|
||
@Override | ||
protected void onPostCreate(Bundle savedInstanceState) { | ||
super.onPostCreate(savedInstanceState); | ||
|
||
navigationView = (NavigationView) findViewById(R.id.navigation); | ||
navigationView.setNavigationItemSelectedListener(this); | ||
} | ||
|
||
protected void setActiveMenuItem(int itemId) { | ||
navigationView.setCheckedItem(itemId); | ||
} | ||
|
||
@Override | ||
public boolean onNavigationItemSelected(MenuItem menuItem) { | ||
switch(menuItem.getItemId()) { | ||
case R.id.nav_data_series: | ||
navigateToDataSeries(); | ||
break; | ||
default: | ||
return false; | ||
} | ||
DrawerLayout mainLayout = (DrawerLayout) findViewById(R.id.mainLayout); | ||
mainLayout.closeDrawers(); | ||
return true; | ||
} | ||
|
||
private void navigateToDataSeries() { | ||
Intent intent = new Intent(this, MainActivity.class); | ||
startActivity(intent); | ||
} | ||
} |
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