2023-10-19 08:18:56 +02:00
|
|
|
package network.loki.messenger
|
|
|
|
|
|
|
|
import androidx.compose.ui.test.hasContentDescriptionExactly
|
|
|
|
import androidx.compose.ui.test.junit4.createComposeRule
|
|
|
|
import androidx.compose.ui.test.performClick
|
|
|
|
import androidx.compose.ui.test.performTextInput
|
|
|
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
|
|
import androidx.test.filters.SmallTest
|
|
|
|
import androidx.test.platform.app.InstrumentationRegistry
|
|
|
|
import org.hamcrest.CoreMatchers.*
|
|
|
|
import org.hamcrest.MatcherAssert.*
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.runner.RunWith
|
|
|
|
import org.thoughtcrime.securesms.ApplicationContext
|
2023-10-30 07:45:15 +01:00
|
|
|
import org.thoughtcrime.securesms.groups.compose.CreateGroup
|
|
|
|
import org.thoughtcrime.securesms.groups.compose.ViewState
|
2023-10-19 08:18:56 +02:00
|
|
|
import org.thoughtcrime.securesms.ui.AppTheme
|
|
|
|
|
|
|
|
@RunWith(AndroidJUnit4::class)
|
|
|
|
@SmallTest
|
|
|
|
class CreateGroupTests {
|
|
|
|
|
|
|
|
@get:Rule
|
|
|
|
val composeTest = createComposeRule()
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun testNavigateToCreateGroup() {
|
|
|
|
val application = InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as ApplicationContext
|
|
|
|
// Accessibility IDs
|
|
|
|
val nameDesc = application.getString(R.string.AccessibilityId_closed_group_edit_group_name)
|
|
|
|
val buttonDesc = application.getString(R.string.AccessibilityId_create_closed_group_create_button)
|
|
|
|
|
|
|
|
var backPressed = false
|
|
|
|
var closePressed = false
|
|
|
|
|
|
|
|
composeTest.setContent {
|
|
|
|
AppTheme {
|
|
|
|
CreateGroup(
|
2023-10-30 07:45:15 +01:00
|
|
|
viewState = ViewState.DEFAULT,
|
2023-10-19 08:18:56 +02:00
|
|
|
onBack = { backPressed = true },
|
2023-11-13 02:05:37 +01:00
|
|
|
onClose = { closePressed = true },
|
|
|
|
onSelectContact = {},
|
|
|
|
updateState = {}
|
|
|
|
)
|
2023-10-19 08:18:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
with(composeTest) {
|
|
|
|
onNode(hasContentDescriptionExactly(nameDesc)).performTextInput("Name")
|
|
|
|
onNode(hasContentDescriptionExactly(buttonDesc)).performClick()
|
|
|
|
}
|
|
|
|
|
|
|
|
assertThat(backPressed, equalTo(false))
|
|
|
|
assertThat(closePressed, equalTo(false))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-10-19 08:24:08 +02:00
|
|
|
@Test
|
|
|
|
fun testFailToCreate() {
|
2023-10-20 00:37:15 +02:00
|
|
|
val application = InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as ApplicationContext
|
|
|
|
// Accessibility IDs
|
|
|
|
val nameDesc = application.getString(R.string.AccessibilityId_closed_group_edit_group_name)
|
|
|
|
val buttonDesc = application.getString(R.string.AccessibilityId_create_closed_group_create_button)
|
2023-10-19 08:24:08 +02:00
|
|
|
|
2023-10-20 00:37:15 +02:00
|
|
|
var backPressed = false
|
|
|
|
var closePressed = false
|
|
|
|
|
|
|
|
composeTest.setContent {
|
|
|
|
AppTheme {
|
|
|
|
CreateGroup(
|
2023-10-30 07:45:15 +01:00
|
|
|
viewState = ViewState.DEFAULT,
|
2023-10-20 00:37:15 +02:00
|
|
|
onBack = { backPressed = true },
|
2023-11-13 02:05:37 +01:00
|
|
|
onClose = { closePressed = true },
|
|
|
|
updateState = {},
|
|
|
|
onSelectContact = {}
|
|
|
|
)
|
2023-10-20 00:37:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
with(composeTest) {
|
|
|
|
onNode(hasContentDescriptionExactly(nameDesc)).performTextInput("")
|
|
|
|
onNode(hasContentDescriptionExactly(buttonDesc)).performClick()
|
|
|
|
}
|
|
|
|
|
|
|
|
assertThat(backPressed, equalTo(false))
|
|
|
|
assertThat(closePressed, equalTo(false))
|
2023-10-19 08:24:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun testBackButton() {
|
2023-10-20 00:37:15 +02:00
|
|
|
val application = InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as ApplicationContext
|
|
|
|
// Accessibility IDs
|
|
|
|
val backDesc = application.getString(R.string.new_conversation_dialog_back_button_content_description)
|
|
|
|
|
|
|
|
var backPressed = false
|
2023-10-19 08:24:08 +02:00
|
|
|
|
2023-10-20 00:37:15 +02:00
|
|
|
composeTest.setContent {
|
|
|
|
AppTheme {
|
|
|
|
CreateGroup(
|
2023-10-30 07:45:15 +01:00
|
|
|
viewState = ViewState.DEFAULT,
|
2023-10-20 00:37:15 +02:00
|
|
|
onBack = { backPressed = true },
|
2023-11-13 02:05:37 +01:00
|
|
|
onClose = {},
|
|
|
|
onSelectContact = {},
|
|
|
|
updateState = {}
|
|
|
|
)
|
2023-10-20 00:37:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
with (composeTest) {
|
|
|
|
onNode(hasContentDescriptionExactly(backDesc)).performClick()
|
|
|
|
}
|
|
|
|
|
|
|
|
assertThat(backPressed, equalTo(true))
|
2023-10-19 08:24:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun testCloseButton() {
|
2023-10-20 00:37:15 +02:00
|
|
|
val application = InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as ApplicationContext
|
|
|
|
// Accessibility IDs
|
|
|
|
val closeDesc = application.getString(R.string.new_conversation_dialog_close_button_content_description)
|
|
|
|
var closePressed = false
|
|
|
|
|
|
|
|
composeTest.setContent {
|
|
|
|
AppTheme {
|
|
|
|
CreateGroup(
|
2023-10-30 07:45:15 +01:00
|
|
|
viewState = ViewState.DEFAULT,
|
|
|
|
onBack = { },
|
2023-11-13 02:05:37 +01:00
|
|
|
onClose = { closePressed = true },
|
|
|
|
onSelectContact = {},
|
|
|
|
updateState = {}
|
|
|
|
)
|
2023-10-20 00:37:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
with (composeTest) {
|
|
|
|
onNode(hasContentDescriptionExactly(closeDesc)).performClick()
|
|
|
|
}
|
2023-10-19 08:24:08 +02:00
|
|
|
|
2023-10-20 00:37:15 +02:00
|
|
|
assertThat(closePressed, equalTo(true))
|
2023-10-19 08:24:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-19 08:18:56 +02:00
|
|
|
}
|