Skip to content

Commit cffbde3

Browse files
authored
fix: Analytics Improvements + Update test cases (#277)
- Updated the analytics with iOS parity - Updated test cases
1 parent 0a1bf3e commit cffbde3

File tree

6 files changed

+129
-35
lines changed

6 files changed

+129
-35
lines changed

course/src/main/java/org/openedx/course/presentation/CourseAnalytics.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@ enum class CourseAnalyticsEvent(val eventName: String, val biValue: String) {
139139
),
140140
PLS_BANNER_VIEWED(
141141
"PLS:Banner Viewed",
142-
"edx.bi.app.coursedates.pls_banner.viewed"
142+
"edx.bi.app.dates.pls_banner.viewed"
143143
),
144144
PLS_SHIFT_BUTTON_CLICKED(
145145
"PLS:Shift Button Clicked",
146146
"edx.bi.app.dates.pls_banner.shift_dates.clicked"
147147
),
148148
PLS_SHIFT_DATES(
149149
"PLS:Shift Dates",
150-
"edx.bi.app.coursedates.pls_banner.shift_dates"
150+
"edx.bi.app.dates.pls_banner.shift_dates"
151151
),
152152
DATES_CALENDAR_SYNC_TOGGLE(
153153
"Dates:CalendarSync Toggle",

course/src/test/java/org/openedx/course/presentation/container/CourseContainerViewModelTest.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import org.openedx.core.system.notifier.CourseStructureUpdated
3636
import org.openedx.course.data.storage.CoursePreferences
3737
import org.openedx.course.domain.interactor.CourseInteractor
3838
import org.openedx.course.presentation.CourseAnalytics
39+
import org.openedx.course.presentation.CourseAnalyticsEvent
3940
import org.openedx.course.presentation.calendarsync.CalendarManager
4041
import java.net.UnknownHostException
4142
import java.util.Date
@@ -136,12 +137,12 @@ class CourseContainerViewModelTest {
136137
)
137138
every { networkConnection.isOnline() } returns true
138139
coEvery { interactor.preloadCourseStructure(any()) } throws UnknownHostException()
139-
every { analytics.logEvent(any(), any()) } returns Unit
140+
every { analytics.logEvent(CourseAnalyticsEvent.DASHBOARD.eventName, any()) } returns Unit
140141
viewModel.preloadCourseStructure()
141142
advanceUntilIdle()
142143

143144
coVerify(exactly = 1) { interactor.preloadCourseStructure(any()) }
144-
verify(exactly = 1) { analytics.logEvent(any(), any()) }
145+
verify(exactly = 1) { analytics.logEvent(CourseAnalyticsEvent.DASHBOARD.eventName, any()) }
145146

146147
val message = viewModel.errorMessage.value
147148
assertEquals(noInternet, message)
@@ -167,12 +168,12 @@ class CourseContainerViewModelTest {
167168
)
168169
every { networkConnection.isOnline() } returns true
169170
coEvery { interactor.preloadCourseStructure(any()) } throws Exception()
170-
every { analytics.logEvent(any(), any()) } returns Unit
171+
every { analytics.logEvent(CourseAnalyticsEvent.DASHBOARD.eventName, any()) } returns Unit
171172
viewModel.preloadCourseStructure()
172173
advanceUntilIdle()
173174

174175
coVerify(exactly = 1) { interactor.preloadCourseStructure(any()) }
175-
verify(exactly = 1) { analytics.logEvent(any(), any()) }
176+
verify(exactly = 1) { analytics.logEvent(CourseAnalyticsEvent.DASHBOARD.eventName, any()) }
176177

177178
val message = viewModel.errorMessage.value
178179
assertEquals(somethingWrong, message)
@@ -199,12 +200,12 @@ class CourseContainerViewModelTest {
199200
every { networkConnection.isOnline() } returns true
200201
coEvery { interactor.preloadCourseStructure(any()) } returns Unit
201202
every { interactor.getCourseStructureFromCache() } returns courseStructure
202-
every { analytics.logEvent(any(), any()) } returns Unit
203+
every { analytics.logEvent(CourseAnalyticsEvent.DASHBOARD.eventName, any()) } returns Unit
203204
viewModel.preloadCourseStructure()
204205
advanceUntilIdle()
205206

206207
coVerify(exactly = 1) { interactor.preloadCourseStructure(any()) }
207-
verify(exactly = 1) { analytics.logEvent(any(), any()) }
208+
verify(exactly = 1) { analytics.logEvent(CourseAnalyticsEvent.DASHBOARD.eventName, any()) }
208209

209210
assert(viewModel.errorMessage.value == null)
210211
assert(viewModel.showProgress.value == false)
@@ -325,5 +326,4 @@ class CourseContainerViewModelTest {
325326
assert(viewModel.errorMessage.value == null)
326327
assert(viewModel.showProgress.value == false)
327328
}
328-
329329
}

course/src/test/java/org/openedx/course/presentation/detail/CourseDetailsViewModelTest.kt

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import org.openedx.core.system.notifier.CourseDashboardUpdate
3333
import org.openedx.core.system.notifier.CourseNotifier
3434
import org.openedx.course.domain.interactor.CourseInteractor
3535
import org.openedx.course.presentation.CourseAnalytics
36+
import org.openedx.course.presentation.CourseAnalyticsEvent
3637
import java.net.UnknownHostException
3738

3839
@OptIn(ExperimentalCoroutinesApi::class)
@@ -239,14 +240,24 @@ class CourseDetailsViewModelTest {
239240
coEvery { notifier.send(CourseDashboardUpdate()) } returns Unit
240241
every { networkConnection.isOnline() } returns true
241242
coEvery { interactor.getCourseDetails(any()) } returns mockCourse
242-
every { analytics.logEvent(any(), any()) } returns Unit
243+
every {
244+
analytics.logEvent(
245+
CourseAnalyticsEvent.COURSE_ENROLL_CLICKED.eventName,
246+
any()
247+
)
248+
} returns Unit
243249

244250

245251
viewModel.enrollInACourse("", "")
246252
advanceUntilIdle()
247253

248254
coVerify(exactly = 1) { interactor.enrollInACourse(any()) }
249-
verify(exactly = 1) { analytics.logEvent(any(), any()) }
255+
verify(exactly = 1) {
256+
analytics.logEvent(
257+
CourseAnalyticsEvent.COURSE_ENROLL_CLICKED.eventName,
258+
any()
259+
)
260+
}
250261

251262
val message = viewModel.uiMessage.value as? UIMessage.SnackBarMessage
252263
assertEquals(somethingWrong, message?.message)
@@ -267,7 +278,18 @@ class CourseDetailsViewModelTest {
267278
)
268279
every { config.isPreLoginExperienceEnabled() } returns false
269280
every { preferencesManager.user } returns null
270-
every { analytics.logEvent(any(), any()) } returns Unit
281+
every {
282+
analytics.logEvent(
283+
CourseAnalyticsEvent.COURSE_ENROLL_CLICKED.eventName,
284+
any()
285+
)
286+
} returns Unit
287+
every {
288+
analytics.logEvent(
289+
CourseAnalyticsEvent.COURSE_ENROLL_SUCCESS.eventName,
290+
any()
291+
)
292+
} returns Unit
271293
coEvery { interactor.enrollInACourse(any()) } returns Unit
272294
coEvery { notifier.send(CourseDashboardUpdate()) } returns Unit
273295
every { networkConnection.isOnline() } returns true
@@ -279,7 +301,18 @@ class CourseDetailsViewModelTest {
279301
advanceUntilIdle()
280302

281303
coVerify(exactly = 1) { interactor.enrollInACourse(any()) }
282-
verify(exactly = 2) { analytics.logEvent(any(), any()) }
304+
verify(exactly = 1) {
305+
analytics.logEvent(
306+
CourseAnalyticsEvent.COURSE_ENROLL_CLICKED.eventName,
307+
any()
308+
)
309+
}
310+
verify(exactly = 1) {
311+
analytics.logEvent(
312+
CourseAnalyticsEvent.COURSE_ENROLL_SUCCESS.eventName,
313+
any()
314+
)
315+
}
283316

284317
assert(viewModel.uiMessage.value == null)
285318
assert(viewModel.uiState.value is CourseDetailsUIState.CourseData)
@@ -318,5 +351,4 @@ class CourseDetailsViewModelTest {
318351
val count = overview.contains("black")
319352
assert(!count)
320353
}
321-
322354
}

course/src/test/java/org/openedx/course/presentation/outline/CourseOutlineViewModelTest.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import org.openedx.core.module.db.DownloadModelEntity
4747
import org.openedx.core.module.db.DownloadedState
4848
import org.openedx.core.module.db.FileType
4949
import org.openedx.core.presentation.CoreAnalytics
50+
import org.openedx.core.presentation.CoreAnalyticsEvent
5051
import org.openedx.core.system.ResourceManager
5152
import org.openedx.core.system.connection.NetworkConnection
5253
import org.openedx.core.system.notifier.CourseNotifier
@@ -439,7 +440,12 @@ class CourseOutlineViewModelTest {
439440
every { interactor.getCourseStructureFromCache() } returns courseStructure
440441
every { networkConnection.isWifiConnected() } returns true
441442
every { networkConnection.isOnline() } returns true
442-
every { coreAnalytics.logEvent(any(), any()) } returns Unit
443+
every {
444+
coreAnalytics.logEvent(
445+
CoreAnalyticsEvent.VIDEO_DOWNLOAD_SUBSECTION.eventName,
446+
any()
447+
)
448+
} returns Unit
443449
coEvery { workerController.saveModels(any()) } returns Unit
444450
coEvery { interactor.getCourseStatus(any()) } returns CourseComponentStatus("id")
445451
coEvery { downloadDao.readAllData() } returns flow { emit(emptyList()) }
@@ -461,7 +467,12 @@ class CourseOutlineViewModelTest {
461467

462468
viewModel.saveDownloadModels("", "")
463469
advanceUntilIdle()
464-
verify(exactly = 1) { coreAnalytics.logEvent(any(), any()) }
470+
verify(exactly = 1) {
471+
coreAnalytics.logEvent(
472+
CoreAnalyticsEvent.VIDEO_DOWNLOAD_SUBSECTION.eventName,
473+
any()
474+
)
475+
}
465476

466477
assert(viewModel.uiMessage.value == null)
467478
}
@@ -530,5 +541,4 @@ class CourseOutlineViewModelTest {
530541
assert(viewModel.uiMessage.value != null)
531542
assert(!viewModel.hasInternetConnection)
532543
}
533-
534544
}

course/src/test/java/org/openedx/course/presentation/unit/video/VideoUnitViewModelTest.kt

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import io.mockk.verify
1212
import kotlinx.coroutines.Dispatchers
1313
import kotlinx.coroutines.ExperimentalCoroutinesApi
1414
import kotlinx.coroutines.flow.flow
15-
import kotlinx.coroutines.test.*
15+
import kotlinx.coroutines.test.StandardTestDispatcher
16+
import kotlinx.coroutines.test.advanceUntilIdle
17+
import kotlinx.coroutines.test.resetMain
18+
import kotlinx.coroutines.test.runTest
19+
import kotlinx.coroutines.test.setMain
1620
import org.junit.After
1721
import org.junit.Before
1822
import org.junit.Rule
@@ -24,6 +28,7 @@ import org.openedx.core.system.notifier.CourseNotifier
2428
import org.openedx.core.system.notifier.CourseVideoPositionChanged
2529
import org.openedx.course.data.repository.CourseRepository
2630
import org.openedx.course.presentation.CourseAnalytics
31+
import org.openedx.course.presentation.CourseAnalyticsEvent
2732

2833
@OptIn(ExperimentalCoroutinesApi::class)
2934
class VideoUnitViewModelTest {
@@ -66,7 +71,12 @@ class VideoUnitViewModelTest {
6671
any()
6772
)
6873
} throws Exception()
69-
every { courseAnalytics.logEvent(any(), any()) } returns Unit
74+
every {
75+
courseAnalytics.logEvent(
76+
CourseAnalyticsEvent.VIDEO_COMPLETED.eventName,
77+
any()
78+
)
79+
} returns Unit
7080
viewModel.markBlockCompleted("", "")
7181
advanceUntilIdle()
7282

@@ -76,7 +86,12 @@ class VideoUnitViewModelTest {
7686
any()
7787
)
7888
}
79-
verify(exactly = 1) { courseAnalytics.logEvent(any(), any()) }
89+
verify(exactly = 1) {
90+
courseAnalytics.logEvent(
91+
CourseAnalyticsEvent.VIDEO_COMPLETED.eventName,
92+
any()
93+
)
94+
}
8095
}
8196

8297
@Test
@@ -95,7 +110,12 @@ class VideoUnitViewModelTest {
95110
any()
96111
)
97112
} returns Unit
98-
every { courseAnalytics.logEvent(any(), any()) } returns Unit
113+
every {
114+
courseAnalytics.logEvent(
115+
CourseAnalyticsEvent.VIDEO_COMPLETED.eventName,
116+
any()
117+
)
118+
} returns Unit
99119
viewModel.markBlockCompleted("", "")
100120
advanceUntilIdle()
101121

