Skip to content

Commit

Permalink
Add minimal leak tests for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasberglund committed Sep 27, 2024
1 parent 8135aea commit c474f32
Show file tree
Hide file tree
Showing 15 changed files with 601 additions and 5,995 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
Expand All @@ -33,6 +34,8 @@ import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.compose.component.Chevron
import net.mullvad.mullvadvpn.compose.component.MullvadCheckbox
import net.mullvad.mullvadvpn.compose.preview.RelayItemCheckableCellPreviewParameterProvider
import net.mullvad.mullvadvpn.compose.test.EXPAND_BUTTON_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.LOCATION_CELL_TEST_TAG
import net.mullvad.mullvadvpn.lib.model.RelayItem
import net.mullvad.mullvadvpn.lib.theme.AppTheme
import net.mullvad.mullvadvpn.lib.theme.Dimens
Expand All @@ -55,6 +58,7 @@ private fun PreviewCheckableRelayLocationCell(
expanded = false,
depth = 0,
onExpand = {},
modifier = Modifier.testTag(LOCATION_CELL_TEST_TAG),
)
}
}
Expand Down Expand Up @@ -166,6 +170,7 @@ fun RelayItemCell(
color = MaterialTheme.colorScheme.onSurface,
isExpanded = isExpanded,
onClick = { onToggleExpand(!isExpanded) },
modifier = Modifier.testTag(EXPAND_BUTTON_TEST_TAG),
)
}
}
Expand Down Expand Up @@ -220,6 +225,7 @@ private fun Name(modifier: Modifier = Modifier, relay: RelayItem) {

@Composable
private fun RowScope.ExpandButton(
modifier: Modifier,
color: Color,
isExpanded: Boolean,
onClick: (expand: Boolean) -> Unit,
Expand All @@ -232,7 +238,8 @@ private fun RowScope.ExpandButton(
color = color,
isExpanded = isExpanded,
modifier =
Modifier.fillMaxHeight()
modifier
.fillMaxHeight()
.clickable { onClick(!isExpanded) }
.padding(horizontal = Dimens.largePadding)
.align(Alignment.CenterVertically),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.tooling.preview.Preview
import net.mullvad.mullvadvpn.compose.test.SWITCH_TEST_TAG
import net.mullvad.mullvadvpn.lib.theme.AppTheme
import net.mullvad.mullvadvpn.lib.theme.Dimens
import net.mullvad.mullvadvpn.lib.theme.color.AlphaDisabled
Expand Down Expand Up @@ -55,7 +57,7 @@ fun MullvadSwitch(
Switch(
checked = checked,
onCheckedChange = onCheckedChange,
modifier = modifier,
modifier = modifier.testTag(SWITCH_TEST_TAG),
thumbContent = thumbContent,
enabled = enabled,
colors = colors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import net.mullvad.mullvadvpn.compose.screen.BottomSheetState.ShowLocationBottom
import net.mullvad.mullvadvpn.compose.state.RelayListItem
import net.mullvad.mullvadvpn.compose.state.SelectLocationUiState
import net.mullvad.mullvadvpn.compose.test.CIRCULAR_PROGRESS_INDICATOR
import net.mullvad.mullvadvpn.compose.test.LOCATION_CELL_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.SELECT_LOCATION_CUSTOM_LIST_BOTTOM_SHEET_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.SELECT_LOCATION_CUSTOM_LIST_HEADER_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.SELECT_LOCATION_LOCATION_BOTTOM_SHEET_TEST_TAG
Expand Down Expand Up @@ -427,6 +428,7 @@ fun LazyItemScope.RelayLocationItem(
onToggleExpand = { onExpand(it) },
isExpanded = relayItem.expanded,
depth = relayItem.depth,
modifier = Modifier.testTag(LOCATION_CELL_TEST_TAG),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@ const val LAZY_LIST_WIREGUARD_CUSTOM_PORT_NUMBER_TEST_TAG =
const val CUSTOM_PORT_DIALOG_INPUT_TEST_TAG = "custom_port_dialog_input_test_tag"
const val LAZY_LIST_WIREGUARD_OBFUSCATION_TITLE_TEST_TAG =
"lazy_list_wireguard_obfuscation_title_test_tag"
const val SWITCH_TEST_TAG = "switch_test_tag"

// SelectLocationScreen, ConnectScreen, CustomListLocationsScreen
const val CIRCULAR_PROGRESS_INDICATOR = "circular_progress_indicator"
const val EXPAND_BUTTON_TEST_TAG = "expand_button_test_tag"
const val LOCATION_CELL_TEST_TAG = "location_cell_test_tag"

// ConnectScreen
const val SCROLLABLE_COLUMN_TEST_TAG = "scrollable_column_test_tag"
const val SELECT_LOCATION_BUTTON_TEST_TAG = "select_location_button_test_tag"
const val CONNECT_BUTTON_TEST_TAG = "connect_button_test_tag"
const val RECONNECT_BUTTON_TEST_TAG = "reconnect_button_test_tag"
const val CONNECT_CARD_HEADER_TEST_TAG = "connect_card_header_test_tag"
const val LOCATION_INFO_TEST_TAG = "location_info_test_tag"
const val LOCATION_INFO_CONNECTION_IN_TEST_TAG = "location_info_connection_in_test_tag"
const val LOCATION_INFO_CONNECTION_OUT_TEST_TAG = "location_info_connection_out_test_tag"

// ConnectScreen - Notification banner
Expand Down
14 changes: 14 additions & 0 deletions android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ grpc-protobuf = "4.28.1"
koin = "4.0.0"
koin-compose = "4.0.0"

# Ktor
ktor = "3.0.0-beta-2"

# Kotlin
# Bump kotlin and kotlin-ksp together, find matching release here:
# https://github.com/google/ksp/releases
kotlin = "2.0.20"
kotlin-ksp = "2.0.20-1.0.25"
kotlinx = "1.9.0"
kotlinx-serialization = "2.0.20"

# Protobuf
protobuf = "0.9.4"
Expand Down Expand Up @@ -130,6 +134,13 @@ kotlin-native-prebuilt = { module = "org.jetbrains.kotlin:kotlin-native-prebuilt
kotlinx-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx" }
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinx" }
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }

# Ktor
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }

# MockK
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
Expand Down Expand Up @@ -159,6 +170,9 @@ kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
kotlin-ksp = { id = "com.google.devtools.ksp", version.ref = "kotlin-ksp"}

# Kotlinx
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlinx-serialization" }

# Protobuf
protobuf-core = { id = "com.google.protobuf", version.ref = "protobuf" }
protobuf-protoc = { id = "com.google.protobuf:protoc", version.ref = "grpc-protobuf" }
Expand Down
Loading

0 comments on commit c474f32

Please sign in to comment.