Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Koin upgrade followup #243

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,8 @@ import coil3.ImageLoader
import coil3.PlatformContext
import coil3.SingletonImageLoader
import coil3.memory.MemoryCache
import de.tum.informatics.www1.artemis.native_app.android.db.dbModule
import de.tum.informatics.www1.artemis.native_app.core.common.ArtemisNotificationChannel
import de.tum.informatics.www1.artemis.native_app.core.common.CurrentActivityListener
import de.tum.informatics.www1.artemis.native_app.core.data.dataModule
import de.tum.informatics.www1.artemis.native_app.core.datastore.datastoreModule
import de.tum.informatics.www1.artemis.native_app.core.device.deviceModule
import de.tum.informatics.www1.artemis.native_app.core.ui.uiModule
import de.tum.informatics.www1.artemis.native_app.core.websocket.websocketModule
import de.tum.informatics.www1.artemis.native_app.feature.courseregistration.courseRegistrationModule
import de.tum.informatics.www1.artemis.native_app.feature.courseview.courseViewModule
import de.tum.informatics.www1.artemis.native_app.feature.dashboard.dashboardModule
import de.tum.informatics.www1.artemis.native_app.feature.exerciseview.exerciseModule
import de.tum.informatics.www1.artemis.native_app.feature.lectureview.lectureModule
import de.tum.informatics.www1.artemis.native_app.feature.login.loginModule
import de.tum.informatics.www1.artemis.native_app.feature.metis.communicationModule
import de.tum.informatics.www1.artemis.native_app.feature.push.pushModule
import de.tum.informatics.www1.artemis.native_app.feature.quiz.quizParticipationModule
import de.tum.informatics.www1.artemis.native_app.feature.settings.settingsModule
import io.sentry.Sentry
import kotlinx.coroutines.flow.MutableStateFlow
import org.koin.android.ext.koin.androidContext
Expand All @@ -49,24 +33,7 @@ class ArtemisApplication : Application(), SingletonImageLoader.Factory, CurrentA
androidContext(this@ArtemisApplication)
workManagerFactory()

modules(
dataModule,
uiModule,
datastoreModule,
deviceModule,
websocketModule,
courseRegistrationModule,
courseViewModule,
dashboardModule,
loginModule,
exerciseModule,
communicationModule,
quizParticipationModule,
settingsModule,
lectureModule,
pushModule,
dbModule
)
modules(appModule)
}

