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

Remove incorrect default arguments #7314

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
@@ -1,12 +1,12 @@
package net.mullvad.mullvadvpn.compose.screen
package net.mullvad.mullvadvpn.compose.dialog

import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import de.mannodermaus.junit5.compose.ComposeContext
import io.mockk.MockKAnnotations
import io.mockk.impl.annotations.MockK
import net.mullvad.mullvadvpn.compose.createEdgeToEdgeComposeExtension
import net.mullvad.mullvadvpn.compose.dialog.ChangelogDialog
import net.mullvad.mullvadvpn.compose.setContentWithTheme
import net.mullvad.mullvadvpn.viewmodel.AppInfoViewModel
import net.mullvad.mullvadvpn.viewmodel.ChangelogUiState
Expand All @@ -25,16 +25,19 @@ class ChangelogDialogTest {
MockKAnnotations.init(this)
}

private fun ComposeContext.initDialog(state: ChangelogUiState, onDismiss: () -> Unit = {}) {
setContentWithTheme { ChangelogDialog(state = state, onDismiss = onDismiss) }
}

@Test
fun testShowChangeLogWhenNeeded() =
composeExtension.use {
// Arrange
setContentWithTheme {
ChangelogDialog(
initDialog(
state =
ChangelogUiState(changes = listOf(CHANGELOG_ITEM), version = CHANGELOG_VERSION),
onDismiss = {},
)
}
onDismiss = {},
)

// Check changelog content showed within dialog
onNodeWithText(CHANGELOG_ITEM).assertExists()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextInput
import de.mannodermaus.junit5.compose.ComposeContext
import io.mockk.MockKAnnotations
import io.mockk.mockk
import io.mockk.verify
Expand All @@ -30,12 +31,28 @@ class CreateCustomListDialogTest {
MockKAnnotations.init(this)
}

private fun ComposeContext.initDialog(
state: CreateCustomListUiState = CreateCustomListUiState(),
createCustomList: (String) -> Unit = {},
onInputChanged: () -> Unit = {},
onDismiss: () -> Unit = {},
) {
setContentWithTheme {
CreateCustomListDialog(
state = state,
createCustomList = createCustomList,
onInputChanged = onInputChanged,
onDismiss = onDismiss,
)
}
}

@Test
fun givenNoErrorShouldShowNoErrorMessage() =
composeExtension.use {
// Arrange
val state = CreateCustomListUiState(error = null)
setContentWithTheme { CreateCustomListDialog(state = state) }
initDialog(state)

// Assert
onNodeWithText(NAME_EXIST_ERROR_TEXT).assertDoesNotExist()
Expand All @@ -50,7 +67,7 @@ class CreateCustomListDialogTest {
CreateCustomListUiState(
error = CreateWithLocationsError.Create(CustomListAlreadyExists)
)
setContentWithTheme { CreateCustomListDialog(state = state) }
initDialog(state)

// Assert
onNodeWithText(NAME_EXIST_ERROR_TEXT).assertExists()
Expand All @@ -65,7 +82,7 @@ class CreateCustomListDialogTest {
CreateCustomListUiState(
error = CreateWithLocationsError.Create(UnknownCustomListError(Throwable()))
)
setContentWithTheme { CreateCustomListDialog(state = state) }
initDialog(state)

// Assert
onNodeWithText(NAME_EXIST_ERROR_TEXT).assertDoesNotExist()
Expand All @@ -78,9 +95,7 @@ class CreateCustomListDialogTest {
// Arrange
val mockedOnDismiss: () -> Unit = mockk(relaxed = true)
val state = CreateCustomListUiState()
setContentWithTheme {
CreateCustomListDialog(state = state, onDismiss = mockedOnDismiss)
}
initDialog(state, onDismiss = mockedOnDismiss)

// Act
onNodeWithText(CANCEL_BUTTON_TEXT).performClick()
Expand All @@ -95,9 +110,7 @@ class CreateCustomListDialogTest {
// Arrange
val mockedCreateCustomList: (String) -> Unit = mockk(relaxed = true)
val state = CreateCustomListUiState()
setContentWithTheme {
CreateCustomListDialog(state = state, createCustomList = mockedCreateCustomList)
}
initDialog(state, createCustomList = mockedCreateCustomList)

// Act
onNodeWithText(CREATE_BUTTON_TEXT).performClick()
Expand All @@ -113,9 +126,7 @@ class CreateCustomListDialogTest {
val mockedCreateCustomList: (String) -> Unit = mockk(relaxed = true)
val inputText = "NEW LIST"
val state = CreateCustomListUiState()
setContentWithTheme {
CreateCustomListDialog(state = state, createCustomList = mockedCreateCustomList)
}
initDialog(state, createCustomList = mockedCreateCustomList)

// Act
onNodeWithTag(CREATE_CUSTOM_LIST_DIALOG_INPUT_TEST_TAG).performTextInput(inputText)
Expand All @@ -132,9 +143,7 @@ class CreateCustomListDialogTest {
val mockedOnInputChanged: () -> Unit = mockk(relaxed = true)
val inputText = "NEW LIST"
val state = CreateCustomListUiState()
setContentWithTheme {
CreateCustomListDialog(state = state, onInputChanged = mockedOnInputChanged)
}
initDialog(state, onInputChanged = mockedOnInputChanged)

// Act
onNodeWithTag(CREATE_CUSTOM_LIST_DIALOG_INPUT_TEST_TAG).performTextInput(inputText)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package net.mullvad.mullvadvpn.compose.dialog

import android.annotation.SuppressLint
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand All @@ -13,6 +11,7 @@ import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextInput
import de.mannodermaus.junit5.compose.ComposeContext
import io.mockk.MockKAnnotations
import io.mockk.mockk
import io.mockk.verify
Expand All @@ -36,30 +35,30 @@ class CustomPortDialogTest {
MockKAnnotations.init(this)
}

@SuppressLint("ComposableNaming")
@Composable
private fun testWireguardCustomPortDialog(
private fun ComposeContext.initDialog(
title: String = "",
portInput: String = "",
isValidInput: Boolean = false,
showResetToDefault: Boolean = false,
allowedPortRanges: List<PortRange> = emptyList(),
showResetToDefault: Boolean = false,
onInputChanged: (String) -> Unit = { _ -> },
onSavePort: (String) -> Unit = { _ -> },
onResetPort: () -> Unit = {},
onDismiss: () -> Unit = {},
) {
CustomPortDialog(
title = title,
portInput = portInput,
isValidInput = isValidInput,
showResetToDefault = showResetToDefault,
allowedPortRanges = allowedPortRanges,
onInputChanged = onInputChanged,
onSavePort = onSavePort,
onDismiss = onDismiss,
onResetPort = onResetPort,
)
setContentWithTheme {
CustomPortDialog(
title = title,
portInput = portInput,
isValidInput = isValidInput,
allowedPortRanges = allowedPortRanges,
showResetToDefault = showResetToDefault,
onInputChanged = onInputChanged,
onSavePort = onSavePort,
onDismiss = onDismiss,
onResetPort = onResetPort,
)
}
}

@Test
Expand All @@ -71,7 +70,17 @@ class CustomPortDialogTest {
// Arrange
setContentWithTheme {
var input by remember { mutableStateOf("") }
testWireguardCustomPortDialog(portInput = input, onInputChanged = { input = it })
CustomPortDialog(
title = "",
portInput = input,
isValidInput = false,
allowedPortRanges = emptyList(),
showResetToDefault = false,
onInputChanged = { input = it },
onSavePort = {},
onDismiss = {},
onResetPort = {},
)
}

// Act
Expand All @@ -86,7 +95,7 @@ class CustomPortDialogTest {
fun testEmptyInputResultsInSetPortButtonBeingDisabled() =
composeExtension.use {
// Arrange
setContentWithTheme { testWireguardCustomPortDialog(isValidInput = false) }
initDialog(isValidInput = false)

// Assert
onNodeWithText("Set port").assertIsNotEnabled()
Expand All @@ -96,9 +105,7 @@ class CustomPortDialogTest {
fun testValidInputResultsInSetPortButtonBeingEnabled() =
composeExtension.use {
// Arrange
setContentWithTheme {
testWireguardCustomPortDialog(portInput = VALID_CUSTOM_PORT, isValidInput = true)
}
initDialog(portInput = VALID_CUSTOM_PORT, isValidInput = true)

// Assert
onNodeWithText("Set port").assertIsEnabled()
Expand All @@ -109,9 +116,7 @@ class CustomPortDialogTest {
fun testInvalidInputResultsInSetPortButtonBeingDisabled() =
composeExtension.use {
// Arrange
setContentWithTheme {
testWireguardCustomPortDialog(portInput = INVALID_CUSTOM_PORT, isValidInput = false)
}
initDialog(portInput = INVALID_CUSTOM_PORT, isValidInput = false)

// Assert
onNodeWithText("Set port").assertIsNotEnabled()
Expand All @@ -122,13 +127,11 @@ class CustomPortDialogTest {
composeExtension.use {
// Arrange
val mockedSubmitHandler: (String) -> Unit = mockk(relaxed = true)
setContentWithTheme {
testWireguardCustomPortDialog(
portInput = VALID_CUSTOM_PORT,
isValidInput = true,
onSavePort = mockedSubmitHandler,
)
}
initDialog(
portInput = VALID_CUSTOM_PORT,
isValidInput = true,
onSavePort = mockedSubmitHandler,
)

// Act
onNodeWithText("Set port").assertIsEnabled().performClick()
Expand All @@ -142,14 +145,12 @@ class CustomPortDialogTest {
composeExtension.use {
// Arrange
val mockedClickHandler: () -> Unit = mockk(relaxed = true)
setContentWithTheme {
testWireguardCustomPortDialog(
portInput = VALID_CUSTOM_PORT,
isValidInput = true,
showResetToDefault = true,
onResetPort = mockedClickHandler,
)
}
initDialog(
portInput = VALID_CUSTOM_PORT,
isValidInput = true,
showResetToDefault = true,
onResetPort = mockedClickHandler,
)

// Act
onNodeWithText("Remove custom port").performClick()
Expand All @@ -163,7 +164,7 @@ class CustomPortDialogTest {
composeExtension.use {
// Arrange
val mockedClickHandler: () -> Unit = mockk(relaxed = true)
setContentWithTheme { testWireguardCustomPortDialog(onDismiss = mockedClickHandler) }
initDialog(onDismiss = mockedClickHandler)

// Assert
onNodeWithText("Cancel").performClick()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.compose.dialog
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import de.mannodermaus.junit5.compose.ComposeContext
import io.mockk.MockKAnnotations
import io.mockk.mockk
import io.mockk.verify
Expand All @@ -25,16 +26,23 @@ class DeleteCustomListConfirmationDialogTest {
MockKAnnotations.init(this)
}

private fun ComposeContext.initDialog(
state: DeleteCustomListUiState =
DeleteCustomListUiState(CustomListName.fromString("My Custom List"), null),
onDelete: () -> Unit = {},
onBack: () -> Unit = {},
) {
setContentWithTheme {
DeleteCustomListConfirmationDialog(state = state, onDelete = onDelete, onBack = onBack)
}
}

@Test
fun givenNameShouldShowDeleteNameTitle() =
composeExtension.use {
// Arrange
val name = CustomListName.fromString("List should be deleted")
setContentWithTheme {
DeleteCustomListConfirmationDialog(
state = DeleteCustomListUiState(name = name, deleteError = null)
)
}
initDialog(state = DeleteCustomListUiState(name = name, deleteError = null))

// Assert
onNodeWithText(DELETE_TITLE.format(name)).assertExists()
Expand All @@ -46,12 +54,10 @@ class DeleteCustomListConfirmationDialogTest {
// Arrange
val name = CustomListName.fromString("List should be deleted")
val mockedOnDelete: () -> Unit = mockk(relaxed = true)
setContentWithTheme {
DeleteCustomListConfirmationDialog(
state = DeleteCustomListUiState(name = name, deleteError = null),
onDelete = mockedOnDelete,
)
}
initDialog(
state = DeleteCustomListUiState(name = name, deleteError = null),
onDelete = mockedOnDelete,
)

// Act
onNodeWithText(DELETE_BUTTON_TEXT).performClick()
Expand All @@ -66,12 +72,10 @@ class DeleteCustomListConfirmationDialogTest {
// Arrange
val name = CustomListName.fromString("List should be deleted")
val mockedOnBack: () -> Unit = mockk(relaxed = true)
setContentWithTheme {
DeleteCustomListConfirmationDialog(
state = DeleteCustomListUiState(name = name, deleteError = null),
onBack = mockedOnBack,
)
}
initDialog(
state = DeleteCustomListUiState(name = name, deleteError = null),
onBack = mockedOnBack,
)

// Act
onNodeWithText(CANCEL_BUTTON_TEXT).performClick()
Expand Down
Loading
Loading