Skip to content

Commit fa250c8

Browse files
committed
Merge branch 'refs/heads/cloud' into dev
2 parents bf600fe + b06604d commit fa250c8

File tree

131 files changed

+3945
-1244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+3945
-1244
lines changed

.idea/androidTestResultsUserPreferences.xml

+23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/kotlinc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/other.xml

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle.kts

+26-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
id("com.android.application")
33
id("org.jetbrains.kotlin.android")
4+
kotlin("plugin.serialization") version "1.9.25"
45
}
56

67
android {
@@ -18,10 +19,11 @@ android {
1819
minSdk = 27
1920
//noinspection EditedTargetSdkVersion,ExpiredTargetSdkVersion
2021
targetSdk = 28
21-
versionCode = 12
22-
versionName = "\"0.11.4-beta\""
22+
versionCode = 14
23+
versionName = "\"0.12.0-beta\""
2324

24-
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
25+
//testInstrumentationRunner = "androidx.test.runner.CustomTestRunner"
26+
testInstrumentationRunner = "com.autosec.pie.AutoPieTestRunner"
2527
vectorDrawables {
2628
useSupportLibrary = true
2729
}
@@ -62,7 +64,7 @@ android {
6264
compose = true
6365
}
6466
composeOptions {
65-
kotlinCompilerExtensionVersion = "1.5.1"
67+
kotlinCompilerExtensionVersion = "1.5.15"
6668
}
6769
packaging {
6870
resources {
@@ -89,18 +91,38 @@ dependencies {
8991
implementation("com.blacksquircle.ui:editorkit:2.0.0")
9092
implementation("com.blacksquircle.ui:language-shell:2.0.0")
9193
implementation("androidx.work:work-runtime-ktx:2.10.0")
94+
implementation("io.ktor:ktor-client-core:2.3.7")
95+
implementation("io.ktor:ktor-client-cio:2.3.7")
96+
implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.7")
97+
implementation("io.ktor:ktor-client-content-negotiation:2.3.7")
98+
implementation("com.mikepenz:multiplatform-markdown-renderer-m3:0.28.0")
99+
implementation("com.mikepenz:multiplatform-markdown-renderer-coil3:0.28.0")
100+
implementation("io.coil-kt.coil3:coil-compose:3.0.4")
101+
implementation("io.coil-kt.coil3:coil-network-okhttp:3.0.4")
92102

93103
implementation("androidx.compose.ui:ui-graphics")
94104
implementation("androidx.compose.ui:ui-tooling-preview")
95105
implementation("androidx.compose.material3:material3")
96106
implementation("com.google.accompanist:accompanist-permissions:0.35.1-alpha")
97107
implementation("io.insert-koin:koin-android:3.5.6")
98108
implementation("androidx.constraintlayout:constraintlayout-compose:1.1.0")
109+
110+
//TEST IMPLS
111+
99112
testImplementation("junit:junit:4.13.2")
113+
testImplementation("io.mockk:mockk:1.13.16")
114+
testImplementation ("io.mockk:mockk-android:1.13.16")
115+
testImplementation ("io.mockk:mockk-agent:1.13.16")
116+
testImplementation ("org.jetbrains.kotlinx:kotlinx-coroutines-test")
100117
androidTestImplementation("androidx.test.ext:junit:1.2.1")
101118
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
102119
androidTestImplementation(platform("androidx.compose:compose-bom:2024.12.01"))
103120
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
104121
debugImplementation("androidx.compose.ui:ui-tooling")
105122
debugImplementation("androidx.compose.ui:ui-test-manifest")
123+
124+
testImplementation ("io.insert-koin:koin-test:3.5.6")
125+
testImplementation ("io.insert-koin:koin-test-junit4:3.5.6")
126+
androidTestImplementation ("io.insert-koin:koin-test:3.5.6")
127+
androidTestImplementation ("io.insert-koin:koin-test-junit4:3.5.6")
106128
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools">
3+
4+
<application
5+
android:name=".TestApplication"
6+
tools:replace="android:name">
7+
<!-- Your test-specific configurations here -->
8+
</application>
9+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,104 @@
11
package com.autosec.pie
22

3+
import android.app.Application
4+
import android.content.Context
35
import androidx.test.platform.app.InstrumentationRegistry
46
import androidx.test.ext.junit.runners.AndroidJUnit4
7+
import androidx.test.runner.AndroidJUnitRunner
8+
import com.autosec.pie.autopieapp.data.CommandModel
9+
import com.autosec.pie.di.getTestModule
10+
import com.autosec.pie.di.testModule
11+
import com.autosec.pie.autopieapp.presentation.viewModels.CommandsListScreenViewModel
12+
import kotlinx.coroutines.Dispatchers
13+
import kotlinx.coroutines.ExperimentalCoroutinesApi
14+
import kotlinx.coroutines.test.StandardTestDispatcher
15+
import kotlinx.coroutines.test.TestCoroutineScheduler
16+
import kotlinx.coroutines.test.resetMain
17+
import kotlinx.coroutines.test.runTest
18+
import kotlinx.coroutines.test.setMain
519

620
import org.junit.Test
721
import org.junit.runner.RunWith
822

923
import org.junit.Assert.*
24+
import org.junit.Before
25+
import org.junit.Rule
26+
import org.junit.rules.TestWatcher
27+
import org.junit.runner.Description
28+
import org.koin.android.ext.koin.androidContext
29+
import org.koin.core.context.GlobalContext.startKoin
30+
import org.koin.java.KoinJavaComponent.inject
31+
import org.koin.test.KoinTest
32+
import timber.log.Timber
1033

1134
/**
1235
* Instrumented test, which will execute on an Android device.
1336
*
1437
* See [testing documentation](http://d.android.com/tools/testing).
1538
*/
1639
@RunWith(AndroidJUnit4::class)
17-
class ExampleInstrumentedTest {
40+
class AutoPieInstrumentedTests : KoinTest {
41+
42+
43+
44+
@get:Rule
45+
val mainDispatcherRule = MainDispatcherRule()
46+
47+
48+
49+
private lateinit var viewModel: CommandsListScreenViewModel
50+
51+
//private val scheduler: TestCoroutineScheduler by inject(TestCoroutineScheduler::class.java)
52+
53+
54+
55+
@Before
56+
fun setup() {
57+
val application = InstrumentationRegistry.getInstrumentation().targetContext.applicationContext
58+
startKoin {
59+
androidContext(application)
60+
modules(getTestModule(mainDispatcherRule.scheduler))
61+
}
62+
63+
}
64+
1865
@Test
19-
fun useAppContext() {
20-
// Context of the app under test.
21-
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22-
assertEquals("com.autosec.pie", appContext.packageName)
66+
fun loadConfigJSON() = runTest {
67+
68+
69+
val viewModel: CommandsListScreenViewModel by inject(CommandsListScreenViewModel::class.java)
70+
71+
72+
assertNotNull(viewModel.main)
73+
74+
75+
Timber.d(viewModel.fullListOfCommands.toString())
76+
77+
78+
mainDispatcherRule.scheduler.advanceUntilIdle()
79+
80+
81+
assert(viewModel.fullListOfCommands.size == 2)
82+
}
83+
}
84+
85+
class AutoPieTestRunner : AndroidJUnitRunner() {
86+
override fun newApplication(cl: ClassLoader, className: String, context: Context): Application {
87+
return super.newApplication(cl, TestApplication::class.java.name, context)
88+
}
89+
}
90+
91+
class MainDispatcherRule : TestWatcher() {
92+
val scheduler = TestCoroutineScheduler()
93+
val testDispatcher = StandardTestDispatcher(scheduler)
94+
95+
@OptIn(ExperimentalCoroutinesApi::class)
96+
override fun starting(description: Description) {
97+
Dispatchers.setMain(testDispatcher)
98+
}
99+
100+
@OptIn(ExperimentalCoroutinesApi::class)
101+
override fun finished(description: Description) {
102+
Dispatchers.resetMain()
23103
}
24104
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.autosec.pie
2+
3+
import android.app.Application
4+
import com.autosec.pie.di.testModule
5+
import org.koin.android.ext.koin.androidContext
6+
import org.koin.core.context.GlobalContext.startKoin
7+
import timber.log.Timber
8+
9+
class TestApplication : Application() {
10+
override fun onCreate() {
11+
super.onCreate()
12+
13+
Timber.plant(Timber.DebugTree())
14+
15+
startKoin {
16+
17+
androidContext(this@TestApplication)
18+
modules(testModule)
19+
}
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.autosec.pie.core
2+
3+
import kotlinx.coroutines.CoroutineDispatcher
4+
import kotlinx.coroutines.test.StandardTestDispatcher
5+
import kotlinx.coroutines.test.TestCoroutineScheduler
6+
7+
class TestDispatchers(private val scheduler : TestCoroutineScheduler): DispatcherProvider {
8+
private val testDispatcher = StandardTestDispatcher(scheduler)
9+
override val main: CoroutineDispatcher
10+
get() = testDispatcher
11+
override val io: CoroutineDispatcher
12+
get() = testDispatcher
13+
override val default: CoroutineDispatcher
14+
get() = testDispatcher
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package com.autosec.pie.di
2+
3+
import com.autosec.pie.core.DispatcherProvider
4+
import com.autosec.pie.core.TestDispatchers
5+
import com.autosec.pie.autopieapp.data.apiService.ApiService
6+
import com.autosec.pie.autopieapp.data.apiService.ApiServiceImpl
7+
import com.autosec.pie.autopieapp.data.apiService.AutoSecHTTPClient
8+
import com.autosec.pie.autopieapp.data.apiService.HTTPClientService
9+
import com.autosec.pie.autopieapp.data.preferences.AppPreferences
10+
import com.autosec.pie.autopieapp.data.services.notifications.AutoPieNotification
11+
import com.autosec.pie.autopieapp.data.services.CronService
12+
import com.autosec.pie.autopieapp.data.services.FakeJSONService
13+
import com.autosec.pie.autopieapp.data.services.JsonService
14+
import com.autosec.pie.autopieapp.presentation.viewModels.CloudCommandsViewModel
15+
import com.autosec.pie.autopieapp.presentation.viewModels.CloudPackagesViewModel
16+
import com.autosec.pie.autopieapp.presentation.viewModels.CommandsListScreenViewModel
17+
import com.autosec.pie.autopieapp.presentation.viewModels.CreateCommandViewModel
18+
import com.autosec.pie.autopieapp.presentation.viewModels.EditCommandViewModel
19+
import com.autosec.pie.autopieapp.presentation.viewModels.InstalledPackagesViewModel
20+
import com.autosec.pie.autopieapp.presentation.viewModels.MainViewModel
21+
import com.autosec.pie.autopieapp.presentation.viewModels.ShareReceiverViewModel
22+
import kotlinx.coroutines.test.TestCoroutineScheduler
23+
import org.koin.core.module.Module
24+
import org.koin.dsl.module
25+
26+
val testModule = module {
27+
28+
29+
single<TestCoroutineScheduler> { TestCoroutineScheduler() }
30+
31+
32+
single<DispatcherProvider> { com.autosec.pie.core.TestDispatchers(get()) }
33+
34+
single<MainViewModel> { MainViewModel(get()) }
35+
single<ShareReceiverViewModel> { ShareReceiverViewModel(get()) }
36+
single<CloudCommandsViewModel> { CloudCommandsViewModel() }
37+
single<CloudPackagesViewModel> { CloudPackagesViewModel() }
38+
39+
single<HTTPClientService> { AutoSecHTTPClient() }
40+
41+
42+
single<JsonService> { FakeJSONService() }
43+
44+
single<CronService> { CronService(get()) }
45+
46+
47+
48+
single<ApiService> { ApiServiceImpl(get()) }
49+
single<CommandsListScreenViewModel> { CommandsListScreenViewModel(get()) }
50+
single<InstalledPackagesViewModel> { InstalledPackagesViewModel(get()) }
51+
single<CreateCommandViewModel> { CreateCommandViewModel(get()) }
52+
single<EditCommandViewModel> { EditCommandViewModel(get(), get()) }
53+
single<AppPreferences> { AppPreferences(get()) }
54+
single<AutoPieNotification> { AutoPieNotification(get()) }
55+
}
56+
57+
fun getTestModule(scheduler: TestCoroutineScheduler): Module {
58+
return module {
59+
60+
61+
single<TestCoroutineScheduler> { scheduler }
62+
63+
64+
single<DispatcherProvider> { com.autosec.pie.core.TestDispatchers(get()) }
65+
66+
single<MainViewModel> { MainViewModel(get()) }
67+
single<ShareReceiverViewModel> { ShareReceiverViewModel(get()) }
68+
single<CloudCommandsViewModel> { CloudCommandsViewModel() }
69+
single<CloudPackagesViewModel> { CloudPackagesViewModel() }
70+
71+
single<HTTPClientService> { AutoSecHTTPClient() }
72+
73+
74+
single<JsonService> { FakeJSONService() }
75+
76+
single<CronService> { CronService(get()) }
77+
78+
79+
80+
single<ApiService> { ApiServiceImpl(get()) }
81+
single<CommandsListScreenViewModel> { CommandsListScreenViewModel(get()) }
82+
single<InstalledPackagesViewModel> { InstalledPackagesViewModel(get()) }
83+
single<CreateCommandViewModel> { CreateCommandViewModel(get()) }
84+
single<EditCommandViewModel> { EditCommandViewModel(get(), get()) }
85+
single<AppPreferences> { AppPreferences(get()) }
86+
single<AutoPieNotification> { AutoPieNotification(get()) }
87+
}
88+
}

0 commit comments

Comments
 (0)