Skip to content

Commit

Permalink
feat: add more debug information (WPB-14930)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbakhtiarov committed Dec 11, 2024
1 parent dd6f326 commit 9063f9a
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ fun DebugDataOptionsContent(

Column {
SettingsItem(
title = "Federation Enabled",
title = stringResource(R.string.debug_federation_enabled),
text = state.isFederationEnabled.toString(),
)
SettingsItem(
title = "Default Backend Protocol",
title = stringResource(R.string.debug_default_backend_protocol),
text = state.defaultProtocol,
)
SettingsItem(
title = "Current API Version",
text = state.currentApiVersion.toString(),
title = stringResource(R.string.debug_current_api_version),
text = state.currentApiVersion,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ data class DebugDataOptionsState(
val startGettingE2EICertificate: Boolean = false,
val analyticsTrackingId: String = "null",
val isFederationEnabled: Boolean = false,
val currentApiVersion: Int = 0,
val currentApiVersion: String = "",
val defaultProtocol: String = "null",
)
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.wire.android.util.getGitBuildId
import com.wire.android.util.ui.UIText
import com.wire.kalium.logic.CoreFailure
import com.wire.kalium.logic.E2EIFailure
import com.wire.kalium.logic.configuration.server.CommonApiVersionType
import com.wire.kalium.logic.data.user.SupportedProtocol
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.feature.analytics.GetCurrentAnalyticsTrackingIdentifierUseCase
Expand Down Expand Up @@ -128,7 +129,10 @@ class DebugDataOptionsViewModelImpl
if (result is SelfServerConfigUseCase.Result.Success) {
state = state.copy(
isFederationEnabled = result.serverLinks.metaData.federation,
currentApiVersion = result.serverLinks.metaData.commonApiVersion.version,
currentApiVersion = when (result.serverLinks.metaData.commonApiVersion) {
CommonApiVersionType.Unknown -> "Unknown"
else -> result.serverLinks.metaData.commonApiVersion.version.toString()
},
)
}
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<string name="debug_analytics_tracking_identifier_title" translatable="false">
Analytics Tracking Identifier
</string>
<string name="debug_federation_enabled" translatable="false">Federation Enabled</string>
<string name="debug_default_backend_protocol" translatable="false">
Default Backend Protocol
</string>
<string name="debug_current_api_version" translatable="false">Current API Version</string>
<string name="label_new">New</string>
<string name="label_login">Login</string>
<string name="label_ok">OK</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,66 @@ class DebugDataOptionsViewModelTest {
assertEquals(UIText.DynamicString("Can't register token, error: error message"), result)
}
}

@Test
fun `given that Proteus protocol is used, view state should have Proteus protocol name`() = runTest {
// given
val (_, viewModel) = DebugDataOptionsHiltArrangement()
.withProteusProtocolSetup()
.arrange()

assertEquals("Proteus", viewModel.state.defaultProtocol)
}

@Test
fun `given that Mls protocol is used, view state should have proteus Mls name`() = runTest {
// given
val (_, viewModel) = DebugDataOptionsHiltArrangement()
.withMlsProtocolSetup()
.arrange()

assertEquals("MLS", viewModel.state.defaultProtocol)
}

@Test
fun `given that federation is disabled, view state should have federation value of false`() = runTest {
// given
val (_, viewModel) = DebugDataOptionsHiltArrangement()
.withFederationDisabled()
.arrange()

assertEquals(false, viewModel.state.isFederationEnabled)
}

@Test
fun `given that federation is enabled, view state should have federation value of true`() = runTest {
// given
val (_, viewModel) = DebugDataOptionsHiltArrangement()
.withFederationEnabled()
.arrange()

assertEquals(true, viewModel.state.isFederationEnabled)
}

@Test
fun `given that api version is unknown, view state should have api version unknown`() = runTest {
// given
val (_, viewModel) = DebugDataOptionsHiltArrangement()
.withApiVersionUnknown()
.arrange()

assertEquals("Unknown", viewModel.state.currentApiVersion)
}

@Test
fun `given that api version is set, view state should have api version set`() = runTest {
// given
val (_, viewModel) = DebugDataOptionsHiltArrangement()
.withApiVersionSet(7)
.arrange()

assertEquals("7", viewModel.state.currentApiVersion)
}
}

internal class DebugDataOptionsHiltArrangement {
Expand Down Expand Up @@ -253,4 +313,80 @@ internal class DebugDataOptionsHiltArrangement {
sendFCMToken()
} returns Either.Left(SendFCMTokenError(SendFCMTokenError.Reason.CANT_REGISTER_TOKEN, "error message"))
}

fun withProteusProtocolSetup() = apply {
every {
getDefaultProtocolUseCase()
} returns SupportedProtocol.PROTEUS
}

fun withMlsProtocolSetup() = apply {
every {
getDefaultProtocolUseCase()
} returns SupportedProtocol.MLS
}

fun withFederationEnabled() = apply {
coEvery {
selfServerConfigUseCase()
} returns SelfServerConfigUseCase.Result.Success(
ServerConfig(
id = "id",
links = mockk(),
metaData = ServerConfig.MetaData(
federation = true,
commonApiVersion = CommonApiVersionType.Unknown,
domain = null,
)
)
)
}

fun withFederationDisabled() = apply {
coEvery {
selfServerConfigUseCase()
} returns SelfServerConfigUseCase.Result.Success(
ServerConfig(
id = "id",
links = mockk(),
metaData = ServerConfig.MetaData(
federation = false,
commonApiVersion = CommonApiVersionType.Unknown,
domain = null,
)
)
)
}

fun withApiVersionUnknown() = apply {
coEvery {
selfServerConfigUseCase()
} returns SelfServerConfigUseCase.Result.Success(
ServerConfig(
id = "id",
links = mockk(),
metaData = ServerConfig.MetaData(
federation = true,
commonApiVersion = CommonApiVersionType.Unknown,
domain = null,
)
)
)
}

fun withApiVersionSet(version: Int) = apply {
coEvery {
selfServerConfigUseCase()
} returns SelfServerConfigUseCase.Result.Success(
ServerConfig(
id = "id",
links = mockk(),
metaData = ServerConfig.MetaData(
federation = true,
commonApiVersion = CommonApiVersionType.Valid(version),
domain = null,
)
)
)
}
}

0 comments on commit 9063f9a

Please sign in to comment.