diff --git a/opensrp-reveal/src/test/java/org/smartregister/reveal/view/DrawerMenuViewTest.java b/opensrp-reveal/src/test/java/org/smartregister/reveal/view/DrawerMenuViewTest.java index 7373a91bb5..8da7a725f5 100644 --- a/opensrp-reveal/src/test/java/org/smartregister/reveal/view/DrawerMenuViewTest.java +++ b/opensrp-reveal/src/test/java/org/smartregister/reveal/view/DrawerMenuViewTest.java @@ -1,7 +1,10 @@ package org.smartregister.reveal.view; import android.content.Context; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; import android.view.View; +import android.view.ViewTreeObserver; import android.widget.ProgressBar; import android.widget.TextView; @@ -9,6 +12,8 @@ import androidx.core.view.GravityCompat; import androidx.drawerlayout.widget.DrawerLayout; +import com.google.android.material.navigation.NavigationView; + import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -21,11 +26,15 @@ import org.robolectric.Robolectric; import org.robolectric.RuntimeEnvironment; import org.smartregister.reveal.BaseUnitTest; +import org.smartregister.reveal.BuildConfig; import org.smartregister.reveal.R; import org.smartregister.reveal.contract.BaseDrawerContract; +import org.smartregister.reveal.util.Country; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -54,6 +63,9 @@ public class DrawerMenuViewTest extends BaseUnitTest { @Mock private TextView operationalAreaTextView; + @Mock + private TextView p2pSyncTextView; + @Mock private BaseDrawerContract.Presenter presenter; @@ -111,6 +123,43 @@ public void testSetOperationalArea() { assertEquals("Akros_1", stringArgumentCaptor.getValue()); } + + @Test + public void testInitializeDrawerLayoutForZambiaAndSenegal() throws PackageManager.NameNotFoundException { + drawerMenuView = spy(drawerMenuView); + doReturn(mockActivity).when(activity).getActivity(); + NavigationView navView = mock(NavigationView.class); + View headView = mock(View.class); + DrawerLayout drawerLayout = mock(DrawerLayout.class); + PackageManager packageManager = mock(PackageManager.class); + when(packageManager.getPackageInfo(anyString(), anyInt())).thenReturn(mock(PackageInfo.class)); + when(mockActivity.findViewById(R.id.drawer_layout)).thenReturn(drawerLayout); + when(mockActivity.findViewById(R.id.nav_view)).thenReturn(navView); + when(mockActivity.getPackageManager()).thenReturn(packageManager); + when(mockActivity.getPackageName()).thenReturn(""); + when(navView.getHeaderView(0)).thenReturn(headView); + when(headView.getViewTreeObserver()).thenReturn(mock(ViewTreeObserver.class)); + when(headView.findViewById(R.id.btn_navMenu_p2pSyncBtn)).thenReturn(p2pSyncTextView); + when(headView.findViewById(R.id.btn_navMenu_offline_maps)).thenReturn(planTextView); + when(headView.findViewById(R.id.sync_button)).thenReturn(planTextView); + when(headView.findViewById(R.id.logout_button)).thenReturn(planTextView); + when(headView.findViewById(R.id.plan_selector)).thenReturn(planTextView); + when(headView.findViewById(R.id.operational_area_selector)).thenReturn(planTextView); + when(headView.findViewById(R.id.application_updated)).thenReturn(planTextView); + when(headView.findViewById(R.id.application_version)).thenReturn(planTextView); + when(headView.findViewById(R.id.btn_navMenu_summaryForms)).thenReturn(planTextView); + when(headView.findViewById(R.id.operator_label)).thenReturn(planTextView); + when(headView.findViewById(R.id.facility_label)).thenReturn(planTextView); + when(headView.findViewById(R.id.district_label)).thenReturn(planTextView); + when(headView.findViewById(R.id.btn_navMenu_filled_forms)).thenReturn(planTextView); + + Country buildCountry = BuildConfig.BUILD_COUNTRY; + Whitebox.setInternalState(BuildConfig.class, BuildConfig.BUILD_COUNTRY, Country.ZAMBIA); + drawerMenuView.initializeDrawerLayout(); + verify(p2pSyncTextView).setVisibility(View.VISIBLE); + Whitebox.setInternalState(BuildConfig.class, BuildConfig.BUILD_COUNTRY, buildCountry); + } + @Test public void testGetOperationalArea() { drawerMenuView = spy(drawerMenuView);