Skip to content

Commit

Permalink
Merge pull request #161 from OpenSRP/fix-recurring-vaccines
Browse files Browse the repository at this point in the history
Fix recurring vaccines string comparison
  • Loading branch information
hamza-vd authored Jan 26, 2021
2 parents d33b10d + 67034a7 commit 159b21e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=3.0.4-SNAPSHOT
VERSION_NAME=3.0.5-SNAPSHOT
VERSION_CODE=2
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Immunization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,25 @@ protected VaccineWrapper doInBackground(Void... params) {
protected void onPostExecute(VaccineWrapper vaccineWrapper) {
vaccineCard.setVaccineWrapper(vaccineWrapper);
vaccineGroup.toggleRecordAllTV();
notifyDataSetChanged();
if (vaccineWrapper.getStatus() == null) {
removeVaccine(vaccineName);
} else {
notifyDataSetChanged();
}
}
}

private void removeVaccine(String vaccineName) {
vaccineCards.remove(vaccineName);
for (int i = 0; i < vaccineGroup.getVaccineData().vaccines.size(); i++) {
org.smartregister.immunization.domain.jsonmapping.Vaccine vaccine = vaccineGroup.getVaccineData().vaccines
.get(i);
if (vaccine.getName().equalsIgnoreCase(vaccineName)) {
vaccineGroup.getVaccineData().vaccines
.remove(i);
}
}
notifyDataSetChanged();
vaccineGroup.getVaccinesGV().invalidateViews();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void updateWrapper(ServiceWrapper tag) {

if (!serviceRecordList.isEmpty()) {
for (ServiceRecord serviceRecord : serviceRecordList) {
if (tag.getName().toLowerCase().contains(serviceRecord.getName().toLowerCase()) && serviceRecord
if (tag.getName().equalsIgnoreCase(serviceRecord.getName()) && serviceRecord
.getDate() != null) {
long diff = serviceRecord.getUpdatedAt() - serviceRecord.getDate().getTime();
if (diff > 0 && TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS) > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
import org.smartregister.commonregistry.CommonPersonObjectClient;
import org.smartregister.domain.Alert;
import org.smartregister.domain.AlertStatus;
Expand Down Expand Up @@ -81,6 +83,11 @@ public void setDataForTest(String dateTimeString) {
wrapper.setName(VaccineRepo.Vaccine.measles2.display());
wrapper.setVaccine(VaccineRepo.Vaccine.measles2);
wrappers.add(wrapper);
wrapper.setDbKey(0l);
wrapper.setName(VaccineRepo.Vaccine.opv0.display());
wrapper.setVaccine(VaccineRepo.Vaccine.opv0);
wrapper.setStatus(null);
wrappers.add(wrapper);

Type listType = new TypeToken<List<VaccineGroup>>() {
}.getType();
Expand Down Expand Up @@ -141,8 +148,20 @@ public void assertGetViewReturnsVaccineGroup() {
ImmunizationRowAdapter immunizationRowAdapter = new ImmunizationRowAdapter(RuntimeEnvironment.application, view,
true, vaccinelist, alertlist);

Assert.assertEquals(immunizationRowAdapter.getView(0, null, null) != null, true);
Assert.assertNotNull(immunizationRowAdapter.getView(0, null, null));

}

@Test
public void assertVaccineRemovedWithNullStatus() {
ImmunizationRowAdapter mockAdapter = Mockito
.spy(new ImmunizationRowAdapter(context, view, true, vaccinelist, alertlist));

ReflectionHelpers.callInstanceMethod(mockAdapter, "removeVaccine",
ReflectionHelpers.ClassParameter.from(String.class, "OPV 0"));


Assert.assertEquals(view.getVaccineData().vaccines.size(), 1);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ public void assertConstructorsNotNull() {
//Assert.assertNotNull(activity.getInstance3());
}

@Test
public void testConstructors() {
Assert.assertNotNull(new ServiceRowGroup(RuntimeEnvironment.application));
Assert.assertNotNull(new ServiceRowGroup(RuntimeEnvironment.application, Robolectric.buildAttributeSet().build()));
Assert.assertNotNull(new ServiceRowGroup(RuntimeEnvironment.application, Robolectric.buildAttributeSet().build(), 0));
Assert.assertNotNull(new ServiceRowGroup(RuntimeEnvironment.application, Robolectric.buildAttributeSet().build(), 0, 0));
}

@After
public void tearDown() {
destroyController();
Expand Down

0 comments on commit 159b21e

Please sign in to comment.