diff --git a/features/analytics/impl/src/test/kotlin/io/element/android/features/analytics/impl/AnalyticsOptInPresenterTest.kt b/features/analytics/impl/src/test/kotlin/io/element/android/features/analytics/impl/AnalyticsOptInPresenterTest.kt index 01e95099d9..a8e42ceb01 100644 --- a/features/analytics/impl/src/test/kotlin/io/element/android/features/analytics/impl/AnalyticsOptInPresenterTest.kt +++ b/features/analytics/impl/src/test/kotlin/io/element/android/features/analytics/impl/AnalyticsOptInPresenterTest.kt @@ -21,9 +21,8 @@ import app.cash.molecule.moleculeFlow import app.cash.turbine.test import com.google.common.truth.Truth.assertThat import io.element.android.features.analytics.api.AnalyticsOptInEvents -import io.element.android.features.analytics.impl.preferences.DefaultAnalyticsPreferencesPresenter -import io.element.android.features.analytics.test.A_BUILD_META import io.element.android.features.analytics.test.FakeAnalyticsService +import io.element.android.libraries.matrix.test.core.aBuildMeta import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest import org.junit.Test @@ -33,7 +32,7 @@ class AnalyticsOptInPresenterTest { fun `present - enable`() = runTest { val analyticsService = FakeAnalyticsService(isEnabled = false) val presenter = AnalyticsOptInPresenter( - A_BUILD_META, + aBuildMeta(), analyticsService ) moleculeFlow(RecompositionClock.Immediate) { @@ -51,7 +50,7 @@ class AnalyticsOptInPresenterTest { fun `present - not now`() = runTest { val analyticsService = FakeAnalyticsService(isEnabled = false) val presenter = AnalyticsOptInPresenter( - A_BUILD_META, + aBuildMeta(), analyticsService ) moleculeFlow(RecompositionClock.Immediate) { diff --git a/features/analytics/impl/src/test/kotlin/io/element/android/features/analytics/impl/preferences/AnalyticsPreferencesPresenterTest.kt b/features/analytics/impl/src/test/kotlin/io/element/android/features/analytics/impl/preferences/AnalyticsPreferencesPresenterTest.kt index c37bf09928..8469abe769 100644 --- a/features/analytics/impl/src/test/kotlin/io/element/android/features/analytics/impl/preferences/AnalyticsPreferencesPresenterTest.kt +++ b/features/analytics/impl/src/test/kotlin/io/element/android/features/analytics/impl/preferences/AnalyticsPreferencesPresenterTest.kt @@ -21,8 +21,8 @@ import app.cash.molecule.moleculeFlow import app.cash.turbine.test import com.google.common.truth.Truth.assertThat import io.element.android.features.analytics.api.AnalyticsOptInEvents -import io.element.android.features.analytics.test.A_BUILD_META import io.element.android.features.analytics.test.FakeAnalyticsService +import io.element.android.libraries.matrix.test.core.aBuildMeta import kotlinx.coroutines.test.runTest import org.junit.Test @@ -31,7 +31,7 @@ class AnalyticsPreferencesPresenterTest { fun `present - initial state available`() = runTest { val presenter = DefaultAnalyticsPreferencesPresenter( FakeAnalyticsService(isEnabled = true, didAskUserConsent = true), - A_BUILD_META + aBuildMeta() ) moleculeFlow(RecompositionClock.Immediate) { presenter.present() @@ -46,7 +46,7 @@ class AnalyticsPreferencesPresenterTest { fun `present - initial state not available`() = runTest { val presenter = DefaultAnalyticsPreferencesPresenter( FakeAnalyticsService(isEnabled = false, didAskUserConsent = false), - A_BUILD_META + aBuildMeta() ) moleculeFlow(RecompositionClock.Immediate) { presenter.present() @@ -60,7 +60,7 @@ class AnalyticsPreferencesPresenterTest { fun `present - enable and disable`() = runTest { val presenter = DefaultAnalyticsPreferencesPresenter( FakeAnalyticsService(isEnabled = true, didAskUserConsent = true), - A_BUILD_META + aBuildMeta() ) moleculeFlow(RecompositionClock.Immediate) { presenter.present() diff --git a/features/analytics/test/src/main/kotlin/io/element/android/features/analytics/test/TestData.kt b/features/analytics/test/src/main/kotlin/io/element/android/features/analytics/test/TestData.kt deleted file mode 100644 index 0c3631c476..0000000000 --- a/features/analytics/test/src/main/kotlin/io/element/android/features/analytics/test/TestData.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.features.analytics.test - -import io.element.android.libraries.core.meta.BuildMeta -import io.element.android.libraries.core.meta.BuildType - -val A_BUILD_META = BuildMeta( - isDebuggable = true, - buildType = BuildType.DEBUG, - applicationName = "Element X test", - applicationId = "", - lowPrivacyLoggingEnabled = false, - versionName = "", - versionCode = 0, - gitRevision = "", - gitRevisionDate = "", - gitBranchName = "", - flavorDescription = "", - flavorShortDescription = "", -) - diff --git a/features/createroom/impl/src/test/kotlin/io/element/android/features/createroom/impl/root/CreateRoomRootPresenterTests.kt b/features/createroom/impl/src/test/kotlin/io/element/android/features/createroom/impl/root/CreateRoomRootPresenterTests.kt index 8d0a22e999..408632e04a 100644 --- a/features/createroom/impl/src/test/kotlin/io/element/android/features/createroom/impl/root/CreateRoomRootPresenterTests.kt +++ b/features/createroom/impl/src/test/kotlin/io/element/android/features/createroom/impl/root/CreateRoomRootPresenterTests.kt @@ -34,6 +34,7 @@ import io.element.android.libraries.matrix.api.core.UserId import io.element.android.libraries.matrix.api.user.MatrixUser import io.element.android.libraries.matrix.test.A_THROWABLE import io.element.android.libraries.matrix.test.FakeMatrixClient +import io.element.android.libraries.matrix.test.core.aBuildMeta import io.element.android.libraries.matrix.test.room.FakeMatrixRoom import io.element.android.libraries.usersearch.test.FakeUserRepository import kotlinx.collections.immutable.persistentListOf @@ -183,19 +184,3 @@ class CreateRoomRootPresenterTests { } } } - -private fun aBuildMeta() = - BuildMeta( - buildType = BuildType.DEBUG, - isDebuggable = true, - applicationId = "", - applicationName = "An Application", - lowPrivacyLoggingEnabled = true, - versionName = "", - versionCode = 0, - gitRevision = "", - gitBranchName = "", - gitRevisionDate = "", - flavorDescription = "", - flavorShortDescription = "", - ) diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/MessagesPresenterTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/MessagesPresenterTest.kt index 028349d76f..604c9ec4a8 100644 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/MessagesPresenterTest.kt +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/MessagesPresenterTest.kt @@ -59,6 +59,7 @@ import io.element.android.libraries.matrix.test.AN_EVENT_ID import io.element.android.libraries.matrix.test.A_ROOM_ID import io.element.android.libraries.matrix.test.A_SESSION_ID import io.element.android.libraries.matrix.test.A_SESSION_ID_2 +import io.element.android.libraries.matrix.test.core.aBuildMeta import io.element.android.libraries.matrix.test.room.FakeMatrixRoom import io.element.android.libraries.matrix.test.room.aRoomMember import io.element.android.libraries.mediapickers.test.FakePickerProvider @@ -566,19 +567,7 @@ class MessagesPresenterTest { timelineItemsFactory = aTimelineItemsFactory(), room = matrixRoom, ) - val buildMeta = BuildMeta( - buildType = BuildType.DEBUG, - isDebuggable = true, - applicationId = "", - applicationName = "", - lowPrivacyLoggingEnabled = true, - versionName = "", - gitRevision = "", - gitBranchName = "", - gitRevisionDate = "", - flavorDescription = "", - flavorShortDescription = "", - ) + val buildMeta = aBuildMeta() val actionListPresenter = ActionListPresenter(buildMeta = buildMeta) val customReactionPresenter = CustomReactionPresenter() val retrySendMenuPresenter = RetrySendMenuPresenter(room = matrixRoom) diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/actionlist/ActionListPresenterTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/actionlist/ActionListPresenterTest.kt index 88334737d7..c90a03e5bb 100644 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/actionlist/ActionListPresenterTest.kt +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/actionlist/ActionListPresenterTest.kt @@ -25,13 +25,11 @@ import io.element.android.features.messages.impl.actionlist.ActionListEvents import io.element.android.features.messages.impl.actionlist.ActionListPresenter import io.element.android.features.messages.impl.actionlist.ActionListState import io.element.android.features.messages.impl.actionlist.model.TimelineItemAction -import io.element.android.features.messages.impl.timeline.model.event.TimelineItemImageContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemRedactedContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemTextContent import io.element.android.features.messages.impl.timeline.model.event.aTimelineItemImageContent -import io.element.android.libraries.core.meta.BuildMeta -import io.element.android.libraries.core.meta.BuildType import io.element.android.libraries.matrix.test.A_MESSAGE +import io.element.android.libraries.matrix.test.core.aBuildMeta import kotlinx.collections.immutable.persistentListOf import kotlinx.coroutines.test.runTest import org.junit.Test @@ -74,7 +72,6 @@ class ActionListPresenterTest { } } - @Test fun `present - compute for message from others redacted`() = runTest { val presenter = anActionListPresenter(isBuildDebuggable = true) @@ -231,31 +228,5 @@ class ActionListPresenterTest { } } -private fun aBuildMeta( - buildType: BuildType = BuildType.DEBUG, - isDebuggable: Boolean = true, - applicationName: String = "", - applicationId: String = "", - lowPrivacyLoggingEnabled: Boolean = true, - versionName: String = "", - gitRevision: String = "", - gitRevisionDate: String = "", - gitBranchName: String = "", - flavorDescription: String = "", - flavorShortDescription: String = "", -) = BuildMeta( - buildType, - isDebuggable, - applicationName, - applicationId, - lowPrivacyLoggingEnabled, - versionName, - gitRevision, - gitRevisionDate, - gitBranchName, - flavorDescription, - flavorShortDescription -) - private fun anActionListPresenter(isBuildDebuggable: Boolean) = ActionListPresenter(buildMeta = aBuildMeta(isDebuggable = isBuildDebuggable)) diff --git a/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/analytics/AnalyticsAnalyticsSettingsPresenterTest.kt b/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/analytics/AnalyticsAnalyticsSettingsPresenterTest.kt index a383bcf71b..5382ad0b37 100644 --- a/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/analytics/AnalyticsAnalyticsSettingsPresenterTest.kt +++ b/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/analytics/AnalyticsAnalyticsSettingsPresenterTest.kt @@ -21,15 +21,15 @@ import app.cash.molecule.moleculeFlow import app.cash.turbine.test import com.google.common.truth.Truth.assertThat import io.element.android.features.analytics.impl.preferences.DefaultAnalyticsPreferencesPresenter -import io.element.android.features.analytics.test.A_BUILD_META import io.element.android.features.analytics.test.FakeAnalyticsService +import io.element.android.libraries.matrix.test.core.aBuildMeta import kotlinx.coroutines.test.runTest import org.junit.Test class AnalyticsAnalyticsSettingsPresenterTest { @Test fun `present - initial state`() = runTest { - val analyticsPresenter = DefaultAnalyticsPreferencesPresenter(FakeAnalyticsService(), A_BUILD_META) + val analyticsPresenter = DefaultAnalyticsPreferencesPresenter(FakeAnalyticsService(), aBuildMeta()) val presenter = AnalyticsSettingsPresenter( analyticsPresenter, ) diff --git a/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootPresenterTest.kt b/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootPresenterTest.kt index fa3d7163cf..1dd4c6c67a 100644 --- a/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootPresenterTest.kt +++ b/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootPresenterTest.kt @@ -20,7 +20,6 @@ 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.features.analytics.test.A_BUILD_META import io.element.android.features.logout.impl.DefaultLogoutPreferencePresenter import io.element.android.libraries.architecture.Async import io.element.android.libraries.matrix.api.user.CurrentUserProvider @@ -28,6 +27,7 @@ import io.element.android.libraries.matrix.api.user.MatrixUser import io.element.android.libraries.matrix.test.AN_AVATAR_URL import io.element.android.libraries.matrix.test.A_USER_NAME import io.element.android.libraries.matrix.test.FakeMatrixClient +import io.element.android.libraries.matrix.test.core.aBuildMeta import io.element.android.libraries.matrix.test.verification.FakeSessionVerificationService import kotlinx.coroutines.test.runTest import org.junit.Test @@ -35,20 +35,21 @@ import org.junit.Test class PreferencesRootPresenterTest { @Test fun `present - initial state`() = runTest { + val buildMeta = aBuildMeta() val matrixClient = FakeMatrixClient() val logoutPresenter = DefaultLogoutPreferencePresenter(matrixClient) val presenter = PreferencesRootPresenter( logoutPresenter, CurrentUserProvider(matrixClient), FakeSessionVerificationService(), - A_BUILD_META + buildMeta, ) moleculeFlow(RecompositionClock.Immediate) { presenter.present() }.test { val initialState = awaitItem() assertThat(initialState.myUser).isNull() - assertThat(initialState.version).isEqualTo("Version " + A_BUILD_META.versionName + " (" + A_BUILD_META.versionCode + ")") + assertThat(initialState.version).isEqualTo("Version " + buildMeta.versionName + " (" + buildMeta.versionCode + ")") val loadedState = awaitItem() assertThat(loadedState.logoutState.logoutAction).isEqualTo(Async.Uninitialized) assertThat(loadedState.myUser).isEqualTo( diff --git a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/core/BuildMeta.kt b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/core/BuildMeta.kt new file mode 100644 index 0000000000..d048101f87 --- /dev/null +++ b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/core/BuildMeta.kt @@ -0,0 +1,48 @@ +/* + * 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.libraries.matrix.test.core + +import io.element.android.libraries.core.meta.BuildMeta +import io.element.android.libraries.core.meta.BuildType + +fun aBuildMeta( + buildType: BuildType = BuildType.DEBUG, + isDebuggable: Boolean = true, + applicationName: String = "", + applicationId: String = "", + lowPrivacyLoggingEnabled: Boolean = true, + versionName: String = "", + versionCode: Int = 0, + gitRevision: String = "", + gitRevisionDate: String = "", + gitBranchName: String = "", + flavorDescription: String = "", + flavorShortDescription: String = "", +) = BuildMeta( + buildType, + isDebuggable, + applicationName, + applicationId, + lowPrivacyLoggingEnabled, + versionName, + versionCode, + gitRevision, + gitRevisionDate, + gitBranchName, + flavorDescription, + flavorShortDescription +)