-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
92 changed files
with
4,367 additions
and
1,997 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...oidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/location/SearchLocationScreenTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package net.mullvad.mullvadvpn.compose.screen.location | ||
|
||
import androidx.compose.ui.test.ExperimentalTestApi | ||
import androidx.compose.ui.test.onNodeWithTag | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.performTextInput | ||
import io.mockk.MockKAnnotations | ||
import io.mockk.mockk | ||
import io.mockk.unmockkAll | ||
import io.mockk.verify | ||
import net.mullvad.mullvadvpn.compose.createEdgeToEdgeComposeExtension | ||
import net.mullvad.mullvadvpn.compose.data.DUMMY_RELAY_ITEM_CUSTOM_LISTS | ||
import net.mullvad.mullvadvpn.compose.setContentWithTheme | ||
import net.mullvad.mullvadvpn.compose.state.RelayListItem | ||
import net.mullvad.mullvadvpn.compose.state.SearchLocationUiState | ||
import net.mullvad.mullvadvpn.compose.test.SELECT_LOCATION_CUSTOM_LIST_HEADER_TEST_TAG | ||
import org.junit.jupiter.api.AfterEach | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.RegisterExtension | ||
|
||
@OptIn(ExperimentalTestApi::class) | ||
class SearchLocationScreenTest { | ||
@JvmField @RegisterExtension val composeExtension = createEdgeToEdgeComposeExtension() | ||
|
||
@BeforeEach | ||
fun setup() { | ||
MockKAnnotations.init(this) | ||
} | ||
|
||
@AfterEach | ||
fun teardown() { | ||
unmockkAll() | ||
} | ||
|
||
@Test | ||
fun testSearchInput() = | ||
composeExtension.use { | ||
// Arrange | ||
val mockedSearchTermInput: (String) -> Unit = mockk(relaxed = true) | ||
setContentWithTheme { | ||
SearchLocationScreen( | ||
state = | ||
SearchLocationUiState.NoQuery(searchTerm = "", filterChips = emptyList()), | ||
onSearchInputChanged = mockedSearchTermInput, | ||
) | ||
} | ||
val mockSearchString = "SEARCH" | ||
|
||
// Act | ||
onNodeWithText("Search for...").performTextInput(mockSearchString) | ||
|
||
// Assert | ||
verify { mockedSearchTermInput.invoke(mockSearchString) } | ||
} | ||
|
||
@Test | ||
fun testSearchTermNotFound() = | ||
composeExtension.use { | ||
// Arrange | ||
val mockSearchString = "SEARCH" | ||
setContentWithTheme { | ||
SearchLocationScreen( | ||
state = | ||
SearchLocationUiState.Content( | ||
searchTerm = mockSearchString, | ||
filterChips = emptyList(), | ||
relayListItems = | ||
listOf(RelayListItem.LocationsEmptyText(mockSearchString)), | ||
customLists = emptyList(), | ||
) | ||
) | ||
} | ||
|
||
// Assert | ||
onNodeWithText("No result for \"$mockSearchString\", please try a different search") | ||
.assertExists() | ||
} | ||
|
||
@Test | ||
fun givenNoCustomListsAndSearchIsActiveShouldNotShowCustomListHeader() = | ||
composeExtension.use { | ||
// Arrange | ||
val mockSearchString = "SEARCH" | ||
setContentWithTheme { | ||
SearchLocationScreen( | ||
state = | ||
SearchLocationUiState.Content( | ||
searchTerm = mockSearchString, | ||
filterChips = emptyList(), | ||
relayListItems = emptyList(), | ||
customLists = DUMMY_RELAY_ITEM_CUSTOM_LISTS, | ||
) | ||
) | ||
} | ||
|
||
// Assert | ||
onNodeWithText(CUSTOM_LISTS_EMPTY_TEXT).assertDoesNotExist() | ||
onNodeWithTag(SELECT_LOCATION_CUSTOM_LIST_HEADER_TEST_TAG).assertDoesNotExist() | ||
} | ||
|
||
companion object { | ||
private const val CUSTOM_LISTS_EMPTY_TEXT = "To create a custom list press the \"︙\"" | ||
} | ||
} |
Oops, something went wrong.