Changes after review
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
@@ -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 <reified T : Any> Node.bindings() = bindings(T::class.java)
|
||||
inline fun <reified T : Any> Context.bindings() = bindings(T::class.java)
|
||||
@@ -27,7 +28,7 @@ fun <T : Any> Context.bindings(klass: Class<T>): T {
|
||||
// search dagger components in the context hierarchy
|
||||
return generateSequence(this) { (it as? ContextWrapper)?.baseContext }
|
||||
.plus(applicationContext)
|
||||
.filterIsInstance<io.element.android.x.di.DaggerComponentOwner>()
|
||||
.filterIsInstance<DaggerComponentOwner>()
|
||||
.map { it.daggerComponent }
|
||||
.flatMap { if (it is Collection<*>) it else listOf(it) }
|
||||
.filterIsInstance(klass)
|
||||
@@ -38,7 +39,7 @@ fun <T : Any> Context.bindings(klass: Class<T>): T {
|
||||
fun <T : Any> Node.bindings(klass: Class<T>): T {
|
||||
// search dagger components in node hierarchy
|
||||
return generateSequence(this, Node::parent)
|
||||
.filterIsInstance<io.element.android.x.di.DaggerComponentOwner>()
|
||||
.filterIsInstance<DaggerComponentOwner>()
|
||||
.map { it.daggerComponent }
|
||||
.flatMap { if (it is Collection<*>) it else listOf(it) }
|
||||
.filterIsInstance(klass)
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
30
libraries/matrixtest/build.gradle.kts
Normal file
30
libraries/matrixtest/build.gradle.kts
Normal file
@@ -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)
|
||||
}
|
||||
18
libraries/matrixtest/src/main/AndroidManifest.xml
Normal file
18
libraries/matrixtest/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<manifest/>
|
||||
@@ -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
|
||||
@@ -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? {
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -53,3 +53,4 @@ include(":libraries:di")
|
||||
include(":anvilannotations")
|
||||
include(":anvilcodegen")
|
||||
include(":libraries:architecture")
|
||||
include(":libraries:matrixtest")
|
||||
|
||||
Reference in New Issue
Block a user