Skip to content

Commit

Permalink
fix: Updated the failed test cases
Browse files Browse the repository at this point in the history
fix: LEARNER-9876
  • Loading branch information
omerhabib26 committed Mar 13, 2024
1 parent d388acb commit 9a15a4f
Show file tree
Hide file tree
Showing 25 changed files with 187 additions and 138 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/org/openedx/app/di/ScreenModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@ val screenModule = module {
}
viewModel { (courseId: String, unitId: String) ->
CourseUnitContainerViewModel(
courseId,
unitId,
get(),
get(),
get(),
get(),
courseId,
unitId
)
}
viewModel { (courseId: String) ->
Expand Down Expand Up @@ -270,10 +270,10 @@ val screenModule = module {
viewModel { (courseId: String, handoutsType: String) ->
HandoutsViewModel(
courseId,
get(),
handoutsType,
get(),
get(),
get(),
)
}
viewModel { CourseSearchViewModel(get(), get(), get(), get(), get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ enum class LogistrationAnalyticEvent(val event: String) {
DISCOVERY_COURSES_SEARCH("Logistration:Discovery Courses Search"),
EXPLORE_ALL_COURSES("Logistration:Explore All Courses"),
REGISTER_CLICKED("Logistration:Register Clicked"),
REGISTER_VIEWED("Logistration:Register Viewed"),
CREATE_ACCOUNT_CLICKED("Logistration:Create Account Clicked"),
REGISTER_SUCCESSFULLY("Logistration:Register Successfully"),
SIGN_IN_CLICKED("Logistration:Sign In Clicked"),
SIGN_IN_VIEWED("Logistration:Sign In Viewed"),
FORGOT_PASSWORD_CLICKED("Logistration:Forgot Password Clicked"),
RESET_PASSWORD_CLICKED("Logistration:Reset Password Clicked"),
RESET_PASSWORD("Logistration:Reset Password"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class RestorePasswordFragment : Fragment() {
requireActivity().supportFragmentManager.popBackStackImmediate()
},
onRestoreButtonClick = {
viewModel.logResetPasswordClickedEvent()
viewModel.passwordReset(it)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class RestorePasswordViewModel(
}

fun passwordReset(email: String) {
logResetPasswordClickedEvent()
_uiState.value = RestorePasswordUIState.Loading
viewModelScope.launch {
try {
Expand Down Expand Up @@ -88,7 +87,7 @@ class RestorePasswordViewModel(
}
}

private fun logResetPasswordClickedEvent() {
fun logResetPasswordClickedEvent() {
analytics.logEvent(
LogistrationAnalyticEvent.RESET_PASSWORD_CLICKED.event,
buildMap {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ class SignInViewModel(

init {
collectAppUpgradeEvent()
logEvent(
LogistrationAnalyticEvent.SIGN_IN_VIEWED,
LogistrationAnalyticValues.SCREEN_NAVIGATION
)
}

fun login(username: String, password: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ class SignUpViewModel(

init {
collectAppUpgradeEvent()
logEvent(
LogistrationAnalyticEvent.REGISTER_VIEWED,
LogistrationAnalyticValues.SCREEN_NAVIGATION
)
}

fun getRegistrationFields() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package org.openedx.auth.presentation.restore

import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import org.openedx.auth.domain.interactor.AuthInteractor
import org.openedx.auth.presentation.AuthAnalytics
import org.openedx.core.R
import org.openedx.core.UIMessage
import org.openedx.core.system.EdxError
import org.openedx.core.system.ResourceManager
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.every
Expand All @@ -22,6 +16,15 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TestRule
import org.openedx.auth.domain.interactor.AuthInteractor
import org.openedx.auth.presentation.AuthAnalytics
import org.openedx.auth.presentation.LogistrationAnalyticEvent
import org.openedx.auth.presentation.LogistrationAnalyticKey
import org.openedx.auth.presentation.LogistrationAnalyticValues
import org.openedx.core.R
import org.openedx.core.UIMessage
import org.openedx.core.system.EdxError
import org.openedx.core.system.ResourceManager
import org.openedx.core.system.notifier.AppUpgradeNotifier
import java.net.UnknownHostException

Expand Down Expand Up @@ -66,13 +69,14 @@ class RestorePasswordViewModelTest {

@Test
fun `passwordReset empty email validation error`() = runTest {
val viewModel = RestorePasswordViewModel(interactor, resourceManager, analytics, appUpgradeNotifier)
val viewModel =
RestorePasswordViewModel(interactor, resourceManager, analytics, appUpgradeNotifier)
coEvery { interactor.passwordReset(emptyEmail) } returns true
every { analytics.resetPasswordClickedEvent(false) } returns Unit
every { analytics.logEvent(any(), any()) } returns Unit
viewModel.passwordReset(emptyEmail)
advanceUntilIdle()
coVerify(exactly = 0) { interactor.passwordReset(any()) }
verify(exactly = 1) { analytics.resetPasswordClickedEvent(false) }
verify(exactly = 1) { analytics.logEvent(any(), any()) }
verify(exactly = 1) { appUpgradeNotifier.notifier }

val message = viewModel.uiMessage.value as? UIMessage.SnackBarMessage
Expand All @@ -83,13 +87,14 @@ class RestorePasswordViewModelTest {

@Test
fun `passwordReset invalid email validation error`() = runTest {
val viewModel = RestorePasswordViewModel(interactor, resourceManager, analytics, appUpgradeNotifier)
val viewModel =
RestorePasswordViewModel(interactor, resourceManager, analytics, appUpgradeNotifier)
coEvery { interactor.passwordReset(invalidEmail) } returns true
every { analytics.resetPasswordClickedEvent(false) } returns Unit
every { analytics.logEvent(any(), any()) } returns Unit
viewModel.passwordReset(invalidEmail)
advanceUntilIdle()
coVerify(exactly = 0) { interactor.passwordReset(any()) }
verify(exactly = 1) { analytics.resetPasswordClickedEvent(false) }
verify(exactly = 1) { analytics.logEvent(any(), any()) }
verify(exactly = 1) { appUpgradeNotifier.notifier }

val message = viewModel.uiMessage.value as? UIMessage.SnackBarMessage
Expand All @@ -100,13 +105,14 @@ class RestorePasswordViewModelTest {

@Test
fun `passwordReset validation error`() = runTest {
val viewModel = RestorePasswordViewModel(interactor, resourceManager, analytics, appUpgradeNotifier)
val viewModel =
RestorePasswordViewModel(interactor, resourceManager, analytics, appUpgradeNotifier)
coEvery { interactor.passwordReset(correctEmail) } throws EdxError.ValidationException("error")
every { analytics.resetPasswordClickedEvent(false) } returns Unit
every { analytics.logEvent(any(), any()) } returns Unit
viewModel.passwordReset(correctEmail)
advanceUntilIdle()
coVerify(exactly = 1) { interactor.passwordReset(any()) }
verify(exactly = 1) { analytics.resetPasswordClickedEvent(false) }
verify(exactly = 1) { analytics.logEvent(any(), any()) }
verify(exactly = 1) { appUpgradeNotifier.notifier }

val message = viewModel.uiMessage.value as? UIMessage.SnackBarMessage
Expand All @@ -117,13 +123,14 @@ class RestorePasswordViewModelTest {

@Test
fun `passwordReset no internet error`() = runTest {
val viewModel = RestorePasswordViewModel(interactor, resourceManager, analytics, appUpgradeNotifier)
val viewModel =
RestorePasswordViewModel(interactor, resourceManager, analytics, appUpgradeNotifier)
coEvery { interactor.passwordReset(correctEmail) } throws UnknownHostException()
every { analytics.resetPasswordClickedEvent(false) } returns Unit
every { analytics.logEvent(any(), any()) } returns Unit
viewModel.passwordReset(correctEmail)
advanceUntilIdle()
coVerify(exactly = 1) { interactor.passwordReset(any()) }
verify(exactly = 1) { analytics.resetPasswordClickedEvent(false) }
verify(exactly = 1) { analytics.logEvent(any(), any()) }
verify(exactly = 1) { appUpgradeNotifier.notifier }

val message = viewModel.uiMessage.value as? UIMessage.SnackBarMessage
Expand All @@ -134,13 +141,14 @@ class RestorePasswordViewModelTest {

@Test
fun `passwordReset unknown error`() = runTest {
val viewModel = RestorePasswordViewModel(interactor, resourceManager, analytics, appUpgradeNotifier)
val viewModel =
RestorePasswordViewModel(interactor, resourceManager, analytics, appUpgradeNotifier)
coEvery { interactor.passwordReset(correctEmail) } throws Exception()
every { analytics.resetPasswordClickedEvent(false) } returns Unit
every { analytics.logEvent(any(), any()) } returns Unit
viewModel.passwordReset(correctEmail)
advanceUntilIdle()
coVerify(exactly = 1) { interactor.passwordReset(any()) }
verify(exactly = 1) { analytics.resetPasswordClickedEvent(false) }
verify(exactly = 1) { analytics.logEvent(any(), any()) }
verify(exactly = 1) { appUpgradeNotifier.notifier }

val message = viewModel.uiMessage.value as? UIMessage.SnackBarMessage
Expand All @@ -151,13 +159,14 @@ class RestorePasswordViewModelTest {

@Test
fun `unSuccess restore password`() = runTest {
val viewModel = RestorePasswordViewModel(interactor, resourceManager, analytics, appUpgradeNotifier)
val viewModel =
RestorePasswordViewModel(interactor, resourceManager, analytics, appUpgradeNotifier)
coEvery { interactor.passwordReset(correctEmail) } returns false
every { analytics.resetPasswordClickedEvent(false) } returns Unit
every { analytics.logEvent(any(), any()) } returns Unit
viewModel.passwordReset(correctEmail)
advanceUntilIdle()
coVerify(exactly = 1) { interactor.passwordReset(any()) }
verify(exactly = 1) { analytics.resetPasswordClickedEvent(false) }
verify(exactly = 1) { analytics.logEvent(any(), any()) }
verify(exactly = 1) { appUpgradeNotifier.notifier }

val message = viewModel.uiMessage.value as? UIMessage.SnackBarMessage
Expand All @@ -169,13 +178,14 @@ class RestorePasswordViewModelTest {

@Test
fun `success restore password`() = runTest {
val viewModel = RestorePasswordViewModel(interactor, resourceManager, analytics, appUpgradeNotifier)
val viewModel =
RestorePasswordViewModel(interactor, resourceManager, analytics, appUpgradeNotifier)
coEvery { interactor.passwordReset(correctEmail) } returns true
every { analytics.resetPasswordClickedEvent(true) } returns Unit
every { analytics.logEvent(any(), any()) } returns Unit
viewModel.passwordReset(correctEmail)
advanceUntilIdle()
coVerify(exactly = 1) { interactor.passwordReset(any()) }
verify(exactly = 1) { analytics.resetPasswordClickedEvent(true) }
verify(exactly = 1) { analytics.logEvent(any(), any()) }
verify(exactly = 1) { appUpgradeNotifier.notifier }

val state = viewModel.uiState.value as? RestorePasswordUIState.Success
Expand All @@ -185,6 +195,4 @@ class RestorePasswordViewModelTest {
assertEquals(true, viewModel.uiState.value is RestorePasswordUIState.Success)
assertEquals(null, message)
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class SignInViewModelTest {
fun `login success`() = runTest {
every { validator.isEmailOrUserNameValid(any()) } returns true
every { validator.isPasswordValid(any()) } returns true
every { analytics.userLoginEvent(any()) } returns Unit
every { analytics.logEvent(any(), any()) } returns Unit
every { preferencesManager.user } returns user
every { analytics.setUserIdForSession(any()) } returns Unit
val viewModel = SignInViewModel(
Expand All @@ -247,7 +247,7 @@ class SignInViewModelTest {
advanceUntilIdle()

coVerify(exactly = 1) { interactor.login(any(), any()) }
verify(exactly = 1) { analytics.userLoginEvent(any()) }
verify(exactly = 1) { analytics.logEvent(any(), any()) }
verify(exactly = 1) { analytics.setUserIdForSession(any()) }
verify(exactly = 1) { appUpgradeNotifier.notifier }
val uiState = viewModel.uiState.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class SignUpViewModelTest {
parametersMap
)
coEvery { interactor.getRegistrationFields() } returns listOfFields
every { analytics.createAccountClickedEvent(any()) } returns Unit
every { analytics.logEvent(any(), any()) } returns Unit
coEvery { interactor.register(parametersMap) } returns Unit
coEvery { interactor.login("", "") } returns Unit
every { preferencesManager.user } returns user
Expand All @@ -158,7 +158,7 @@ class SignUpViewModelTest {
viewModel.register()
advanceUntilIdle()
coVerify(exactly = 1) { interactor.validateRegistrationFields(any()) }
verify(exactly = 1) { analytics.createAccountClickedEvent(any()) }
verify(exactly = 1) { analytics.logEvent(any(), any()) }
coVerify(exactly = 0) { interactor.register(any()) }
coVerify(exactly = 0) { interactor.login(any(), any()) }
verify(exactly = 0) { analytics.setUserIdForSession(any()) }
Expand Down Expand Up @@ -195,7 +195,7 @@ class SignUpViewModelTest {
parametersMap.getValue(ApiConstants.PASSWORD)
)
} returns Unit
every { analytics.createAccountClickedEvent(any()) } returns Unit
every { analytics.logEvent(any(), any()) } returns Unit
every { preferencesManager.user } returns user
every { analytics.setUserIdForSession(any()) } returns Unit
viewModel.getRegistrationFields()
Expand All @@ -205,7 +205,7 @@ class SignUpViewModelTest {
}
viewModel.register()
advanceUntilIdle()
verify(exactly = 1) { analytics.createAccountClickedEvent(any()) }
verify(exactly = 1) { analytics.logEvent(any(), any()) }
verify(exactly = 0) { analytics.setUserIdForSession(any()) }
coVerify(exactly = 1) { interactor.validateRegistrationFields(any()) }
coVerify(exactly = 0) { interactor.register(any()) }
Expand Down Expand Up @@ -238,13 +238,13 @@ class SignUpViewModelTest {
coEvery { interactor.validateRegistrationFields(parametersMap) } throws Exception()
coEvery { interactor.register(parametersMap) } returns Unit
coEvery { interactor.login("", "") } returns Unit
every { analytics.createAccountClickedEvent(any()) } returns Unit
every { analytics.logEvent(any(), any()) } returns Unit
every { preferencesManager.user } returns user
every { analytics.setUserIdForSession(any()) } returns Unit
viewModel.register()
advanceUntilIdle()
verify(exactly = 0) { analytics.setUserIdForSession(any()) }
verify(exactly = 1) { analytics.createAccountClickedEvent(any()) }
verify(exactly = 1) { analytics.logEvent(any(), any()) }
coVerify(exactly = 1) { interactor.validateRegistrationFields(any()) }
coVerify(exactly = 0) { interactor.register(any()) }
coVerify(exactly = 0) { interactor.login(any(), any()) }
Expand Down Expand Up @@ -274,8 +274,8 @@ class SignUpViewModelTest {
coEvery { interactor.validateRegistrationFields(parametersMap) } returns ValidationFields(
emptyMap()
)
every { analytics.createAccountClickedEvent(any()) } returns Unit
every { analytics.registrationSuccessEvent(any()) } returns Unit
every { analytics.logEvent(any(), any()) } returns Unit
coEvery { analytics.logEvent(any(), any()) } returns Unit
coEvery { interactor.getRegistrationFields() } returns listOfFields
coEvery { interactor.register(parametersMap) } returns Unit
coEvery {
Expand All @@ -297,8 +297,7 @@ class SignUpViewModelTest {
coVerify(exactly = 1) { interactor.validateRegistrationFields(any()) }
coVerify(exactly = 1) { interactor.register(any()) }
coVerify(exactly = 1) { interactor.login(any(), any()) }
verify(exactly = 1) { analytics.createAccountClickedEvent(any()) }
verify(exactly = 1) { analytics.registrationSuccessEvent(any()) }
verify(exactly = 2) { analytics.logEvent(any(), any()) }
verify(exactly = 1) { appUpgradeNotifier.notifier }

assertFalse(viewModel.uiState.value.validationError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import org.openedx.course.presentation.CourseAnalytics

class HandoutsViewModel(
private val courseId: String,
val handoutsType: String,
private val config: Config,
private val handoutsType: String,
private val interactor: CourseInteractor,
private val courseAnalytics: CourseAnalytics,
) : BaseViewModel() {
Expand All @@ -30,11 +30,6 @@ class HandoutsViewModel(

init {
getEnrolledCourse()
if (HandoutsType.valueOf(handoutsType) == HandoutsType.Handouts) {
logEvent(CourseAnalyticEvent.HANDOUTS)
} else {
logEvent(CourseAnalyticEvent.ANNOUNCEMENTS)
}
}

private fun getEnrolledCourse() {
Expand Down Expand Up @@ -103,7 +98,7 @@ class HandoutsViewModel(
return java.lang.Long.toHexString(color.toLong()).substring(2, 8)
}

private fun logEvent(event: CourseAnalyticEvent) {
fun logEvent(event: CourseAnalyticEvent) {
courseAnalytics.logEvent(
event = event.event,
params = buildMap {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.openedx.core.ui.WindowType
import org.openedx.core.ui.rememberWindowSize
import org.openedx.core.ui.theme.OpenEdXTheme
import org.openedx.core.ui.theme.appColors
import org.openedx.course.presentation.CourseAnalyticEvent

class HandoutsWebViewFragment : Fragment() {

Expand Down Expand Up @@ -60,6 +61,11 @@ class HandoutsWebViewFragment : Fragment() {
})
}
}
if (HandoutsType.valueOf(viewModel.handoutsType) == HandoutsType.Handouts) {
viewModel.logEvent(CourseAnalyticEvent.HANDOUTS)
} else {
viewModel.logEvent(CourseAnalyticEvent.ANNOUNCEMENTS)
}
}

companion object {
Expand Down
Loading

0 comments on commit 9a15a4f

Please sign in to comment.