From bd7283db7da194ed39817bedc7b9918c707e6d84 Mon Sep 17 00:00:00 2001 From: Farhan Arshad Date: Fri, 20 Dec 2024 17:49:15 +0500 Subject: [PATCH] fix: unit test cases --- .../presentation/DashboardViewModelTest.kt | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/dashboard/src/test/java/org/openedx/dashboard/presentation/DashboardViewModelTest.kt b/dashboard/src/test/java/org/openedx/dashboard/presentation/DashboardViewModelTest.kt index c0455c763..ae9865709 100644 --- a/dashboard/src/test/java/org/openedx/dashboard/presentation/DashboardViewModelTest.kt +++ b/dashboard/src/test/java/org/openedx/dashboard/presentation/DashboardViewModelTest.kt @@ -36,12 +36,14 @@ import org.openedx.core.domain.model.DashboardCourseList import org.openedx.core.domain.model.IAPConfig import org.openedx.core.domain.model.Pagination import org.openedx.core.presentation.IAPAnalytics +import org.openedx.core.system.PushNotifier import org.openedx.core.system.ResourceManager import org.openedx.core.system.connection.NetworkConnection import org.openedx.core.system.notifier.CourseDashboardUpdate import org.openedx.core.system.notifier.CourseDataUpdated import org.openedx.core.system.notifier.DiscoveryNotifier import org.openedx.core.system.notifier.IAPNotifier +import org.openedx.core.system.notifier.PushEvent import org.openedx.core.system.notifier.app.AppNotifier import org.openedx.dashboard.domain.interactor.DashboardInteractor import java.net.UnknownHostException @@ -61,6 +63,7 @@ class DashboardViewModelTest { private val networkConnection = mockk() private val discoveryNotifier = mockk() private val iapNotifier = mockk() + private val pushNotifier = mockk() private val analytics = mockk() private val appNotifier = mockk() private val iapAnalytics = mockk() @@ -112,11 +115,12 @@ class DashboardViewModelTest { resourceManager, discoveryNotifier, iapNotifier, + pushNotifier, analytics, appNotifier, corePreferences, + iapInteractor, iapAnalytics, - iapInteractor ) coEvery { interactor.getEnrolledCourses(any()) } throws UnknownHostException() advanceUntilIdle() @@ -143,11 +147,12 @@ class DashboardViewModelTest { resourceManager, discoveryNotifier, iapNotifier, + pushNotifier, analytics, appNotifier, corePreferences, + iapInteractor, iapAnalytics, - iapInteractor ) coEvery { interactor.getEnrolledCourses(any()) } throws Exception() @@ -175,11 +180,12 @@ class DashboardViewModelTest { resourceManager, discoveryNotifier, iapNotifier, + pushNotifier, analytics, appNotifier, corePreferences, + iapInteractor, iapAnalytics, - iapInteractor ) coEvery { interactor.getEnrolledCourses(any()) } returns dashboardCourseList @@ -207,11 +213,12 @@ class DashboardViewModelTest { resourceManager, discoveryNotifier, iapNotifier, + pushNotifier, analytics, appNotifier, corePreferences, + iapInteractor, iapAnalytics, - iapInteractor ) coEvery { interactor.getEnrolledCourses(any()) } returns dashboardCourseList.copy( @@ -248,11 +255,12 @@ class DashboardViewModelTest { resourceManager, discoveryNotifier, iapNotifier, + pushNotifier, analytics, appNotifier, corePreferences, + iapInteractor, iapAnalytics, - iapInteractor ) advanceUntilIdle() @@ -278,11 +286,12 @@ class DashboardViewModelTest { resourceManager, discoveryNotifier, iapNotifier, + pushNotifier, analytics, appNotifier, corePreferences, + iapInteractor, iapAnalytics, - iapInteractor ) coEvery { interactor.getEnrolledCourses(any()) } throws UnknownHostException() @@ -312,11 +321,12 @@ class DashboardViewModelTest { resourceManager, discoveryNotifier, iapNotifier, + pushNotifier, analytics, appNotifier, corePreferences, + iapInteractor, iapAnalytics, - iapInteractor ) coEvery { interactor.getEnrolledCourses(any()) } throws Exception() @@ -340,6 +350,7 @@ class DashboardViewModelTest { coEvery { interactor.getEnrolledCourses(any()) } returns dashboardCourseList coEvery { iapNotifier.notifier } returns flow { emit(CourseDataUpdated()) } coEvery { iapNotifier.send(any()) } returns Unit + coEvery { pushNotifier.send(any()) } returns Unit val viewModel = DashboardListViewModel( context, @@ -349,11 +360,12 @@ class DashboardViewModelTest { resourceManager, discoveryNotifier, iapNotifier, + pushNotifier, analytics, appNotifier, corePreferences, + iapInteractor, iapAnalytics, - iapInteractor ) viewModel.updateCourses() @@ -383,6 +395,7 @@ class DashboardViewModelTest { ) coEvery { iapNotifier.notifier } returns flow { emit(CourseDataUpdated()) } coEvery { iapNotifier.send(any()) } returns Unit + coEvery { pushNotifier.send(any()) } returns Unit val viewModel = DashboardListViewModel( context, @@ -392,11 +405,12 @@ class DashboardViewModelTest { resourceManager, discoveryNotifier, iapNotifier, + pushNotifier, analytics, appNotifier, corePreferences, + iapInteractor, iapAnalytics, - iapInteractor ) viewModel.updateCourses() @@ -425,11 +439,12 @@ class DashboardViewModelTest { resourceManager, discoveryNotifier, iapNotifier, + pushNotifier, analytics, appNotifier, corePreferences, + iapInteractor, iapAnalytics, - iapInteractor ) val mockLifeCycleOwner: LifecycleOwner = mockk()