Skip to content

Commit f8ff37e

Browse files
feat: junit tests and analytics
1 parent 2f7b10e commit f8ff37e

File tree

6 files changed

+60
-3
lines changed

6 files changed

+60
-3
lines changed

app/src/main/java/org/openedx/app/AnalyticsManager.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.openedx.core.presentation.CoreAnalytics
55
import org.openedx.core.presentation.dialog.appreview.AppReviewAnalytics
66
import org.openedx.course.presentation.CourseAnalytics
77
import org.openedx.dashboard.presentation.DashboardAnalytics
8+
import org.openedx.dates.presentation.DatesAnalytics
89
import org.openedx.discovery.presentation.DiscoveryAnalytics
910
import org.openedx.discussion.presentation.DiscussionAnalytics
1011
import org.openedx.foundation.interfaces.Analytics
@@ -21,7 +22,8 @@ class AnalyticsManager :
2122
DiscoveryAnalytics,
2223
DiscussionAnalytics,
2324
ProfileAnalytics,
24-
WhatsNewAnalytics {
25+
WhatsNewAnalytics,
26+
DatesAnalytics {
2527

2628
private val analytics: MutableList<Analytics> = mutableListOf()
2729

app/src/main/java/org/openedx/app/di/AppModule.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import org.openedx.course.utils.ImageProcessor
6363
import org.openedx.course.worker.OfflineProgressSyncScheduler
6464
import org.openedx.dashboard.presentation.DashboardAnalytics
6565
import org.openedx.dashboard.presentation.DashboardRouter
66+
import org.openedx.dates.presentation.DatesAnalytics
6667
import org.openedx.dates.presentation.DatesRouter
6768
import org.openedx.discovery.presentation.DiscoveryAnalytics
6869
import org.openedx.discovery.presentation.DiscoveryRouter
@@ -212,6 +213,7 @@ val appModule = module {
212213
single<DiscussionAnalytics> { get<AnalyticsManager>() }
213214
single<ProfileAnalytics> { get<AnalyticsManager>() }
214215
single<WhatsNewAnalytics> { get<AnalyticsManager>() }
216+
single<DatesAnalytics> { get<AnalyticsManager>() }
215217

216218
factory { AgreementProvider(get(), get()) }
217219
factory { FacebookAuthHelper() }

app/src/main/java/org/openedx/app/di/ScreenModule.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,8 @@ val screenModule = module {
513513
networkConnection = get(),
514514
resourceManager = get(),
515515
datesInteractor = get(),
516-
corePreferences = get()
516+
corePreferences = get(),
517+
analytics = get()
517518
)
518519
}
519520
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.openedx.dates.presentation
2+
3+
interface DatesAnalytics {
4+
fun logEvent(event: String, params: Map<String, Any?>)
5+
}
6+
7+
enum class DatesAnalyticsEvent(val eventName: String, val biValue: String) {
8+
ASSIGNMENT_CLICK(
9+
"Dates:Assignment click",
10+
"edx.bi.app.dates.assignment_click"
11+
),
12+
SHIFT_DUE_DATE_CLICK(
13+
"Dates:Shift due date click",
14+
"edx.bi.app.dates.shift_due_date_click"
15+
),
16+
}
17+
18+
enum class DatesAnalyticsKey(val key: String) {
19+
NAME("name"),
20+
}

dates/src/main/java/org/openedx/dates/presentation/dates/DatesViewModel.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import org.openedx.core.system.connection.NetworkConnection
1919
import org.openedx.core.utils.isToday
2020
import org.openedx.core.utils.toCalendar
2121
import org.openedx.dates.domain.interactor.DatesInteractor
22+
import org.openedx.dates.presentation.DatesAnalytics
23+
import org.openedx.dates.presentation.DatesAnalyticsEvent
24+
import org.openedx.dates.presentation.DatesAnalyticsKey
2225
import org.openedx.dates.presentation.DatesRouter
2326
import org.openedx.foundation.extension.isInternetError
2427
import org.openedx.foundation.presentation.BaseViewModel
@@ -32,6 +35,7 @@ class DatesViewModel(
3235
private val networkConnection: NetworkConnection,
3336
private val resourceManager: ResourceManager,
3437
private val datesInteractor: DatesInteractor,
38+
private val analytics: DatesAnalytics,
3539
corePreferences: CorePreferences,
3640
) : BaseViewModel() {
3741

@@ -116,6 +120,7 @@ class DatesViewModel(
116120
}
117121

118122
fun shiftDueDate() {
123+
logEvent(DatesAnalyticsEvent.SHIFT_DUE_DATE_CLICK)
119124
viewModelScope.launch {
120125
try {
121126
_uiState.update { state ->
@@ -167,6 +172,7 @@ class DatesViewModel(
167172
fragmentManager: FragmentManager,
168173
courseDate: CourseDate,
169174
) {
175+
logEvent(DatesAnalyticsEvent.ASSIGNMENT_CLICK)
170176
datesRouter.navigateToCourseOutline(
171177
fm = fragmentManager,
172178
courseId = courseDate.courseId,
@@ -201,6 +207,19 @@ class DatesViewModel(
201207

202208
return grouped
203209
}
210+
211+
private fun logEvent(
212+
event: DatesAnalyticsEvent,
213+
params: Map<String, Any?> = emptyMap(),
214+
) {
215+
analytics.logEvent(
216+
event = event.eventName,
217+
params = buildMap {
218+
put(DatesAnalyticsKey.NAME.key, event.biValue)
219+
putAll(params)
220+
}
221+
)
222+
}
204223
}
205224

206225
interface DatesViewActions {

dates/src/test/java/org/openedx/dates/DatesViewModelTest.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import org.openedx.core.domain.model.CourseDate
3131
import org.openedx.core.domain.model.CourseDatesResponse
3232
import org.openedx.core.system.connection.NetworkConnection
3333
import org.openedx.dates.domain.interactor.DatesInteractor
34+
import org.openedx.dates.presentation.DatesAnalytics
3435
import org.openedx.dates.presentation.DatesRouter
3536
import org.openedx.dates.presentation.dates.DatesViewModel
3637
import org.openedx.foundation.presentation.UIMessage
@@ -51,6 +52,7 @@ class DatesViewModelTest {
5152
private val resourceManager = mockk<ResourceManager>()
5253
private val datesInteractor = mockk<DatesInteractor>()
5354
private val corePreferences = mockk<CorePreferences>()
55+
private val analytics = mockk<DatesAnalytics>()
5456

5557
private val noInternet = "Slow or no internet connection"
5658
private val somethingWrong = "Something went wrong"
@@ -63,6 +65,7 @@ class DatesViewModelTest {
6365
// By default, assume we have an internet connection
6466
every { networkConnection.isOnline() } returns true
6567
every { corePreferences.isRelativeDatesEnabled } returns true
68+
every { analytics.logEvent(any(), any()) } returns Unit
6669
}
6770

6871
@After
@@ -88,7 +91,8 @@ class DatesViewModelTest {
8891
networkConnection,
8992
resourceManager,
9093
datesInteractor,
91-
corePreferences
94+
analytics,
95+
corePreferences,
9296
)
9397
advanceUntilIdle()
9498

@@ -109,6 +113,7 @@ class DatesViewModelTest {
109113
networkConnection,
110114
resourceManager,
111115
datesInteractor,
116+
analytics,
112117
corePreferences
113118
)
114119
advanceUntilIdle()
@@ -131,6 +136,7 @@ class DatesViewModelTest {
131136
networkConnection,
132137
resourceManager,
133138
datesInteractor,
139+
analytics,
134140
corePreferences
135141
)
136142
val message = async {
@@ -155,6 +161,7 @@ class DatesViewModelTest {
155161
networkConnection,
156162
resourceManager,
157163
datesInteractor,
164+
analytics,
158165
corePreferences
159166
)
160167
val message = async {
@@ -193,6 +200,7 @@ class DatesViewModelTest {
193200
networkConnection,
194201
resourceManager,
195202
datesInteractor,
203+
analytics,
196204
corePreferences
197205
)
198206
advanceUntilIdle()
@@ -228,6 +236,7 @@ class DatesViewModelTest {
228236
networkConnection,
229237
resourceManager,
230238
datesInteractor,
239+
analytics,
231240
corePreferences
232241
)
233242
advanceUntilIdle()
@@ -251,6 +260,7 @@ class DatesViewModelTest {
251260
networkConnection,
252261
resourceManager,
253262
datesInteractor,
263+
analytics,
254264
corePreferences
255265
)
256266
val fragmentManager = mockk<FragmentManager>(relaxed = true)
@@ -266,6 +276,7 @@ class DatesViewModelTest {
266276
networkConnection,
267277
resourceManager,
268278
datesInteractor,
279+
analytics,
269280
corePreferences
270281
)
271282
val fragmentManager = mockk<FragmentManager>(relaxed = true)
@@ -308,6 +319,7 @@ class DatesViewModelTest {
308319
networkConnection,
309320
resourceManager,
310321
datesInteractor,
322+
analytics,
311323
corePreferences
312324
)
313325
advanceUntilIdle()
@@ -339,6 +351,7 @@ class DatesViewModelTest {
339351
networkConnection,
340352
resourceManager,
341353
datesInteractor,
354+
analytics,
342355
corePreferences
343356
)
344357
advanceUntilIdle()

0 commit comments

Comments
 (0)