@@ -105,7 +125,12 @@ class VideoUnitViewModelTest {
105125
any()
106126
)
107127
}
108-
verify(exactly = 1) { courseAnalytics.logEvent(any(), any()) }
128+
verify(exactly = 1) {
129+
courseAnalytics.logEvent(
130+
CourseAnalyticsEvent.VIDEO_COMPLETED.eventName,
131+
any()
132+
)
133+
}
109134
}
110135

111136
@Test

course/src/test/java/org/openedx/course/presentation/unit/video/VideoViewModelTest.kt

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
package org.openedx.course.presentation.unit.video
22

33
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
4-
import org.openedx.core.system.notifier.CourseNotifier
5-
import org.openedx.core.system.notifier.CourseVideoPositionChanged
6-
import org.openedx.course.data.repository.CourseRepository
74
import io.mockk.coEvery
85
import io.mockk.coVerify
96
import io.mockk.every
107
import io.mockk.mockk
118
import io.mockk.verify
129
import kotlinx.coroutines.Dispatchers
1310
import kotlinx.coroutines.ExperimentalCoroutinesApi
14-
import kotlinx.coroutines.test.*
11+
import kotlinx.coroutines.test.StandardTestDispatcher
12+
import kotlinx.coroutines.test.advanceUntilIdle
13+
import kotlinx.coroutines.test.resetMain
14+
import kotlinx.coroutines.test.runTest
15+
import kotlinx.coroutines.test.setMain
1516
import org.junit.After
1617
import org.junit.Before
1718
import org.junit.Rule
1819
import org.junit.Test
1920
import org.junit.rules.TestRule
2021
import org.openedx.core.data.storage.CorePreferences
22+
import org.openedx.core.system.notifier.CourseNotifier
23+
import org.openedx.core.system.notifier.CourseVideoPositionChanged
24+
import org.openedx.course.data.repository.CourseRepository
2125
import org.openedx.course.presentation.CourseAnalytics
26+
import org.openedx.course.presentation.CourseAnalyticsEvent
2227

