diff --git a/features/roomlist/build.gradle.kts b/features/roomlist/build.gradle.kts index 69131f1d06..fe2fd050fe 100644 --- a/features/roomlist/build.gradle.kts +++ b/features/roomlist/build.gradle.kts @@ -51,6 +51,7 @@ dependencies { testImplementation(libs.molecule.runtime) testImplementation(libs.test.truth) testImplementation(libs.test.turbine) + testImplementation(project(":libraries:matrixtest")) androidTestImplementation(libs.test.junitext) diff --git a/features/roomlist/src/test/kotlin/io/element/android/x/features/roomlist/RoomListPresenterTests.kt b/features/roomlist/src/test/kotlin/io/element/android/x/features/roomlist/RoomListPresenterTests.kt index e2e85e8db3..cd1b148ce5 100644 --- a/features/roomlist/src/test/kotlin/io/element/android/x/features/roomlist/RoomListPresenterTests.kt +++ b/features/roomlist/src/test/kotlin/io/element/android/x/features/roomlist/RoomListPresenterTests.kt @@ -20,7 +20,7 @@ import app.cash.molecule.RecompositionClock import app.cash.molecule.moleculeFlow import app.cash.turbine.test import com.google.common.truth.Truth.assertThat -import io.element.android.x.matrix.FakeMatrixClient +import io.element.android.x.libraries.matrixtest.FakeMatrixClient import io.element.android.x.matrix.core.SessionId import kotlinx.coroutines.test.runTest import org.junit.Test @@ -30,7 +30,10 @@ class RoomListPresenterTests { @Test fun `present - should start with no user and then load user with success`() = runTest { - val presenter = RoomListPresenter(FakeMatrixClient(SessionId("sessionId")), LastMessageFormatter()) + val presenter = RoomListPresenter( + FakeMatrixClient( + SessionId("sessionId") + ), LastMessageFormatter()) moleculeFlow(RecompositionClock.Immediate) { presenter.present() }.test { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 26963a3f0f..9f7df7ddb0 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -29,26 +29,15 @@ coroutines = "1.6.4" accompanist = "0.27.0" # Test -test_junit = "4.13.2" -test_runner = "1.4.0" test_core = "1.4.0" -test_mockk = "1.13.2" -test_uiautomator = "2.2.0" -test_junitext = "1.1.3" -test_barista = "4.2.0" -test_hamcrest = "2.2" -test_orchestrator = "1.4.1" -test_turbine = "0.12.1" #other coil = "2.2.2" datetime = "0.4.0" -wysiwyg = "0.7.0.1" serialization_json = "1.4.1" showkase = "1.0.0-beta14" jsoup = "1.15.3" appyx = "1.0.1" -seismic = "1.0.3" dependencycheck = "7.4.4" stem = "2.2.3" @@ -98,20 +87,20 @@ accompanist_pagerindicator = { module = "com.google.accompanist:accompanist-page accompanist_flowlayout = { module = "com.google.accompanist:accompanist-flowlayout", version.ref = "accompanist" } # Libraries -squareup_seismic = { module = "com.squareup:seismic", version.ref = "seismic" } +squareup_seismic = "com.squareup:seismic:1.0.3" # Test -test_junit = { module = "junit:junit", version.ref = "test_junit" } -test_runner = { module = "androidx.test:runner", version.ref = "test_runner" } test_core = { module = "androidx.test:core", version.ref = "test_core" } test_corektx = { module = "androidx.test:core-ktx", version.ref = "test_core" } -test_uiautomator = { module = "androidx.test.uiautomator:uiautomator", version.ref = "test_uiautomator" } -test_junitext = { module = "androidx.test.ext:junit", version.ref = "test_junitext" } -test_mockk = { module = "io.mockk:mockk", version.ref = "test_mockk" } -test_barista = { module = "com.adevinta.android:barista", version.ref = "test_barista" } -test_hamcrest = { module = "org.hamcrest:hamcrest", version.ref = "test_hamcrest" } -test_orchestrator = { module = "androidx.test:orchestrator", version.ref = "test_orchestrator" } -test_turbine = { module = "app.cash.turbine:turbine", version.ref = "test_turbine"} +test_junit = "junit:junit:4.13.2" +test_runner = "androidx.test:runner:1.4.0" +test_uiautomator = "androidx.test.uiautomator:uiautomator:2.2.0" +test_junitext = "androidx.test.ext:junit:1.1.3" +test_mockk = "io.mockk:mockk:1.13.2" +test_barista = "com.adevinta.android:barista:4.2.0" +test_hamcrest = "org.hamcrest:hamcrest:2.2" +test_orchestrator = "androidx.test:orchestrator:1.4.1" +test_turbine = "app.cash.turbine:turbine:0.12.1" test_truth = "com.google.truth:truth:1.1.3" @@ -123,18 +112,18 @@ serialization_json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-jso showkase = { module = "com.airbnb.android:showkase", version.ref = "showkase" } showkase_processor = { module = "com.airbnb.android:showkase-processor", version.ref = "showkase" } jsoup = { module = "org.jsoup:jsoup", version.ref = "jsoup" } -appyx_core = {module = "com.bumble.appyx:core", version.ref = "appyx"} +appyx_core = { module = "com.bumble.appyx:core", version.ref = "appyx" } molecule-runtime = { module = "app.cash.molecule:molecule-runtime", version.ref = "molecule" } # Di -inject = { module = "javax.inject:javax.inject", version = "1" } +inject = "javax.inject:javax.inject:1" dagger = { module = "com.google.dagger:dagger", version.ref = "dagger" } dagger_compiler = { module = "com.google.dagger:dagger-compiler", version.ref = "dagger" } anvil_compiler_api = { module = "com.squareup.anvil:compiler-api", version.ref = "anvil" } anvil_compiler_utils = { module = "com.squareup.anvil:compiler-utils", version.ref = "anvil" } # Composer -wysiwyg = { module = "io.element.android:wysiwyg", version.ref = "wysiwyg" } +wysiwyg = "io.element.android:wysiwyg:0.7.1" [bundles] diff --git a/libraries/architecture/src/main/kotlin/io/element/android/x/architecture/Bindings.kt b/libraries/architecture/src/main/kotlin/io/element/android/x/architecture/Bindings.kt index fadb0764dd..be09103db3 100644 --- a/libraries/architecture/src/main/kotlin/io/element/android/x/architecture/Bindings.kt +++ b/libraries/architecture/src/main/kotlin/io/element/android/x/architecture/Bindings.kt @@ -19,6 +19,7 @@ package io.element.android.x.architecture import android.content.Context import android.content.ContextWrapper import com.bumble.appyx.core.node.Node +import io.element.android.x.di.DaggerComponentOwner inline fun Node.bindings() = bindings(T::class.java) inline fun Context.bindings() = bindings(T::class.java) @@ -27,7 +28,7 @@ fun Context.bindings(klass: Class): T { // search dagger components in the context hierarchy return generateSequence(this) { (it as? ContextWrapper)?.baseContext } .plus(applicationContext) - .filterIsInstance() + .filterIsInstance() .map { it.daggerComponent } .flatMap { if (it is Collection<*>) it else listOf(it) } .filterIsInstance(klass) @@ -38,7 +39,7 @@ fun Context.bindings(klass: Class): T { fun Node.bindings(klass: Class): T { // search dagger components in node hierarchy return generateSequence(this, Node::parent) - .filterIsInstance() + .filterIsInstance() .map { it.daggerComponent } .flatMap { if (it is Collection<*>) it else listOf(it) } .filterIsInstance(klass) diff --git a/libraries/matrix/src/main/kotlin/io/element/android/x/matrix/media/MediaResolver.kt b/libraries/matrix/src/main/kotlin/io/element/android/x/matrix/media/MediaResolver.kt index e89c7fa390..0fb796a421 100644 --- a/libraries/matrix/src/main/kotlin/io/element/android/x/matrix/media/MediaResolver.kt +++ b/libraries/matrix/src/main/kotlin/io/element/android/x/matrix/media/MediaResolver.kt @@ -16,9 +16,7 @@ package io.element.android.x.matrix.media -import io.element.android.x.matrix.MatrixClient import org.matrix.rustcomponents.sdk.MediaSource -import org.matrix.rustcomponents.sdk.mediaSourceFromUrl interface MediaResolver { @@ -39,23 +37,3 @@ interface MediaResolver { suspend fun resolve(meta: Meta): ByteArray? } - -internal class RustMediaResolver(private val client: MatrixClient) : MediaResolver { - - override suspend fun resolve(url: String?, kind: MediaResolver.Kind): ByteArray? { - if (url.isNullOrEmpty()) return null - val mediaSource = mediaSourceFromUrl(url) - return resolve(MediaResolver.Meta(mediaSource, kind)) - } - - override suspend fun resolve(meta: MediaResolver.Meta): ByteArray? { - return when (meta.kind) { - is MediaResolver.Kind.Content -> client.loadMediaContentForSource(meta.source) - is MediaResolver.Kind.Thumbnail -> client.loadMediaThumbnailForSource( - meta.source, - meta.kind.width.toLong(), - meta.kind.height.toLong() - ) - }.getOrNull() - } -} diff --git a/libraries/matrix/src/main/kotlin/io/element/android/x/matrix/media/RustMediaResolver.kt b/libraries/matrix/src/main/kotlin/io/element/android/x/matrix/media/RustMediaResolver.kt new file mode 100644 index 0000000000..f8c1ca3868 --- /dev/null +++ b/libraries/matrix/src/main/kotlin/io/element/android/x/matrix/media/RustMediaResolver.kt @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.x.matrix.media + +import io.element.android.x.matrix.MatrixClient +import org.matrix.rustcomponents.sdk.mediaSourceFromUrl + +internal class RustMediaResolver(private val client: MatrixClient) : MediaResolver { + + override suspend fun resolve(url: String?, kind: MediaResolver.Kind): ByteArray? { + if (url.isNullOrEmpty()) return null + val mediaSource = mediaSourceFromUrl(url) + return resolve(MediaResolver.Meta(mediaSource, kind)) + } + + override suspend fun resolve(meta: MediaResolver.Meta): ByteArray? { + return when (meta.kind) { + is MediaResolver.Kind.Content -> client.loadMediaContentForSource(meta.source) + is MediaResolver.Kind.Thumbnail -> client.loadMediaThumbnailForSource( + meta.source, + meta.kind.width.toLong(), + meta.kind.height.toLong() + ) + }.getOrNull() + } +} diff --git a/libraries/matrixtest/build.gradle.kts b/libraries/matrixtest/build.gradle.kts new file mode 100644 index 0000000000..f4ba43aaac --- /dev/null +++ b/libraries/matrixtest/build.gradle.kts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TODO: Remove once https://youtrack.jetbrains.com/issue/KTIJ-19369 is fixed +@Suppress("DSL_SCOPE_VIOLATION") +plugins { + id("io.element.android-library") +} + +android { + namespace = "io.element.android.x.libraries.matrix.test" +} + +dependencies { + api(project(":libraries:matrix")) + api(libs.coroutines.core) +} diff --git a/libraries/matrixtest/src/main/AndroidManifest.xml b/libraries/matrixtest/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..6a35d06cce --- /dev/null +++ b/libraries/matrixtest/src/main/AndroidManifest.xml @@ -0,0 +1,18 @@ + + + + diff --git a/libraries/matrix/src/main/kotlin/io/element/android/x/matrix/FakeMatrixClient.kt b/libraries/matrixtest/src/main/kotlin/io/element/android/x/libraries/matrixtest/FakeMatrixClient.kt similarity index 86% rename from libraries/matrix/src/main/kotlin/io/element/android/x/matrix/FakeMatrixClient.kt rename to libraries/matrixtest/src/main/kotlin/io/element/android/x/libraries/matrixtest/FakeMatrixClient.kt index f90540da83..5e55b6dc79 100644 --- a/libraries/matrix/src/main/kotlin/io/element/android/x/matrix/FakeMatrixClient.kt +++ b/libraries/matrixtest/src/main/kotlin/io/element/android/x/libraries/matrixtest/FakeMatrixClient.kt @@ -14,15 +14,16 @@ * limitations under the License. */ -package io.element.android.x.matrix +package io.element.android.x.libraries.matrixtest +import io.element.android.x.matrix.MatrixClient import io.element.android.x.matrix.core.RoomId import io.element.android.x.matrix.core.SessionId import io.element.android.x.matrix.core.UserId -import io.element.android.x.matrix.media.FakeMediaResolver +import io.element.android.x.libraries.matrixtest.media.FakeMediaResolver import io.element.android.x.matrix.media.MediaResolver -import io.element.android.x.matrix.room.FakeMatrixRoom -import io.element.android.x.matrix.room.InMemoryRoomSummaryDataSource +import io.element.android.x.libraries.matrixtest.room.FakeMatrixRoom +import io.element.android.x.libraries.matrixtest.room.InMemoryRoomSummaryDataSource import io.element.android.x.matrix.room.MatrixRoom import io.element.android.x.matrix.room.RoomSummaryDataSource import org.matrix.rustcomponents.sdk.MediaSource diff --git a/libraries/matrix/src/main/kotlin/io/element/android/x/matrix/media/FakeMediaResolver.kt b/libraries/matrixtest/src/main/kotlin/io/element/android/x/libraries/matrixtest/media/FakeMediaResolver.kt similarity index 88% rename from libraries/matrix/src/main/kotlin/io/element/android/x/matrix/media/FakeMediaResolver.kt rename to libraries/matrixtest/src/main/kotlin/io/element/android/x/libraries/matrixtest/media/FakeMediaResolver.kt index a84997c511..07fc24c468 100644 --- a/libraries/matrix/src/main/kotlin/io/element/android/x/matrix/media/FakeMediaResolver.kt +++ b/libraries/matrixtest/src/main/kotlin/io/element/android/x/libraries/matrixtest/media/FakeMediaResolver.kt @@ -14,7 +14,9 @@ * limitations under the License. */ -package io.element.android.x.matrix.media +package io.element.android.x.libraries.matrixtest.media + +import io.element.android.x.matrix.media.MediaResolver class FakeMediaResolver : MediaResolver { override suspend fun resolve(url: String?, kind: MediaResolver.Kind): ByteArray? { diff --git a/libraries/matrix/src/main/kotlin/io/element/android/x/matrix/room/FakeMatrixRoom.kt b/libraries/matrixtest/src/main/kotlin/io/element/android/x/libraries/matrixtest/room/FakeMatrixRoom.kt similarity index 91% rename from libraries/matrix/src/main/kotlin/io/element/android/x/matrix/room/FakeMatrixRoom.kt rename to libraries/matrixtest/src/main/kotlin/io/element/android/x/libraries/matrixtest/room/FakeMatrixRoom.kt index 46154bba37..fca74a59d9 100644 --- a/libraries/matrix/src/main/kotlin/io/element/android/x/matrix/room/FakeMatrixRoom.kt +++ b/libraries/matrixtest/src/main/kotlin/io/element/android/x/libraries/matrixtest/room/FakeMatrixRoom.kt @@ -14,11 +14,12 @@ * limitations under the License. */ -package io.element.android.x.matrix.room +package io.element.android.x.libraries.matrixtest.room import io.element.android.x.matrix.core.EventId import io.element.android.x.matrix.core.RoomId -import io.element.android.x.matrix.timeline.FakeMatrixTimeline +import io.element.android.x.matrix.room.MatrixRoom +import io.element.android.x.libraries.matrixtest.timeline.FakeMatrixTimeline import io.element.android.x.matrix.timeline.MatrixTimeline import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.emptyFlow diff --git a/libraries/matrix/src/main/kotlin/io/element/android/x/matrix/room/InMemoryRoomSummaryDataSource.kt b/libraries/matrixtest/src/main/kotlin/io/element/android/x/libraries/matrixtest/room/InMemoryRoomSummaryDataSource.kt similarity index 84% rename from libraries/matrix/src/main/kotlin/io/element/android/x/matrix/room/InMemoryRoomSummaryDataSource.kt rename to libraries/matrixtest/src/main/kotlin/io/element/android/x/libraries/matrixtest/room/InMemoryRoomSummaryDataSource.kt index 7e2dc952ee..eaa75e1448 100644 --- a/libraries/matrix/src/main/kotlin/io/element/android/x/matrix/room/InMemoryRoomSummaryDataSource.kt +++ b/libraries/matrixtest/src/main/kotlin/io/element/android/x/libraries/matrixtest/room/InMemoryRoomSummaryDataSource.kt @@ -14,8 +14,10 @@ * limitations under the License. */ -package io.element.android.x.matrix.room +package io.element.android.x.libraries.matrixtest.room +import io.element.android.x.matrix.room.RoomSummary +import io.element.android.x.matrix.room.RoomSummaryDataSource import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.emptyFlow diff --git a/libraries/matrix/src/main/kotlin/io/element/android/x/matrix/timeline/FakeMatrixTimeline.kt b/libraries/matrixtest/src/main/kotlin/io/element/android/x/libraries/matrixtest/timeline/FakeMatrixTimeline.kt similarity index 89% rename from libraries/matrix/src/main/kotlin/io/element/android/x/matrix/timeline/FakeMatrixTimeline.kt rename to libraries/matrixtest/src/main/kotlin/io/element/android/x/libraries/matrixtest/timeline/FakeMatrixTimeline.kt index 4a7eabbb0f..27443bde6f 100644 --- a/libraries/matrix/src/main/kotlin/io/element/android/x/matrix/timeline/FakeMatrixTimeline.kt +++ b/libraries/matrixtest/src/main/kotlin/io/element/android/x/libraries/matrixtest/timeline/FakeMatrixTimeline.kt @@ -14,9 +14,11 @@ * limitations under the License. */ -package io.element.android.x.matrix.timeline +package io.element.android.x.libraries.matrixtest.timeline import io.element.android.x.matrix.core.EventId +import io.element.android.x.matrix.timeline.MatrixTimeline +import io.element.android.x.matrix.timeline.MatrixTimelineItem import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.emptyFlow import org.matrix.rustcomponents.sdk.TimelineListener @@ -24,7 +26,7 @@ import org.matrix.rustcomponents.sdk.TimelineListener class FakeMatrixTimeline : MatrixTimeline { override var callback: MatrixTimeline.Callback? - get() = TODO("Not yet implemented") + get() = null set(value) {} override val hasMoreToLoad: Boolean @@ -38,9 +40,7 @@ class FakeMatrixTimeline : MatrixTimeline { return Result.success(Unit) } - override fun addListener(timelineListener: TimelineListener) { - // - } + override fun addListener(timelineListener: TimelineListener) = Unit override fun initialize() = Unit diff --git a/settings.gradle.kts b/settings.gradle.kts index 2e1ed9af84..43e3ebb8c1 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -53,3 +53,4 @@ include(":libraries:di") include(":anvilannotations") include(":anvilcodegen") include(":libraries:architecture") +include(":libraries:matrixtest")