ArtemisNotificationChannel.entries.forEach { notificationChannel ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package de.tum.informatics.www1.artemis.native_app.android

import de.tum.informatics.www1.artemis.native_app.android.db.dbModule
import de.tum.informatics.www1.artemis.native_app.core.data.dataModule
import de.tum.informatics.www1.artemis.native_app.core.datastore.datastoreModule
import de.tum.informatics.www1.artemis.native_app.core.device.deviceModule
import de.tum.informatics.www1.artemis.native_app.core.ui.uiModule
import de.tum.informatics.www1.artemis.native_app.core.websocket.websocketModule
import de.tum.informatics.www1.artemis.native_app.feature.courseregistration.courseRegistrationModule
import de.tum.informatics.www1.artemis.native_app.feature.courseview.courseViewModule
import de.tum.informatics.www1.artemis.native_app.feature.dashboard.dashboardModule
import de.tum.informatics.www1.artemis.native_app.feature.exerciseview.exerciseModule
import de.tum.informatics.www1.artemis.native_app.feature.lectureview.lectureModule
import de.tum.informatics.www1.artemis.native_app.feature.login.loginModule
import de.tum.informatics.www1.artemis.native_app.feature.metis.communicationModule
import de.tum.informatics.www1.artemis.native_app.feature.push.pushModule
import de.tum.informatics.www1.artemis.native_app.feature.quiz.quizParticipationModule
import de.tum.informatics.www1.artemis.native_app.feature.settings.settingsModule
import org.koin.dsl.module

val appModule = module { includes(
dataModule,
uiModule,
datastoreModule,
deviceModule,
websocketModule,
courseRegistrationModule,
courseViewModule,
dashboardModule,
loginModule,
exerciseModule,
communicationModule,
quizParticipationModule,
settingsModule,
lectureModule,
pushModule,
dbModule
)}
5 changes: 4 additions & 1 deletion feature/core-modules-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ dependencies {

implementation(libs.kotlinx.datetime)

testImplementation(project(":app"))
testImplementation(project(":core:core-test"))
testImplementation(project(":feature:login"))
testImplementation(project(":feature:login-test"))
testImplementation(project(":core:core-test"))
testImplementation(project(":feature:metis:shared"))
testImplementation(project(":feature:quiz"))

kover(project(":core:data"))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package de.tum.informatics.www1.artemis.native_app.feature.coremodulestest

import android.app.Application
import android.content.Context
import androidx.lifecycle.SavedStateHandle
import androidx.work.WorkerParameters
import de.tum.informatics.www1.artemis.native_app.android.appModule
import de.tum.informatics.www1.artemis.native_app.core.common.CurrentActivityListener
import de.tum.informatics.www1.artemis.native_app.core.common.test.UnitTest
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.StandalonePostId
import de.tum.informatics.www1.artemis.native_app.feature.quiz.QuizType
import org.junit.Test
import org.junit.experimental.categories.Category
import org.junit.runner.RunWith
import org.koin.core.annotation.KoinExperimentalAPI
import org.koin.test.verify.verify
import org.robolectric.RobolectricTestRunner
import kotlin.coroutines.CoroutineContext

@OptIn(KoinExperimentalAPI::class)
@Category(UnitTest::class)
@RunWith(RobolectricTestRunner::class)
class AppModuleTest {

@Test
fun checkKoinModule() {

// Verify Koin configuration
appModule.verify(
extraTypes = listOf(
CoroutineContext::class,
SavedStateHandle::class,
Boolean::class,
Long::class,
StandalonePostId::class,
Application::class,
CurrentActivityListener::class,
Context::class,
WorkerParameters::class,
QuizType.WorkableQuizType::class,
QuizType.ViewableQuizType::class,
)
)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.tum.informatics.www1.artemis.native_app.feature.courseview

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.test.platform.app.InstrumentationRegistry
import de.tum.informatics.www1.artemis.native_app.core.model.Course
Expand All @@ -20,10 +19,6 @@ import de.tum.informatics.www1.artemis.native_app.feature.login.test.testLoginMo
import org.junit.Before
import org.junit.Rule
import org.koin.android.ext.koin.androidContext
import org.koin.compose.LocalKoinApplication
import org.koin.compose.LocalKoinScope
import org.koin.core.annotation.KoinInternalApi
import org.koin.mp.KoinPlatformTools
import org.koin.test.KoinTestRule
import org.koin.test.get

Expand All @@ -47,7 +42,6 @@ abstract class BaseCourseTest : BaseComposeTest() {
}
}

@OptIn(KoinInternalApi::class)
internal fun setupAndDisplayCourseUi(): CourseViewModel {
val viewModel = CourseViewModel(
courseId = course.id!!,
Expand All @@ -61,27 +55,21 @@ abstract class BaseCourseTest : BaseComposeTest() {
)

composeTestRule.setContent {
CompositionLocalProvider(
LocalKoinScope provides KoinPlatformTools.defaultContext()
.get().scopeRegistry.rootScope,
LocalKoinApplication provides KoinPlatformTools.defaultContext().get()
) {
CourseUiScreen(
modifier = Modifier.fillMaxSize(),
viewModel = viewModel,
courseId = course.id!!,
conversationId = DEFAULT_CONVERSATION_ID,
postId = DEFAULT_POST_ID,
username = "",
onNavigateToExercise = {},
onNavigateToExerciseResultView = {},
onNavigateToTextExerciseParticipation = { _, _ -> },
onParticipateInQuiz = { _, _ -> },
onClickViewQuizResults = { _, _ -> },
onNavigateToLecture = {},
onNavigateBack = {}
)
}
CourseUiScreen(
modifier = Modifier.fillMaxSize(),
viewModel = viewModel,
courseId = course.id!!,
conversationId = DEFAULT_CONVERSATION_ID,
postId = DEFAULT_POST_ID,
username = "",
onNavigateToExercise = {},
onNavigateToExerciseResultView = {},
onNavigateToTextExerciseParticipation = { _, _ -> },
onParticipateInQuiz = { _, _ -> },
onClickViewQuizResults = { _, _ -> },
onNavigateToLecture = {},
onNavigateBack = {}
)
}

return viewModel
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package de.tum.informatics.www1.artemis.native_app.feature.exercise_view

import de.tum.informatics.www1.artemis.native_app.core.common.test.UnitTest
import de.tum.informatics.www1.artemis.native_app.core.data.service.network.CourseExerciseService
import de.tum.informatics.www1.artemis.native_app.core.data.service.network.ExerciseService
import de.tum.informatics.www1.artemis.native_app.core.datastore.AccountService
import de.tum.informatics.www1.artemis.native_app.core.datastore.ServerConfigurationService
import de.tum.informatics.www1.artemis.native_app.core.device.NetworkStatusProvider
import de.tum.informatics.www1.artemis.native_app.core.websocket.LiveParticipationService
import de.tum.informatics.www1.artemis.native_app.feature.exerciseview.ExerciseViewModel
import de.tum.informatics.www1.artemis.native_app.feature.exerciseview.exerciseModule
import de.tum.informatics.www1.artemis.native_app.feature.exerciseview.participate.textexercise.TextExerciseParticipationViewModel
import org.junit.Test
import org.junit.experimental.categories.Category
import org.junit.runner.RunWith
import org.koin.core.annotation.KoinExperimentalAPI
import org.koin.test.verify.definition
import org.koin.test.verify.verify
import org.robolectric.RobolectricTestRunner
import kotlin.coroutines.CoroutineContext

@RunWith(RobolectricTestRunner::class)
@Category(UnitTest::class)
internal class exercise_moduleTest {

@OptIn(KoinExperimentalAPI::class)
@Test
fun checkKoinModule() {
exerciseModule.verify(
injections = listOf(
definition<ExerciseViewModel>(Long::class),
definition<TextExerciseParticipationViewModel>(Long::class, Long::class)
),
extraTypes = listOf(
ServerConfigurationService::class,
NetworkStatusProvider::class,
AccountService::class,
CoroutineContext::class,
ExerciseService::class,
LiveParticipationService::class,
CourseExerciseService::class
)
)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.tum.informatics.www1.artemis.native_app.feature.exercise_view.participate.text_exercise

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.hasText
Expand All @@ -18,10 +17,6 @@ import de.tum.informatics.www1.artemis.native_app.feature.exerciseview.home.Exer
import org.junit.Test
import org.junit.experimental.categories.Category
import org.junit.runner.RunWith
import org.koin.compose.LocalKoinApplication
import org.koin.compose.LocalKoinScope
import org.koin.core.annotation.KoinInternalApi
import org.koin.mp.KoinPlatformTools
import org.koin.test.get
import org.robolectric.RobolectricTestRunner
import de.tum.informatics.www1.artemis.native_app.core.ui.R as CoreUiR
Expand Down Expand Up @@ -58,7 +53,6 @@ class ExerciseOverviewE2eTest : BaseExerciseTest() {
)
}

@OptIn(KoinInternalApi::class)
private fun setupUiAndViewModel(
onViewTextExerciseParticipationScreen: (participationId: Long) -> Unit = {}
): ExerciseViewModel {
Expand All @@ -74,22 +68,16 @@ class ExerciseOverviewE2eTest : BaseExerciseTest() {
)

composeTestRule.setContent {
CompositionLocalProvider(
LocalKoinScope provides KoinPlatformTools.defaultContext()
.get().scopeRegistry.rootScope,
LocalKoinApplication provides KoinPlatformTools.defaultContext().get()
) {
ExerciseScreen(
modifier = Modifier.fillMaxSize(),
viewModel = viewModel,
navController = rememberNavController(),
onNavigateBack = { },
onViewResult = { },
onViewTextExerciseParticipationScreen = onViewTextExerciseParticipationScreen,
onParticipateInQuiz = { _, _ -> },
onClickViewQuizResults = { }
)
}
ExerciseScreen(
modifier = Modifier.fillMaxSize(),
viewModel = viewModel,
navController = rememberNavController(),
onNavigateBack = { },
onViewResult = { },
onViewTextExerciseParticipationScreen = onViewTextExerciseParticipationScreen,
onParticipateInQuiz = { _, _ -> },
onClickViewQuizResults = { }
)
}

return viewModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.tum.informatics.www1.artemis.native_app.feature.lecture_view

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.hasParent
Expand Down Expand Up @@ -55,10 +54,6 @@ import org.junit.Test
import org.junit.experimental.categories.Category
import org.junit.runner.RunWith
import org.koin.android.ext.koin.androidContext
import org.koin.compose.LocalKoinApplication
import org.koin.compose.LocalKoinScope
import org.koin.core.annotation.KoinInternalApi
import org.koin.mp.KoinPlatformTools
import org.koin.test.KoinTestRule
import org.koin.test.get
import org.robolectric.RobolectricTestRunner
Expand Down Expand Up @@ -233,7 +228,6 @@ class LectureE2eTest : BaseComposeTest() {
}
}

@OptIn(KoinInternalApi::class)
private fun setupViewModelAndUi(): LectureViewModel {
val viewModel = LectureViewModel(
lectureId = lecture.id!!,
Expand All @@ -249,25 +243,19 @@ class LectureE2eTest : BaseComposeTest() {
)

composeTestRule.setContent {
CompositionLocalProvider(
LocalKoinScope provides KoinPlatformTools.defaultContext()
.get().scopeRegistry.rootScope,
LocalKoinApplication provides KoinPlatformTools.defaultContext().get()
) {
LectureScreen(
modifier = Modifier.fillMaxSize(),
courseId = course.id!!,
lectureId = lecture.id!!,
viewModel = viewModel,
navController = rememberNavController(),
onNavigateBack = { },
onViewExercise = {},
onNavigateToExerciseResultView = {},
onNavigateToTextExerciseParticipation = { _, _ -> },
onParticipateInQuiz = { _, _ -> },
onClickViewQuizResults = { _, _ -> }
)
}
LectureScreen(
modifier = Modifier.fillMaxSize(),
courseId = course.id!!,
lectureId = lecture.id!!,
viewModel = viewModel,
navController = rememberNavController(),
onNavigateBack = { },
onViewExercise = {},
onNavigateToExerciseResultView = {},
onNavigateToTextExerciseParticipation = { _, _ -> },
onParticipateInQuiz = { _, _ -> },
onClickViewQuizResults = { _, _ -> }
)
}

composeTestRule.waitUntilAtLeastOneExists(
Expand Down
Loading
Loading