Merge remote-tracking branch 'refs/remotes/origin/master' into 2.7.x-release

This commit is contained in:
misaochan 2018-03-28 19:48:13 +10:00
commit 4c1bf1b3c5
3 changed files with 2 additions and 243 deletions

View file

@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.design.widget.CoordinatorLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
@ -39,32 +39,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="mini"
android:layout_alignBottom="@id/toolbar"
android:layout_alignParentRight="true"
android:layout_marginRight="28dp"
android:layout_marginBottom="-96dp"
android:visibility="invisible"
app:elevation="6dp"
app:pressedTranslationZ="12dp"
app:backgroundTint="@color/button_blue"
android:clickable="true"
app:srcCompat="@drawable/ic_list_white_24dp"
android:scaleType="center"
/>
<View
android:id="@+id/transparentView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="18dp"
android:layout_below="@id/toolbar"
android:background="#aa969696"
android:elevation="6dp">

View file

@ -1,93 +0,0 @@
package fr.free.nrw.commons.nearby;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.MenuItem;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import edu.emory.mathcs.backport.java.util.Collections;
import fr.free.nrw.commons.BuildConfig;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.TestCommonsApplication;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.location.LocationServiceManager;
import io.reactivex.android.plugins.RxAndroidPlugins;
import io.reactivex.plugins.RxJavaPlugins;
import io.reactivex.schedulers.Schedulers;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21, application = TestCommonsApplication.class)
public class NearbyActivityTest {
private static final LatLng ST_LOUIS_MO_LAT_LNG
= new LatLng(38.627003, -90.199402, 0);
private static final Place AIRPORT = new Place(
"name", Place.Label.AIRPORT,
"desc", null,
new LatLng(38.6270, -90.1994, 0),
null, null);
@Mock
private LocationServiceManager locationManager;
@Mock
private NearbyController nearbyController;
@InjectMocks
private NearbyActivity nearbyActivity;
@Before
public void setUp() throws Exception {
// ensure waiting all threads to complete
RxJavaPlugins.setIoSchedulerHandler(
scheduler -> Schedulers.trampoline());
RxJavaPlugins.setComputationSchedulerHandler(
scheduler -> Schedulers.trampoline());
RxJavaPlugins.setNewThreadSchedulerHandler(
scheduler -> Schedulers.trampoline());
RxAndroidPlugins.setInitMainThreadSchedulerHandler(
scheduler -> Schedulers.trampoline());
nearbyActivity = Robolectric.setupActivity(NearbyActivity.class);
// replace methods and fields with mocks
MockitoAnnotations.initMocks(this);
when(locationManager.getLastLocation()).thenReturn(ST_LOUIS_MO_LAT_LNG);
when(locationManager.isProviderEnabled()).thenReturn(true);
when(nearbyController.loadAttractionsFromLocation(any(LatLng.class)))
.thenReturn(mock(NearbyController.NearbyPlacesInfo.class));
}
@Test
public void pressRefreshAndShowList() {
// MenuItem refresh = shadowOf(nearbyActivity).getOptionsMenu().findItem(R.id.action_refresh);
// nearbyActivity.onOptionsItemSelected(refresh);
//
// Fragment nearbyListFragment = nearbyActivity.getSupportFragmentManager()
// .findFragmentByTag(NearbyListFragment.class.getSimpleName());
// assertNotNull(nearbyListFragment);
//
// // one element (AIRPORT) exists in the list
// RecyclerView view = nearbyListFragment.getView().findViewById(R.id.listView);
// assertNotNull(view.findViewHolderForAdapterPosition(0));
// assertNull(view.findViewHolderForAdapterPosition(1));
}
}

View file

