Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename tests to new format #5838

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ class RedeemVoucherDialogTest {
val mockedClickHandler: (Boolean) -> Unit = mockk(relaxed = true)
setContentWithTheme {
RedeemVoucherDialog(
uiState =
VoucherDialogUiState(voucherViewModelState = VoucherDialogState.Success(0)),
uiState = VoucherDialogUiState(voucherState = VoucherDialogState.Success(0)),
onVoucherInputChange = {},
onRedeem = {},
onDismiss = mockedClickHandler
Expand Down Expand Up @@ -98,8 +97,7 @@ class RedeemVoucherDialogTest {
// Arrange
setContentWithTheme {
RedeemVoucherDialog(
uiState =
VoucherDialogUiState(voucherViewModelState = VoucherDialogState.Verifying),
uiState = VoucherDialogUiState(voucherState = VoucherDialogState.Verifying),
onVoucherInputChange = {},
onRedeem = {},
onDismiss = {}
Expand All @@ -116,8 +114,7 @@ class RedeemVoucherDialogTest {
// Arrange
setContentWithTheme {
RedeemVoucherDialog(
uiState =
VoucherDialogUiState(voucherViewModelState = VoucherDialogState.Success(0)),
uiState = VoucherDialogUiState(voucherState = VoucherDialogState.Success(0)),
onVoucherInputChange = {},
onRedeem = {},
onDismiss = {}
Expand All @@ -136,7 +133,7 @@ class RedeemVoucherDialogTest {
RedeemVoucherDialog(
uiState =
VoucherDialogUiState(
voucherViewModelState = VoucherDialogState.Error(ERROR_MESSAGE)
voucherState = VoucherDialogState.Error(ERROR_MESSAGE)
),
onVoucherInputChange = {},
onRedeem = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ fun RedeemVoucherDialog(
) {
AlertDialog(
title = {
if (uiState.voucherViewModelState !is VoucherDialogState.Success)
if (uiState.voucherState !is VoucherDialogState.Success)
Text(
text = stringResource(id = R.string.enter_voucher_code),
)
},
confirmButton = {
Column {
if (uiState.voucherViewModelState !is VoucherDialogState.Success) {
if (uiState.voucherState !is VoucherDialogState.Success) {
VariantButton(
text = stringResource(id = R.string.redeem),
onClick = { onRedeem(uiState.voucherInput) },
Expand All @@ -138,13 +138,11 @@ fun RedeemVoucherDialog(
text =
stringResource(
id =
if (uiState.voucherViewModelState is VoucherDialogState.Success)
if (uiState.voucherState is VoucherDialogState.Success)
R.string.got_it
else R.string.cancel
),
onClick = {
onDismiss(uiState.voucherViewModelState is VoucherDialogState.Success)
}
onClick = { onDismiss(uiState.voucherState is VoucherDialogState.Success) }
)
}
},
Expand All @@ -153,11 +151,9 @@ fun RedeemVoucherDialog(
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally
) {
if (uiState.voucherViewModelState is VoucherDialogState.Success) {
if (uiState.voucherState is VoucherDialogState.Success) {
val days: Int =
(uiState.voucherViewModelState.addedTime /
DateTimeConstants.SECONDS_PER_DAY)
.toInt()
(uiState.voucherState.addedTime / DateTimeConstants.SECONDS_PER_DAY).toInt()
val message =
stringResource(
R.string.added_to_your_account,
Expand Down Expand Up @@ -190,9 +186,7 @@ fun RedeemVoucherDialog(
},
containerColor = MaterialTheme.colorScheme.background,
titleContentColor = MaterialTheme.colorScheme.onBackground,
onDismissRequest = {
onDismiss(uiState.voucherViewModelState is VoucherDialogState.Success)
},
onDismissRequest = { onDismiss(uiState.voucherState is VoucherDialogState.Success) },
properties =
DialogProperties(
securePolicy =
Expand Down Expand Up @@ -257,17 +251,17 @@ private fun EnterVoucherBody(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.height(Dimens.listIconSize).fillMaxWidth()
) {
if (uiState.voucherViewModelState is VoucherDialogState.Verifying) {
if (uiState.voucherState is VoucherDialogState.Verifying) {
MullvadCircularProgressIndicatorSmall()
Text(
text = stringResource(id = R.string.verifying_voucher),
modifier = Modifier.padding(start = Dimens.smallPadding),
color = MaterialTheme.colorScheme.onPrimary,
style = MaterialTheme.typography.bodySmall
)
} else if (uiState.voucherViewModelState is VoucherDialogState.Error) {
} else if (uiState.voucherState is VoucherDialogState.Error) {
Text(
text = uiState.voucherViewModelState.errorMessage,
text = uiState.voucherState.errorMessage,
color = MaterialTheme.colorScheme.error,
style = MaterialTheme.typography.bodySmall
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package net.mullvad.mullvadvpn.compose.state

data class VoucherDialogUiState(
val voucherInput: String = "",
val voucherViewModelState: VoucherDialogState = VoucherDialogState.Default
val voucherState: VoucherDialogState = VoucherDialogState.Default
) {
companion object {
val INITIAL = VoucherDialogUiState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fun PaymentAvailability.toPaymentState(): PaymentState =
is PaymentAvailability.Error.Other -> PaymentState.Error.Generic
is PaymentAvailability.ProductsAvailable -> PaymentState.PaymentAvailable(products)
PaymentAvailability.ProductsUnavailable -> PaymentState.NoPayment
PaymentAvailability.NoProductsFounds -> PaymentState.NoProductsFounds
PaymentAvailability.NoProductsFound -> PaymentState.NoProductsFounds
PaymentAvailability.Loading -> PaymentState.Loading
// Unrecoverable error states
PaymentAvailability.Error.DeveloperError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class VoucherDialogViewModel(
_shared
.flatMapLatest {
combine(vmState, voucherInput) { state, input ->
VoucherDialogUiState(voucherInput = input, voucherViewModelState = state)
VoucherDialogUiState(voucherInput = input, voucherState = state)
}
}
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), VoucherDialogUiState.INITIAL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ApplicationsProviderTest {
}

@Test
fun test_get_apps() {
fun `fetch all apps should work`() {
val launchWithInternetPackageName = "launch_with_internet_package_name"
val launchWithoutInternetPackageName = "launch_without_internet_package_name"
val nonLaunchWithInternetPackageName = "non_launch_with_internet_package_name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,48 @@ class RelayNameComparatorTest {
}

@Test
fun test_compare_respect_numbers_in_name() {
fun `given two relays with same prefix but different numbers comparator should return lowest number first`() {
val relay9 =
RelayItem.Relay(
name = "se9-wireguard",
location = mockk(),
locationName = "mock",
active = false
active = false,
)
val relay10 =
RelayItem.Relay(
name = "se10-wireguard",
location = mockk(),
locationName = "mock",
active = false
active = false,
)

relay9 assertOrderBothDirection relay10
}

@Test
fun test_compare_same_name() {
fun `given two relays with same name with number in name comparator should return 0`() {
val relay9a =
RelayItem.Relay(
name = "se9-wireguard",
location = mockk(),
locationName = "mock",
active = false
active = false,
)
val relay9b =
RelayItem.Relay(
name = "se9-wireguard",
location = mockk(),
locationName = "mock",
active = false
active = false,
)

assertTrue(RelayNameComparator.compare(relay9a, relay9b) == 0)
assertTrue(RelayNameComparator.compare(relay9b, relay9a) == 0)
}

@Test
fun test_compare_only_numbers_in_name() {
fun `comparator should be able to handle name of only numbers`() {
val relay001 =
RelayItem.Relay(name = "001", location = mockk(), locationName = "mock", active = false)
val relay1 =
Expand All @@ -72,75 +72,75 @@ class RelayNameComparatorTest {
}

@Test
fun test_compare_without_numbers_in_name() {
fun `given two relays with same name and without number comparator should return 0`() {
val relay9a =
RelayItem.Relay(
name = "se-wireguard",
location = mockk(),
locationName = "mock",
active = false
active = false,
)
val relay9b =
RelayItem.Relay(
name = "se-wireguard",
location = mockk(),
locationName = "mock",
active = false
active = false,
)

assertTrue(RelayNameComparator.compare(relay9a, relay9b) == 0)
assertTrue(RelayNameComparator.compare(relay9b, relay9a) == 0)
}

@Test
fun test_compare_with_trailing_zeros_in_name() {
fun `given two relays with leading zeroes comparator should return lowest number first`() {
val relay001 =
RelayItem.Relay(
name = "se001-wireguard",
location = mockk(),
locationName = "mock",
active = false
active = false,
)
val relay005 =
RelayItem.Relay(
name = "se005-wireguard",
location = mockk(),
locationName = "mock",
active = false
active = false,
)

relay001 assertOrderBothDirection relay005
}

@Test
fun test_compare_prefix_and_numbers() {
fun `given 4 relays comparator should sort by prefix then number`() {
val relayAr2 =
RelayItem.Relay(
name = "ar2-wireguard",
location = mockk(),
locationName = "mock",
active = false
active = false,
)
val relayAr8 =
RelayItem.Relay(
name = "ar8-wireguard",
location = mockk(),
locationName = "mock",
active = false
active = false,
)
val relaySe5 =
RelayItem.Relay(
name = "se5-wireguard",
location = mockk(),
locationName = "mock",
active = false
active = false,
)
val relaySe10 =
RelayItem.Relay(
name = "se10-wireguard",
location = mockk(),
locationName = "mock",
active = false
active = false,
)

relayAr2 assertOrderBothDirection relayAr8
Expand All @@ -149,7 +149,7 @@ class RelayNameComparatorTest {
}

@Test
fun test_compare_suffix_and_numbers() {
fun `given two relays with same prefix and number comparator should sort by suffix`() {
val relay2c =
RelayItem.Relay(
name = "se2-cloud",
Expand All @@ -162,14 +162,14 @@ class RelayNameComparatorTest {
name = "se2-wireguard",
location = mockk(),
locationName = "mock",
active = false
active = false,
)

relay2c assertOrderBothDirection relay2w
}

@Test
fun test_compare_different_length() {
fun `given two relays with same prefix, but one with no suffix, the one with no suffix should come first`() {
val relay22a =
RelayItem.Relay(
name = "se22",
Expand All @@ -182,7 +182,7 @@ class RelayNameComparatorTest {
name = "se22-wireguard",
location = mockk(),
locationName = "mock",
active = false
active = false,
)

relay22a assertOrderBothDirection relay22b
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ConnectionProxyTest {
}

@Test
fun test_initialize_connection_proxy() {
fun `initialize connection proxy should work`() {
// Arrange
val eventType = slot<KClass<Event.TunnelStateChange>>()
every { mockedDispatchingHandler.registerHandler(capture(eventType), any()) } just Runs
Expand All @@ -60,7 +60,7 @@ class ConnectionProxyTest {
}

@Test
fun test_tunnel_normal_connect_disconnect() {
fun `normal connect and disconnect should not crash`() {
// Arrange
every { connection.send(any()) } just Runs
every { mockedDispatchingHandler.registerHandler(any<KClass<Event>>(), any()) } just Runs
Expand All @@ -71,7 +71,7 @@ class ConnectionProxyTest {
}

@Test
fun test_tunnel_handle_crash_on_connect() {
fun `connect should catch DeadObjectException`() {
// Arrange
every { connection.send(any()) } throws DeadObjectException()
every { mockedDispatchingHandler.registerHandler(any<KClass<Event>>(), any()) } just Runs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ServiceConnectionDeviceDataSourceTest {
}

@Test
fun test_get_devices_list() {
fun `get device should work`() {
// Arrange
every { connection.send(any()) } just Runs
every { mockedDispatchingHandler.registerHandler(any<KClass<Event>>(), any()) } just Runs
Expand All @@ -58,7 +58,7 @@ class ServiceConnectionDeviceDataSourceTest {
}

@Test
fun test_catch_exception_on_devices_list() {
fun `get device should catch DeadObjectException`() {
// Arrange
every { connection.send(any()) } throws DeadObjectException()
every { mockedDispatchingHandler.registerHandler(any<KClass<Event>>(), any()) } just Runs
Expand Down
Loading
Loading