Skip to content

Commit

Permalink
Merge pull request #28 from azrael8576/chore/datastore-test
Browse files Browse the repository at this point in the history
  • Loading branch information
azrael8576 authored Dec 10, 2023
2 parents 3b2ce1c + 9fcecca commit 1abb72e
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 3 deletions.
5 changes: 2 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,11 @@ dependencies {
implementation(project(":core:datastore"))

androidTestImplementation(project(":core:designsystem"))
// TODO Wei
// androidTestImplementation(project(":core:datastore-test"))
androidTestImplementation(project(":core:datastore-test"))
androidTestImplementation(project(":core:testing"))
androidTestImplementation(libs.androidx.navigation.testing)
androidTestImplementation(libs.accompanist.testharness)
// testImplementation(project(":core:datastore-test"))
testImplementation(project(":core:datastore-test"))
testImplementation(project(":core:testing"))
testImplementation(libs.androidx.navigation.testing)
testImplementation(libs.accompanist.testharness)
Expand Down
1 change: 1 addition & 0 deletions core/datastore-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
22 changes: 22 additions & 0 deletions core/datastore-test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
alias(libs.plugins.pq.android.library)
alias(libs.plugins.pq.android.hilt)
alias(libs.plugins.protobuf)
}

android {
namespace = "com.wei.picquest.core.datastore.test"
}

dependencies {
api(project(":core:datastore"))
implementation(project(":core:testing"))
implementation(project(":core:common"))
implementation(project(":core:model"))

// DataStore
implementation(libs.androidx.datastore)

// Protobuf
implementation(libs.protobuf.kotlin.lite)
}
4 changes: 4 additions & 0 deletions core/datastore-test/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.wei.picquest.core.datastore.test

import androidx.datastore.core.DataStore
import androidx.datastore.core.DataStoreFactory
import com.wei.picquest.core.datastore.UserPreferences
import com.wei.picquest.core.datastore.UserPreferencesSerializer
import com.wei.picquest.core.datastore.di.DataStoreModule
import com.wei.picquest.core.network.di.ApplicationScope
import dagger.Module
import dagger.Provides
import dagger.hilt.components.SingletonComponent
import dagger.hilt.testing.TestInstallIn
import kotlinx.coroutines.CoroutineScope
import org.junit.rules.TemporaryFolder
import javax.inject.Singleton

@Module
@TestInstallIn(
components = [SingletonComponent::class],
replaces = [DataStoreModule::class],
)
object TestDataStoreModule {

@Provides
@Singleton
fun providesUserPreferencesDataStore(
@ApplicationScope scope: CoroutineScope,
userPreferencesSerializer: UserPreferencesSerializer,
tmpFolder: TemporaryFolder,
): DataStore<UserPreferences> =
tmpFolder.testUserPreferencesDataStore(
coroutineScope = scope,
userPreferencesSerializer = userPreferencesSerializer,
)
}

fun TemporaryFolder.testUserPreferencesDataStore(
coroutineScope: CoroutineScope,
userPreferencesSerializer: UserPreferencesSerializer = UserPreferencesSerializer(),
) = DataStoreFactory.create(
serializer = userPreferencesSerializer,
scope = coroutineScope,
) {
newFile("user_preferences_test.pb")
}
File renamed without changes.
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ include(":core:domain")
include(":core:model")
include(":core:network")
include(":core:datastore")
include(":core:datastore-test")

include(":ui-test-hilt-manifest")

Expand Down

0 comments on commit 1abb72e

Please sign in to comment.