Add tests for compose activity initial state changes (#1972)

This commit is contained in:
Levi Bard 2020-10-28 18:43:11 +01:00 committed by GitHub
parent af44b25c29
commit d7e47caef3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -1028,7 +1028,7 @@ class ComposeActivity : BaseActivity(),
private const val MEDIA_TAKE_PHOTO_RESULT = 2
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"
// Mastodon only counts URLs as this long in terms of status character limits

View File

@ -16,6 +16,7 @@
package com.keylesspalace.tusky
import android.content.Intent
import android.text.SpannedString
import android.widget.EditText
import androidx.test.ext.junit.runners.AndroidJUnit4
@ -76,6 +77,7 @@ class ComposeActivityTest {
notificationLight = true
)
var instanceResponseCallback: (()->Instance)? = null
var composeOptions: ComposeActivity.ComposeOptions? = null
@Before
fun setupActivity() {
@ -114,6 +116,9 @@ class ComposeActivityTest {
mock(SaveTootHelper::class.java),
dbMock
)
activity.intent = Intent(activity, ComposeActivity::class.java).apply {
putExtra(ComposeActivity.COMPOSE_OPTIONS_EXTRA, composeOptions)
}
val viewModelFactoryMock = mock(ViewModelFactory::class.java)
`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
}
@Test
fun whenModifiedInitialState_andCloseButtonPressed_notFinish() {
composeOptions = ComposeActivity.ComposeOptions(modifiedInitialState = true)
setupActivity()
clickUp()
assertFalse(activity.isFinishing)
}
@Test
fun whenBackButtonPressedAndEmpty_finish() {
clickBack()
@ -152,6 +165,14 @@ class ComposeActivityTest {
// 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
fun whenMaximumTootCharsIsNull_defaultLimitIsUsed() {
instanceResponseCallback = { getInstanceWithMaximumTootCharacters(null) }