Skip to content

Commit

Permalink
Merge pull request #370 from OpenSRP/date_fixed
Browse files Browse the repository at this point in the history
Date fixed
  • Loading branch information
paulinembabu authored Mar 31, 2021
2 parents da927aa + f677aa4 commit 72b6876
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 73 deletions.
10 changes: 5 additions & 5 deletions opensrp-giz-malawi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ android {
minSdkVersion androidMinSdkVersion
targetSdkVersion androidTargetSdkVersion
versionCode 36
versionName "0.2.46"
versionName "0.3.0"
multiDexEnabled true
buildConfigField "long", "MAX_SERVER_TIME_DIFFERENCE", "1800000l"
buildConfigField "boolean", "TIME_CHECK", "false"
Expand Down Expand Up @@ -113,7 +113,7 @@ android {
buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '100'
buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '2'
buildConfigField "int", "VACCINE_SYNC_TIME", '0'
buildConfigField "int", "DATABASE_VERSION", '14'
buildConfigField "int", "DATABASE_VERSION", '15'
buildConfigField "long", "MAX_SERVER_TIME_DIFFERENCE", "1800000l"
buildConfigField "boolean", "TIME_CHECK", "true"
buildConfigField "int", "DATA_SYNC_DURATION_MINUTES", '15'
Expand Down Expand Up @@ -141,7 +141,7 @@ android {
buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '10'
buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '2'
buildConfigField "int", "VACCINE_SYNC_TIME", '0'
buildConfigField "int", "DATABASE_VERSION", '14'
buildConfigField "int", "DATABASE_VERSION", '15'
buildConfigField "long", "MAX_SERVER_TIME_DIFFERENCE", "1800000l"
buildConfigField "boolean", "TIME_CHECK", "true"
buildConfigField "int", "DATA_SYNC_DURATION_MINUTES", '15'
Expand All @@ -168,7 +168,7 @@ android {
buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '100'
buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '2'
buildConfigField "int", "VACCINE_SYNC_TIME", '0'
buildConfigField "int", "DATABASE_VERSION", '14'
buildConfigField "int", "DATABASE_VERSION", '15'
buildConfigField "long", "MAX_SERVER_TIME_DIFFERENCE", "1800000l"
buildConfigField "boolean", "TIME_CHECK", "true"
buildConfigField "int", "DATA_SYNC_DURATION_MINUTES", '15'
Expand All @@ -191,7 +191,7 @@ android {
buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '100'
buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '2'
buildConfigField "int", "VACCINE_SYNC_TIME", '0'
buildConfigField "int", "DATABASE_VERSION", '14'
buildConfigField "int", "DATABASE_VERSION", '15'
buildConfigField "long", "MAX_SERVER_TIME_DIFFERENCE", "1800000l"
buildConfigField "boolean", "TIME_CHECK", "true"
buildConfigField "int", "DATA_SYNC_DURATION_MINUTES", '15'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public class FilterReportFragment extends Fragment implements FindReportContract
public static final String TAG = "FilterReportFragment";
public static final String REPORT_NAME = "REPORT_NAME";
private final SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy", Locale.US);
private final Calendar myCalendar = Calendar.getInstance();
private final List<String> communityList = new ArrayList<>();
protected AutoCompleteTextView autoCompleteTextView;
protected ImageView imageView;
protected FindReportContract.Presenter presenter;
private Calendar myCalendar = Calendar.getInstance();
private View view;
private String titleName;
private EditText editTextDate;
Expand Down Expand Up @@ -80,8 +80,9 @@ public void onResume() {
selectedItem = null;
}
if (editTextDate != null) {
Calendar calendar = Calendar.getInstance();
editTextDate.setText(dateFormat.format(calendar.getTime()));
myCalendar.clear();
myCalendar = Calendar.getInstance();
editTextDate.setText(dateFormat.format(myCalendar.getTime()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
import org.smartregister.util.DatabaseMigrationUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -191,8 +193,10 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
upgradeToVersion13CreateReasonForDefaultingTable(db);
break;
case 14:
db.execSQL(VaccineRepository.UPDATE_TABLE_ADD_IS_VOIDED_COL);
db.execSQL(VaccineRepository.UPDATE_TABLE_ADD_IS_VOIDED_COL_INDEX);
upgradeToVersion14UpdateMissingColumns(db);
break;
case 15:
upgradeToVersion15TriggerCreateNewTable(db);
break;
default:
break;
Expand Down Expand Up @@ -480,6 +484,24 @@ private void upgradeToVersion13CreateReasonForDefaultingTable(@NonNull SQLiteDat
}
}

private void upgradeToVersion14UpdateMissingColumns(@NonNull SQLiteDatabase db) {
db.execSQL(VaccineRepository.UPDATE_TABLE_ADD_IS_VOIDED_COL);
db.execSQL(VaccineRepository.UPDATE_TABLE_ADD_IS_VOIDED_COL_INDEX);
EventClientRepository.addEventTaskId(db);
EventClientRepository.createIndex(db, EventClientRepository.Table.event, EventClientRepository.event_column.values());
}

private void upgradeToVersion15TriggerCreateNewTable(@NonNull SQLiteDatabase db) {
try {
DatabaseMigrationUtils.createAddedECTables(db,
new HashSet<>(Collections.singletonList("ec_family_member_location")),
GizMalawiApplication.createCommonFtsObject(context));

} catch (Exception e) {
Timber.e(e, "upgradeToVersion15");
}
}

private boolean checkIfAppUpdated() {
String savedAppVersion = ReportingLibrary.getInstance().getContext().allSharedPreferences().getPreference(appVersionCodePref);
if (savedAppVersion.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package org.smartregister.giz.activity;

import android.content.Intent;

import org.json.JSONObject;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatchers;
import org.mockito.Captor;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.Robolectric;
import org.robolectric.android.controller.ActivityController;
import org.robolectric.util.ReflectionHelpers;
import org.smartregister.Context;
import org.smartregister.CoreLibrary;
import org.smartregister.child.util.ChildJsonFormUtils;
import org.smartregister.giz.BaseUnitTest;
import org.smartregister.giz.adapter.NavigationAdapter;
import org.smartregister.giz.presenter.GizChildRegisterPresenter;
import org.smartregister.giz.view.NavigationMenu;

public class ChildRegisterActivityTest extends BaseUnitTest {
@Rule
public MockitoRule rule = MockitoJUnit.rule();
private ChildRegisterActivity activity;
private ActivityController<ChildRegisterActivity> controller;
@Captor
private ArgumentCaptor<Intent> intentArgumentCaptor;
@Captor
private ArgumentCaptor<Integer> integerArgumentCaptor;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);

Context context = Context.getInstance();
CoreLibrary.init(context);

//Auto login by default
context.session().start(context.session().lengthInMilliseconds());

controller = Robolectric.buildActivity(ChildRegisterActivity.class).create().start().resume().restart();
activity = controller.get();
}

@Test
public void testInitializePresenter() {
activity.initializePresenter();
Assert.assertTrue(ReflectionHelpers.getField(activity, "presenter") instanceof GizChildRegisterPresenter);
}

@Test
public void testStartFormActivityInvokesChildForm() throws Exception {
activity = Mockito.spy(activity);

Mockito.doNothing().when(activity).startActivityForResult(ArgumentMatchers.any(Intent.class), ArgumentMatchers.anyInt());

activity.startFormActivity(new JSONObject());

Mockito.verify(activity).startActivityForResult(intentArgumentCaptor.capture(), integerArgumentCaptor.capture());

Intent capturedIntent = intentArgumentCaptor.getValue();
Assert.assertNotNull(capturedIntent);
Assert.assertEquals("org.smartregister.giz.activity.ChildFormActivity", capturedIntent.getComponent().getClassName());

Integer capturedInteger = integerArgumentCaptor.getValue();

Assert.assertNotNull(capturedInteger);
Assert.assertEquals(ChildJsonFormUtils.REQUEST_CODE_GET_JSON, capturedInteger.intValue());

}

@Test
public void testOpenDrawer() {
NavigationMenu navigationMenu = Mockito.mock(NavigationMenu.class);
activity = Mockito.spy(activity);
NavigationAdapter navigationAdapter = Mockito.mock(NavigationAdapter.class);
Mockito.when(navigationMenu.getNavigationAdapter()).thenReturn(navigationAdapter);
activity.openDrawer();
Mockito.verify(activity).openDrawer();
}

@Test
public void testCloseDrawer() {
NavigationMenu navigationMenu = Mockito.mock(NavigationMenu.class);
activity = Mockito.spy(activity);
NavigationAdapter navigationAdapter = Mockito.mock(NavigationAdapter.class);
Mockito.when(navigationMenu.getNavigationAdapter()).thenReturn(navigationAdapter);
activity.closeDrawer();
Mockito.verify(activity).closeDrawer();
}

@Test
public void testOnResumption() {
activity = Mockito.spy(activity);
NavigationMenu navigationMenu = Mockito.mock(NavigationMenu.class);
NavigationAdapter navigationAdapter = Mockito.mock(NavigationAdapter.class);
Mockito.when(navigationMenu.getNavigationAdapter()).thenReturn(navigationAdapter);
activity.onResumption();

Mockito.verify(activity).onResumption();
}

@After
public void tearDown() {
try {
activity.finish();
controller.pause().stop().destroy(); //destroy controller if we can
} catch (Exception e) {
e.printStackTrace();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class LoginActivityTest extends BaseActivityUnitTest {
public void setUp() {
MockitoAnnotations.initMocks(this);

controller = Robolectric.buildActivity(LoginActivity.class).create().start();
controller = Robolectric.buildActivity(LoginActivity.class).create().start().resume();
loginActivity = controller.get();
}

Expand Down
Loading

0 comments on commit 72b6876

Please sign in to comment.