FormMapActivity extends BaseGeoMapActivity { public void onFeatureClicked(int featureId) { summarySheet.setState(BottomSheetBehavior.STATE_HIDDEN); if (!isSummaryForGivenSubmissionDisplayed(featureId)) { removeEnlargedMarkerIfExist(featureId); FormMapViewModel.MappableFormInstance mappableFormInstance = instancesByFeatureId.get(featureId); if (mappableFormInstance != null) { map.zoomToPoint(new MapPoint(mappableFormInstance.getLatitude(), mappableFormInstance.getLongitude()), map.getZoom(), true); updateSubmissionMarker(featureId, mappableFormInstance.getStatus(), true); setUpSummarySheetDetails(mappableFormInstance); } viewModel.setSelectedSubmissionId(featureId); } }  @Override void onCreate(Bundle savedInstanceState); @Override void onResume(); @Override void onBackPressed(); @SuppressLint("MissingPermission") // Permission handled in Constructor void initMap(MapFragment newMapFragment); void onLocationChanged(MapPoint point); void onFeatureClicked(int featureId); static final String MAP_CENTER_KEY; static final String MAP_ZOOM_KEY; public BottomSheetBehavior summarySheet; @VisibleForTesting public ViewModelProvider.Factory viewModelFactory; }
@LooperMode(PAUSED) @Test public void tappingOnInstance_centersToThatInstanceAndKeepsTheSameZoom() { MapPoint sent = new MapPoint(10.3, 125.7); map.zoomToPoint(new MapPoint(7, 8), 7, false); assertThat(map.getLatestZoomPoint().lat, is(7.0)); assertThat(map.getLatestZoomPoint().lon, is(8.0)); assertThat(map.getZoom(), is(7.0)); activity.onFeatureClicked(map.getFeatureIdFor(sent)); assertThat(map.getLatestZoomPoint().lat, is(10.3)); assertThat(map.getLatestZoomPoint().lon, is(125.7)); assertThat(map.getZoom(), is(7.0)); }
@LooperMode(PAUSED) @Test public void openingEditableInstances_launchesEditActivity() { MapPoint editableAndFinalized = new MapPoint(10.1, 125.6); MapPoint unfinalized = new MapPoint(10.1, 126.6); MapPoint failedToSend = new MapPoint(10.3, 125.6); MapPoint[] testPoints = {editableAndFinalized, unfinalized, failedToSend}; for (MapPoint toTap : testPoints) { int featureId = map.getFeatureIdFor(toTap); activity.onFeatureClicked(featureId); clickOnOpenFormChip(); Intent actual = shadowOf(RuntimeEnvironment.application).getNextStartedActivity(); assertThat(actual.getAction(), is(Intent.ACTION_EDIT)); assertThat(actual.getStringExtra(ApplicationConstants.BundleKeys.FORM_MODE), is(nullValue())); } }
@LooperMode(PAUSED) @Test public void openingEditableInstance_whenEditingSettingisOff_launchesViewActivity() { AdminSharedPreferences.getInstance().save(AdminKeys.KEY_EDIT_SAVED, false); MapPoint editableAndFinalized = new MapPoint(10.1, 125.6); MapPoint unfinalized = new MapPoint(10.1, 126.6); MapPoint failedToSend = new MapPoint(10.3, 125.6); MapPoint[] testPoints = {editableAndFinalized, unfinalized, failedToSend}; for (MapPoint toTap : testPoints) { int featureId = map.getFeatureIdFor(toTap); activity.onFeatureClicked(featureId); clickOnOpenFormChip(); Intent actual = shadowOf(RuntimeEnvironment.application).getNextStartedActivity(); assertThat(actual.getAction(), is(Intent.ACTION_EDIT)); assertThat(actual.getStringExtra(ApplicationConstants.BundleKeys.FORM_MODE), is(ApplicationConstants.FormModes.VIEW_SENT)); } }
@LooperMode(PAUSED) @Test public void openingUneditableInstances_launchesViewActivity() { MapPoint sent = new MapPoint(10.3, 125.7); int featureId = map.getFeatureIdFor(sent); activity.onFeatureClicked(featureId); clickOnOpenFormChip(); Intent actual = shadowOf(RuntimeEnvironment.application).getNextStartedActivity(); assertThat(actual.getAction(), is(Intent.ACTION_EDIT)); assertThat(actual.getStringExtra(ApplicationConstants.BundleKeys.FORM_MODE), is(ApplicationConstants.FormModes.VIEW_SENT)); }
@LooperMode(PAUSED) @Test public void tappingOnEditableInstance_showsSubmissionSummaryWithAppropriateMessage() { MapPoint editableAndFinalized = new MapPoint(10.1, 125.6); MapPoint unfinalized = new MapPoint(10.1, 126.6); MapPoint failedToSend = new MapPoint(10.3, 125.6); MapPoint[] testPoints = {editableAndFinalized, unfinalized, failedToSend}; for (MapPoint toTap : testPoints) { int featureId = map.getFeatureIdFor(toTap); FormMapViewModel.MappableFormInstance mappableFormInstance = activity.instancesByFeatureId.get(featureId); activity.onFeatureClicked(featureId); assertSubmissionSummaryContent(mappableFormInstance); } }
@LooperMode(PAUSED) @Test public void tappingOnUneditableInstances_showsSubmissionSummaryWithAppropriateMessage() { MapPoint sent = new MapPoint(10.3, 125.7); int featureId = map.getFeatureIdFor(sent); FormMapViewModel.MappableFormInstance mappableFormInstance = activity.instancesByFeatureId.get(featureId); activity.onFeatureClicked(featureId); assertSubmissionSummaryContent(mappableFormInstance); }
@LooperMode(PAUSED) @Test public void tappingOnEncryptedInstances_showsSubmissionSummaryWithAppropriateMessage() { MapPoint submissionFailedCantEditWhenFinalized = new MapPoint(10.4, 125.6); int featureId = map.getFeatureIdFor(submissionFailedCantEditWhenFinalized); FormMapViewModel.MappableFormInstance mappableFormInstance = activity.instancesByFeatureId.get(featureId); activity.onFeatureClicked(featureId); assertSubmissionSummaryContent(mappableFormInstance); }
@LooperMode(PAUSED) @Test public void tappingOnDeletedInstances_showsSubmissionSummaryWithAppropriateMessage() { MapPoint deleted = new MapPoint(10.0, 125.6); int featureId = map.getFeatureIdFor(deleted); FormMapViewModel.MappableFormInstance mappableFormInstance = activity.instancesByFeatureId.get(featureId); activity.onFeatureClicked(featureId); assertSubmissionSummaryContent(mappableFormInstance); }