@ -1,129 +0,0 @@
package fr.free.nrw.commons.nearby;
import android.support.annotation.NonNull;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.pedrogomez.renderers.RVRendererAdapter;
import com.pedrogomez.renderers.RendererViewHolder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowDrawable;
import java.util.Collections;
import fr.free.nrw.commons.BuildConfig;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.TestCommonsApplication;
import fr.free.nrw.commons.location.LatLng;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21, application = TestCommonsApplication.class)
public class NearbyAdapterFactoryTest {
private static final Place PLACE = new Place("name", Place.Label.AIRPORT,
"desc", null, new LatLng(38.6270, -90.1994, 0), null, null);
private static final Place UNKNOWN_PLACE = new Place("name", Place.Label.UNKNOWN,
"desc", null, new LatLng(39.7392, -104.9903, 0), null, null);
private Place clickedPlace;
@Test
public void factoryHandlesNullListAndNullListener() {
NearbyAdapterFactory testObject = new NearbyAdapterFactory();
RVRendererAdapter<Place> result = testObject.create(null);
assertNotNull(result);
assertEquals(0, result.getItemCount());
}
@Test
public void factoryHandlesEmptyListAndNullListener() {
NearbyAdapterFactory testObject = new NearbyAdapterFactory();
RVRendererAdapter<Place> result = testObject.create(Collections.<Place>emptyList());
assertNotNull(result);
assertEquals(0, result.getItemCount());
}
@Test
public void factoryHandlesNonEmptyListAndNullListener() {
NearbyAdapterFactory testObject = new NearbyAdapterFactory();
RVRendererAdapter<Place> result = testObject.create(Collections.singletonList(PLACE));
assertNotNull(result);
assertEquals(1, result.getItemCount());
assertEquals(PLACE, result.getItem(0));
}
@Test
public void rendererCorrectlyBound() {
NearbyAdapterFactory testObject = new NearbyAdapterFactory();
RVRendererAdapter<Place> result = testObject.create(Collections.singletonList(PLACE));
RendererViewHolder viewHolder = renderComponent(result);
// test that the values we gave are actually rendered
assertNotNull(viewHolder.itemView.findViewById(R.id.tvName));
assertEquals(PLACE.name,
((TextView) viewHolder.itemView.findViewById(R.id.tvName)).getText().toString());
assertNotNull(viewHolder.itemView.findViewById(R.id.tvDesc));
assertEquals(PLACE.getLongDescription(),
((TextView) viewHolder.itemView.findViewById(R.id.tvDesc)).getText().toString());
assertNotNull(viewHolder.itemView.findViewById(R.id.distance));
assertEquals("",
((TextView) viewHolder.itemView.findViewById(R.id.distance)).getText().toString());
assertNotNull(viewHolder.itemView.findViewById(R.id.icon));
ImageView imageView = (ImageView) viewHolder.itemView.findViewById(R.id.icon);
ShadowDrawable shadow = Shadows.shadowOf(imageView.getDrawable());
assertEquals(R.drawable.round_icon_airport, shadow.getCreatedFromResId());
}
@Test
public void rendererCorrectlyBoundForUnknownPlace() {
NearbyAdapterFactory testObject = new NearbyAdapterFactory();
RVRendererAdapter<Place> result = testObject.create(Collections.singletonList(UNKNOWN_PLACE));
RendererViewHolder viewHolder = renderComponent(result);
assertNotNull(viewHolder.itemView.findViewById(R.id.tvDesc));
assertEquals(RuntimeEnvironment.application.getString(R.string.no_description_found),
((TextView) viewHolder.itemView.findViewById(R.id.tvDesc)).getText().toString());
assertNotNull(viewHolder.itemView.findViewById(R.id.icon));
ImageView imageView = (ImageView) viewHolder.itemView.findViewById(R.id.icon);
ShadowDrawable shadow = Shadows.shadowOf(imageView.getDrawable());
assertEquals(R.drawable.round_icon_unknown, shadow.getCreatedFromResId());
}
@Test
public void clickView() {
NearbyAdapterFactory testObject = new NearbyAdapterFactory();
RVRendererAdapter<Place> result = testObject.create(Collections.singletonList(PLACE));
RendererViewHolder viewHolder = renderComponent(result);
viewHolder.itemView.performClick();
assertEquals(PLACE, clickedPlace);
}
@NonNull
private RendererViewHolder renderComponent(RVRendererAdapter<Place> result) {
FrameLayout viewGroup = new FrameLayout(RuntimeEnvironment.application);
int itemViewType = result.getItemViewType(0);
RendererViewHolder viewHolder = result.onCreateViewHolder(viewGroup, itemViewType);
assertNotNull(viewHolder);
result.bindViewHolder(viewHolder, 0);
return viewHolder;
}
}