Add tests for compose activity initial state changes (#1972)
This commit is contained in:
parent
af44b25c29
commit
d7e47caef3
|
@ -1028,7 +1028,7 @@ class ComposeActivity : BaseActivity(),
|
||||||
private const val MEDIA_TAKE_PHOTO_RESULT = 2
|
private const val MEDIA_TAKE_PHOTO_RESULT = 2
|
||||||
private const val PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1
|
private const val PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1
|
||||||
|
|
||||||
private const val COMPOSE_OPTIONS_EXTRA = "COMPOSE_OPTIONS"
|
internal const val COMPOSE_OPTIONS_EXTRA = "COMPOSE_OPTIONS"
|
||||||
private const val PHOTO_UPLOAD_URI_KEY = "PHOTO_UPLOAD_URI"
|
private const val PHOTO_UPLOAD_URI_KEY = "PHOTO_UPLOAD_URI"
|
||||||
|
|
||||||
// Mastodon only counts URLs as this long in terms of status character limits
|
// Mastodon only counts URLs as this long in terms of status character limits
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package com.keylesspalace.tusky
|
package com.keylesspalace.tusky
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import android.text.SpannedString
|
import android.text.SpannedString
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
@ -76,6 +77,7 @@ class ComposeActivityTest {
|
||||||
notificationLight = true
|
notificationLight = true
|
||||||
)
|
)
|
||||||
var instanceResponseCallback: (()->Instance)? = null
|
var instanceResponseCallback: (()->Instance)? = null
|
||||||
|
var composeOptions: ComposeActivity.ComposeOptions? = null
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setupActivity() {
|
fun setupActivity() {
|
||||||
|
@ -114,6 +116,9 @@ class ComposeActivityTest {
|
||||||
mock(SaveTootHelper::class.java),
|
mock(SaveTootHelper::class.java),
|
||||||
dbMock
|
dbMock
|
||||||
)
|
)
|
||||||
|
activity.intent = Intent(activity, ComposeActivity::class.java).apply {
|
||||||
|
putExtra(ComposeActivity.COMPOSE_OPTIONS_EXTRA, composeOptions)
|
||||||
|
}
|
||||||
|
|
||||||
val viewModelFactoryMock = mock(ViewModelFactory::class.java)
|
val viewModelFactoryMock = mock(ViewModelFactory::class.java)
|
||||||
`when`(viewModelFactoryMock.create(ComposeViewModel::class.java)).thenReturn(viewModel)
|
`when`(viewModelFactoryMock.create(ComposeViewModel::class.java)).thenReturn(viewModel)
|
||||||
|
@ -138,6 +143,14 @@ class ComposeActivityTest {
|
||||||
// We would like to check for dialog but Robolectric doesn't work with AppCompat v7 yet
|
// We would like to check for dialog but Robolectric doesn't work with AppCompat v7 yet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun whenModifiedInitialState_andCloseButtonPressed_notFinish() {
|
||||||
|
composeOptions = ComposeActivity.ComposeOptions(modifiedInitialState = true)
|
||||||
|
setupActivity()
|
||||||
|
clickUp()
|
||||||
|
assertFalse(activity.isFinishing)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun whenBackButtonPressedAndEmpty_finish() {
|
fun whenBackButtonPressedAndEmpty_finish() {
|
||||||
clickBack()
|
clickBack()
|
||||||
|
@ -152,6 +165,14 @@ class ComposeActivityTest {
|
||||||
// We would like to check for dialog but Robolectric doesn't work with AppCompat v7 yet
|
// We would like to check for dialog but Robolectric doesn't work with AppCompat v7 yet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun whenModifiedInitialState_andBackButtonPressed_notFinish() {
|
||||||
|
composeOptions = ComposeActivity.ComposeOptions(modifiedInitialState = true)
|
||||||
|
setupActivity()
|
||||||
|
clickBack()
|
||||||
|
assertFalse(activity.isFinishing)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun whenMaximumTootCharsIsNull_defaultLimitIsUsed() {
|
fun whenMaximumTootCharsIsNull_defaultLimitIsUsed() {
|
||||||
instanceResponseCallback = { getInstanceWithMaximumTootCharacters(null) }
|
instanceResponseCallback = { getInstanceWithMaximumTootCharacters(null) }
|
||||||
|
|
Loading…
Reference in New Issue