2328
@OptIn(ExperimentalCoroutinesApi::class)
2429
class VideoViewModelTest {
@@ -45,7 +50,8 @@ class VideoViewModelTest {
4550

4651
@Test
4752
fun `sendTime test`() = runTest {
48-
val viewModel = VideoViewModel("", courseRepository, notifier, preferenceManager, courseAnalytics)
53+
val viewModel =
54+
VideoViewModel("", courseRepository, notifier, preferenceManager, courseAnalytics)
4955
coEvery { notifier.send(CourseVideoPositionChanged("", 0, false)) } returns Unit
5056
viewModel.sendTime()
5157
advanceUntilIdle()
@@ -55,14 +61,20 @@ class VideoViewModelTest {
5561

5662
@Test
5763
fun `markBlockCompleted exception`() = runTest {
58-
val viewModel = VideoViewModel("", courseRepository, notifier, preferenceManager, courseAnalytics)
64+
val viewModel =
65+
VideoViewModel("", courseRepository, notifier, preferenceManager, courseAnalytics)
5966
coEvery {
6067
courseRepository.markBlocksCompletion(
6168
any(),
6269
any()
6370
)
6471
} throws Exception()
65-
every { courseAnalytics.logEvent(any(), any()) } returns Unit
72+
every {
73+
courseAnalytics.logEvent(
74+
CourseAnalyticsEvent.VIDEO_COMPLETED.eventName,
75+
any()
76+
)
77+
} returns Unit
6678
viewModel.markBlockCompleted("", "")
6779
advanceUntilIdle()
6880

@@ -72,20 +84,31 @@ class VideoViewModelTest {
7284
any()
7385
)
7486
}
75-
verify(exactly = 1) { courseAnalytics.logEvent(any(), any()) }
87+
verify(exactly = 1) {
88+
courseAnalytics.logEvent(
89+
CourseAnalyticsEvent.VIDEO_COMPLETED.eventName,
90+
any()
91+
)
92+
}
7693

7794
}
7895

7996
@Test
8097
fun `markBlockCompleted success`() = runTest {
81-
val viewModel = VideoViewModel("", courseRepository, notifier, preferenceManager, courseAnalytics)
98+
val viewModel =
99+
VideoViewModel("", courseRepository, notifier, preferenceManager, courseAnalytics)
82100
coEvery {
83101
courseRepository.markBlocksCompletion(
84102
any(),
85103
any()
86104
)
87105
} returns Unit
88-
every { courseAnalytics.logEvent(any(), any()) } returns Unit
106+
every {
107+
courseAnalytics.logEvent(
108+
CourseAnalyticsEvent.VIDEO_COMPLETED.eventName,
109+
any()
110+
)
111+
} returns Unit
89112
viewModel.markBlockCompleted("", "")
90113
advanceUntilIdle()
91114

@@ -95,7 +118,11 @@ class VideoViewModelTest {
95118
any()
96119
)
97120
}
98-
verify(exactly = 1) { courseAnalytics.logEvent(any(), any()) }
121+
verify(exactly = 1) {
122+
courseAnalytics.logEvent(
123+
CourseAnalyticsEvent.VIDEO_COMPLETED.eventName,
124+
any()
125+
)
126+
}
99127
}
100-
101-
}
128+
}

0 commit comments

Comments
 (0)