2018-03-28 04:47:00 +11:00
|
|
|
/* Copyright 2018 charlag
|
|
|
|
*
|
|
|
|
* This file is a part of Tusky.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
|
|
|
|
2018-03-10 08:02:32 +11:00
|
|
|
package com.keylesspalace.tusky
|
|
|
|
|
2020-10-29 04:43:11 +11:00
|
|
|
import android.content.Intent
|
2020-11-23 05:02:54 +11:00
|
|
|
import android.os.Looper.getMainLooper
|
2018-04-29 18:08:25 +10:00
|
|
|
import android.text.SpannedString
|
2018-03-10 08:02:32 +11:00
|
|
|
import android.widget.EditText
|
2019-12-20 05:09:40 +11:00
|
|
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
|
|
import com.keylesspalace.tusky.components.compose.ComposeActivity
|
|
|
|
import com.keylesspalace.tusky.components.compose.ComposeViewModel
|
|
|
|
import com.keylesspalace.tusky.components.compose.DEFAULT_CHARACTER_LIMIT
|
|
|
|
import com.keylesspalace.tusky.components.compose.MediaUploader
|
|
|
|
import com.keylesspalace.tusky.db.*
|
|
|
|
import com.keylesspalace.tusky.di.ViewModelFactory
|
2018-04-29 18:08:25 +10:00
|
|
|
import com.keylesspalace.tusky.entity.Account
|
2018-04-22 18:35:46 +10:00
|
|
|
import com.keylesspalace.tusky.entity.Instance
|
2018-04-14 06:37:21 +10:00
|
|
|
import com.keylesspalace.tusky.network.MastodonApi
|
2019-12-20 05:09:40 +11:00
|
|
|
import com.keylesspalace.tusky.service.ServiceClient
|
|
|
|
import com.keylesspalace.tusky.util.SaveTootHelper
|
|
|
|
import com.nhaarman.mockitokotlin2.any
|
|
|
|
import io.reactivex.Single
|
|
|
|
import io.reactivex.SingleObserver
|
2018-04-29 18:08:25 +10:00
|
|
|
import org.junit.Assert.*
|
2018-03-10 08:02:32 +11:00
|
|
|
import org.junit.Before
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.runner.RunWith
|
|
|
|
import org.mockito.Mockito.`when`
|
2018-05-27 18:22:12 +10:00
|
|
|
import org.mockito.Mockito.mock
|
2018-03-10 08:02:32 +11:00
|
|
|
import org.robolectric.Robolectric
|
2020-11-23 05:02:54 +11:00
|
|
|
import org.robolectric.Shadows.shadowOf
|
2018-03-10 08:02:32 +11:00
|
|
|
import org.robolectric.annotation.Config
|
|
|
|
import org.robolectric.fakes.RoboMenuItem
|
2019-03-08 07:33:29 +11:00
|
|
|
|
2018-03-10 08:02:32 +11:00
|
|
|
/**
|
|
|
|
* Created by charlag on 3/7/18.
|
|
|
|
*/
|
|
|
|
|
2020-02-26 05:49:15 +11:00
|
|
|
@Config(sdk = [28])
|
2019-03-31 01:18:16 +11:00
|
|
|
@RunWith(AndroidJUnit4::class)
|
2018-03-10 08:02:32 +11:00
|
|
|
class ComposeActivityTest {
|
2019-03-31 01:18:16 +11:00
|
|
|
private lateinit var activity: ComposeActivity
|
|
|
|
private lateinit var accountManagerMock: AccountManager
|
|
|
|
private lateinit var apiMock: MastodonApi
|
2018-03-10 08:02:32 +11:00
|
|
|
|
2019-12-20 05:09:40 +11:00
|
|
|
private val instanceDomain = "example.domain"
|
|
|
|
|
2019-03-31 01:18:16 +11:00
|
|
|
private val account = AccountEntity(
|
2018-03-10 08:02:32 +11:00
|
|
|
id = 1,
|
2019-12-20 05:09:40 +11:00
|
|
|
domain = instanceDomain,
|
2018-03-10 08:02:32 +11:00
|
|
|
accessToken = "token",
|
|
|
|
isActive = true,
|
|
|
|
accountId = "1",
|
|
|
|
username = "username",
|
|
|
|
displayName = "Display Name",
|
|
|
|
profilePictureUrl = "",
|
|
|
|
notificationsEnabled = true,
|
|
|
|
notificationsMentioned = true,
|
|
|
|
notificationsFollowed = true,
|
2020-03-20 08:02:10 +11:00
|
|
|
notificationsFollowRequested = false,
|
2018-03-10 08:02:32 +11:00
|
|
|
notificationsReblogged = true,
|
|
|
|
notificationsFavorited = true,
|
|
|
|
notificationSound = true,
|
|
|
|
notificationVibration = true,
|
|
|
|
notificationLight = true
|
|
|
|
)
|
2020-11-23 05:02:54 +11:00
|
|
|
private var instanceResponseCallback: (()->Instance)? = null
|
|
|
|
private var composeOptions: ComposeActivity.ComposeOptions? = null
|
2018-03-10 08:02:32 +11:00
|
|
|
|
|
|
|
@Before
|
2018-04-29 18:08:25 +10:00
|
|
|
fun setupActivity() {
|
2018-03-10 08:02:32 +11:00
|
|
|
val controller = Robolectric.buildActivity(ComposeActivity::class.java)
|
|
|
|
activity = controller.get()
|
2018-04-14 06:37:21 +10:00
|
|
|
|
2019-10-04 03:58:21 +10:00
|
|
|
accountManagerMock = mock(AccountManager::class.java)
|
2019-12-20 05:09:40 +11:00
|
|
|
`when`(accountManagerMock.activeAccount).thenReturn(account)
|
2018-04-14 06:37:21 +10:00
|
|
|
|
2019-10-04 03:58:21 +10:00
|
|
|
apiMock = mock(MastodonApi::class.java)
|
2019-12-20 05:09:40 +11:00
|
|
|
`when`(apiMock.getCustomEmojis()).thenReturn(Single.just(emptyList()))
|
2019-09-22 16:18:44 +10:00
|
|
|
`when`(apiMock.getInstance()).thenReturn(object: Single<Instance>() {
|
2019-08-05 04:25:07 +10:00
|
|
|
override fun subscribeActual(observer: SingleObserver<in Instance>) {
|
|
|
|
val instance = instanceResponseCallback?.invoke()
|
|
|
|
if (instance == null) {
|
|
|
|
observer.onError(Throwable())
|
|
|
|
} else {
|
|
|
|
observer.onSuccess(instance)
|
|
|
|
}
|
2018-04-29 18:08:25 +10:00
|
|
|
}
|
2018-04-22 18:35:46 +10:00
|
|
|
})
|
2018-04-14 06:37:21 +10:00
|
|
|
|
2018-05-27 18:22:12 +10:00
|
|
|
val instanceDaoMock = mock(InstanceDao::class.java)
|
2019-12-20 05:09:40 +11:00
|
|
|
`when`(instanceDaoMock.loadMetadataForInstance(any())).thenReturn(
|
|
|
|
Single.just(InstanceEntity(instanceDomain, emptyList(),null, null, null, null))
|
|
|
|
)
|
|
|
|
|
2018-05-27 18:22:12 +10:00
|
|
|
val dbMock = mock(AppDatabase::class.java)
|
|
|
|
`when`(dbMock.instanceDao()).thenReturn(instanceDaoMock)
|
|
|
|
|
2019-12-20 05:09:40 +11:00
|
|
|
val viewModel = ComposeViewModel(
|
|
|
|
apiMock,
|
|
|
|
accountManagerMock,
|
|
|
|
mock(MediaUploader::class.java),
|
|
|
|
mock(ServiceClient::class.java),
|
|
|
|
mock(SaveTootHelper::class.java),
|
|
|
|
dbMock
|
|
|
|
)
|
2020-10-29 04:43:11 +11:00
|
|
|
activity.intent = Intent(activity, ComposeActivity::class.java).apply {
|
|
|
|
putExtra(ComposeActivity.COMPOSE_OPTIONS_EXTRA, composeOptions)
|
|
|
|
}
|
2018-04-14 06:37:21 +10:00
|
|
|
|
2019-12-20 05:09:40 +11:00
|
|
|
val viewModelFactoryMock = mock(ViewModelFactory::class.java)
|
|
|
|
`when`(viewModelFactoryMock.create(ComposeViewModel::class.java)).thenReturn(viewModel)
|
2018-04-14 06:37:21 +10:00
|
|
|
|
2019-12-20 05:09:40 +11:00
|
|
|
activity.accountManager = accountManagerMock
|
|
|
|
activity.viewModelFactory = viewModelFactoryMock
|
2018-04-14 06:37:21 +10:00
|
|
|
|
2018-03-10 08:02:32 +11:00
|
|
|
controller.create().start()
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun whenCloseButtonPressedAndEmpty_finish() {
|
|
|
|
clickUp()
|
|
|
|
assertTrue(activity.isFinishing)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun whenCloseButtonPressedNotEmpty_notFinish() {
|
|
|
|
insertSomeTextInContent()
|
|
|
|
clickUp()
|
|
|
|
assertFalse(activity.isFinishing)
|
|
|
|
// We would like to check for dialog but Robolectric doesn't work with AppCompat v7 yet
|
|
|
|
}
|
|
|
|
|
2020-10-29 04:43:11 +11:00
|
|
|
@Test
|
|
|
|
fun whenModifiedInitialState_andCloseButtonPressed_notFinish() {
|
|
|
|
composeOptions = ComposeActivity.ComposeOptions(modifiedInitialState = true)
|
|
|
|
setupActivity()
|
|
|
|
clickUp()
|
|
|
|
assertFalse(activity.isFinishing)
|
|
|
|
}
|
|
|
|
|
2018-03-10 08:02:32 +11:00
|
|
|
@Test
|
|
|
|
fun whenBackButtonPressedAndEmpty_finish() {
|
|
|
|
clickBack()
|
|
|
|
assertTrue(activity.isFinishing)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun whenBackButtonPressedNotEmpty_notFinish() {
|
|
|
|
insertSomeTextInContent()
|
|
|
|
clickBack()
|
|
|
|
assertFalse(activity.isFinishing)
|
|
|
|
// We would like to check for dialog but Robolectric doesn't work with AppCompat v7 yet
|
|
|
|
}
|
|
|
|
|
2020-10-29 04:43:11 +11:00
|
|
|
@Test
|
|
|
|
fun whenModifiedInitialState_andBackButtonPressed_notFinish() {
|
|
|
|
composeOptions = ComposeActivity.ComposeOptions(modifiedInitialState = true)
|
|
|
|
setupActivity()
|
|
|
|
clickBack()
|
|
|
|
assertFalse(activity.isFinishing)
|
|
|
|
}
|
|
|
|
|
2018-04-29 18:08:25 +10:00
|
|
|
@Test
|
|
|
|
fun whenMaximumTootCharsIsNull_defaultLimitIsUsed() {
|
2019-08-05 04:25:07 +10:00
|
|
|
instanceResponseCallback = { getInstanceWithMaximumTootCharacters(null) }
|
2018-04-29 18:08:25 +10:00
|
|
|
setupActivity()
|
2019-12-20 05:09:40 +11:00
|
|
|
assertEquals(DEFAULT_CHARACTER_LIMIT, activity.maximumTootCharacters)
|
2018-04-29 18:08:25 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun whenMaximumTootCharsIsPopulated_customLimitIsUsed() {
|
|
|
|
val customMaximum = 1000
|
2019-08-05 04:25:07 +10:00
|
|
|
instanceResponseCallback = { getInstanceWithMaximumTootCharacters(customMaximum) }
|
2018-04-29 18:08:25 +10:00
|
|
|
setupActivity()
|
2020-11-23 05:02:54 +11:00
|
|
|
shadowOf(getMainLooper()).idle()
|
2018-04-29 18:08:25 +10:00
|
|
|
assertEquals(customMaximum, activity.maximumTootCharacters)
|
|
|
|
}
|
|
|
|
|
2018-05-17 03:14:26 +10:00
|
|
|
@Test
|
2018-07-11 03:39:52 +10:00
|
|
|
fun whenTextContainsNoUrl_everyCharacterIsCounted() {
|
|
|
|
val content = "This is test content please ignore thx "
|
|
|
|
insertSomeTextInContent(content)
|
2019-10-04 03:58:21 +10:00
|
|
|
assertEquals(activity.calculateTextLength(), content.length)
|
2018-07-11 03:39:52 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun whenTextContainsUrl_onlyEllipsizedURLIsCounted() {
|
2018-05-17 03:14:26 +10:00
|
|
|
val url = "https://www.google.dk/search?biw=1920&bih=990&tbm=isch&sa=1&ei=bmDrWuOoKMv6kwWOkIaoDQ&q=indiana+jones+i+hate+snakes+animated&oq=indiana+jones+i+hate+snakes+animated&gs_l=psy-ab.3...54174.55443.0.55553.9.7.0.0.0.0.255.333.1j0j1.2.0....0...1c.1.64.psy-ab..7.0.0....0.40G-kcDkC6A#imgdii=PSp15hQjN1JqvM:&imgrc=H0hyE2JW5wrpBM:"
|
|
|
|
val additionalContent = "Check out this @image #search result: "
|
|
|
|
insertSomeTextInContent(additionalContent + url)
|
2019-10-04 03:58:21 +10:00
|
|
|
assertEquals(activity.calculateTextLength(), additionalContent.length + ComposeActivity.MAXIMUM_URL_LENGTH)
|
2018-07-11 03:39:52 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun whenTextContainsMultipleUrls_onlyEllipsizedURLIsCounted() {
|
|
|
|
val shortUrl = "https://tusky.app"
|
|
|
|
val url = "https://www.google.dk/search?biw=1920&bih=990&tbm=isch&sa=1&ei=bmDrWuOoKMv6kwWOkIaoDQ&q=indiana+jones+i+hate+snakes+animated&oq=indiana+jones+i+hate+snakes+animated&gs_l=psy-ab.3...54174.55443.0.55553.9.7.0.0.0.0.255.333.1j0j1.2.0....0...1c.1.64.psy-ab..7.0.0....0.40G-kcDkC6A#imgdii=PSp15hQjN1JqvM:&imgrc=H0hyE2JW5wrpBM:"
|
|
|
|
val additionalContent = " Check out this @image #search result: "
|
|
|
|
insertSomeTextInContent(shortUrl + additionalContent + url)
|
2019-12-20 05:09:40 +11:00
|
|
|
assertEquals(activity.calculateTextLength(), additionalContent.length + shortUrl.length + ComposeActivity.MAXIMUM_URL_LENGTH)
|
2018-05-17 03:14:26 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun whenTextContainsMultipleURLs_allURLsGetEllipsized() {
|
|
|
|
val url = "https://www.google.dk/search?biw=1920&bih=990&tbm=isch&sa=1&ei=bmDrWuOoKMv6kwWOkIaoDQ&q=indiana+jones+i+hate+snakes+animated&oq=indiana+jones+i+hate+snakes+animated&gs_l=psy-ab.3...54174.55443.0.55553.9.7.0.0.0.0.255.333.1j0j1.2.0....0...1c.1.64.psy-ab..7.0.0....0.40G-kcDkC6A#imgdii=PSp15hQjN1JqvM:&imgrc=H0hyE2JW5wrpBM:"
|
|
|
|
val additionalContent = " Check out this @image #search result: "
|
|
|
|
insertSomeTextInContent(url + additionalContent + url)
|
2019-12-20 05:09:40 +11:00
|
|
|
assertEquals(activity.calculateTextLength(), additionalContent.length + (ComposeActivity.MAXIMUM_URL_LENGTH * 2))
|
2018-05-17 03:14:26 +10:00
|
|
|
}
|
|
|
|
|
2020-01-14 01:21:17 +11:00
|
|
|
@Test
|
|
|
|
fun whenSelectionIsEmpty_specialTextIsInsertedAtCaret() {
|
|
|
|
val editor = activity.findViewById<EditText>(R.id.composeEditField)
|
|
|
|
val insertText = "#"
|
|
|
|
editor.setText("Some text")
|
|
|
|
|
|
|
|
for (caretIndex in listOf(9, 1, 0)) {
|
|
|
|
editor.setSelection(caretIndex)
|
|
|
|
activity.prependSelectedWordsWith(insertText)
|
|
|
|
// Text should be inserted at caret
|
2020-11-23 05:02:54 +11:00
|
|
|
assertEquals("Unexpected value at $caretIndex", insertText, editor.text.substring(caretIndex, caretIndex + insertText.length))
|
2020-01-14 01:21:17 +11:00
|
|
|
|
|
|
|
// Caret should be placed after inserted text
|
|
|
|
assertEquals(caretIndex + insertText.length, editor.selectionStart)
|
|
|
|
assertEquals(caretIndex + insertText.length, editor.selectionEnd)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun whenSelectionDoesNotIncludeWordBreak_noSpecialTextIsInserted() {
|
|
|
|
val editor = activity.findViewById<EditText>(R.id.composeEditField)
|
|
|
|
val insertText = "#"
|
|
|
|
val originalText = "Some text"
|
|
|
|
val selectionStart = 1
|
|
|
|
val selectionEnd = 4
|
|
|
|
editor.setText(originalText)
|
|
|
|
editor.setSelection(selectionStart, selectionEnd) // "ome"
|
|
|
|
activity.prependSelectedWordsWith(insertText)
|
|
|
|
|
|
|
|
// Text and selection should be unmodified
|
|
|
|
assertEquals(originalText, editor.text.toString())
|
|
|
|
assertEquals(selectionStart, editor.selectionStart)
|
|
|
|
assertEquals(selectionEnd, editor.selectionEnd)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun whenSelectionIncludesWordBreaks_startsOfAllWordsArePrepended() {
|
|
|
|
val editor = activity.findViewById<EditText>(R.id.composeEditField)
|
|
|
|
val insertText = "#"
|
|
|
|
val originalText = "one two three four"
|
|
|
|
val selectionStart = 2
|
|
|
|
val originalSelectionEnd = 15
|
|
|
|
val modifiedSelectionEnd = 18
|
|
|
|
editor.setText(originalText)
|
|
|
|
editor.setSelection(selectionStart, originalSelectionEnd) // "e two three f"
|
|
|
|
activity.prependSelectedWordsWith(insertText)
|
|
|
|
|
|
|
|
// text should be inserted at word starts inside selection
|
|
|
|
assertEquals("one #two #three #four", editor.text.toString())
|
|
|
|
|
|
|
|
// selection should be expanded accordingly
|
|
|
|
assertEquals(selectionStart, editor.selectionStart)
|
|
|
|
assertEquals(modifiedSelectionEnd, editor.selectionEnd)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun whenSelectionIncludesEnd_textIsNotAppended() {
|
|
|
|
val editor = activity.findViewById<EditText>(R.id.composeEditField)
|
|
|
|
val insertText = "#"
|
|
|
|
val originalText = "Some text"
|
|
|
|
val selectionStart = 7
|
|
|
|
val selectionEnd = 9
|
|
|
|
editor.setText(originalText)
|
|
|
|
editor.setSelection(selectionStart, selectionEnd) // "xt"
|
|
|
|
activity.prependSelectedWordsWith(insertText)
|
|
|
|
|
|
|
|
// Text and selection should be unmodified
|
|
|
|
assertEquals(originalText, editor.text.toString())
|
|
|
|
assertEquals(selectionStart, editor.selectionStart)
|
|
|
|
assertEquals(selectionEnd, editor.selectionEnd)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun whenSelectionIncludesStartAndStartIsAWord_textIsPrepended() {
|
|
|
|
val editor = activity.findViewById<EditText>(R.id.composeEditField)
|
|
|
|
val insertText = "#"
|
|
|
|
val originalText = "Some text"
|
|
|
|
val selectionStart = 0
|
|
|
|
val selectionEnd = 3
|
|
|
|
editor.setText(originalText)
|
|
|
|
editor.setSelection(selectionStart, selectionEnd) // "Som"
|
|
|
|
activity.prependSelectedWordsWith(insertText)
|
|
|
|
|
|
|
|
// Text should be inserted at beginning
|
|
|
|
assert(editor.text.startsWith(insertText))
|
|
|
|
|
|
|
|
// selection should be expanded accordingly
|
|
|
|
assertEquals(selectionStart, editor.selectionStart)
|
|
|
|
assertEquals(selectionEnd + insertText.length, editor.selectionEnd)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun whenSelectionIncludesStartAndStartIsNotAWord_textIsNotPrepended() {
|
|
|
|
val editor = activity.findViewById<EditText>(R.id.composeEditField)
|
|
|
|
val insertText = "#"
|
|
|
|
val originalText = " Some text"
|
|
|
|
val selectionStart = 0
|
|
|
|
val selectionEnd = 1
|
|
|
|
editor.setText(originalText)
|
|
|
|
editor.setSelection(selectionStart, selectionEnd) // " "
|
|
|
|
activity.prependSelectedWordsWith(insertText)
|
|
|
|
|
|
|
|
// Text and selection should be unmodified
|
|
|
|
assertEquals(originalText, editor.text.toString())
|
|
|
|
assertEquals(selectionStart, editor.selectionStart)
|
|
|
|
assertEquals(selectionEnd, editor.selectionEnd)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun whenSelectionBeginsAtWordStart_textIsPrepended() {
|
|
|
|
val editor = activity.findViewById<EditText>(R.id.composeEditField)
|
|
|
|
val insertText = "#"
|
|
|
|
val originalText = "Some text"
|
|
|
|
val selectionStart = 5
|
|
|
|
val selectionEnd = 9
|
|
|
|
editor.setText(originalText)
|
|
|
|
editor.setSelection(selectionStart, selectionEnd) // "text"
|
|
|
|
activity.prependSelectedWordsWith(insertText)
|
|
|
|
|
|
|
|
// Text is prepended
|
|
|
|
assertEquals("Some #text", editor.text.toString())
|
|
|
|
|
|
|
|
// Selection is expanded accordingly
|
|
|
|
assertEquals(selectionStart, editor.selectionStart)
|
|
|
|
assertEquals(selectionEnd + insertText.length, editor.selectionEnd)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun whenSelectionEndsAtWordStart_textIsAppended() {
|
|
|
|
val editor = activity.findViewById<EditText>(R.id.composeEditField)
|
|
|
|
val insertText = "#"
|
|
|
|
val originalText = "Some text"
|
|
|
|
val selectionStart = 1
|
|
|
|
val selectionEnd = 5
|
|
|
|
editor.setText(originalText)
|
|
|
|
editor.setSelection(selectionStart, selectionEnd) // "ome "
|
|
|
|
activity.prependSelectedWordsWith(insertText)
|
|
|
|
|
|
|
|
// Text is prepended
|
|
|
|
assertEquals("Some #text", editor.text.toString())
|
|
|
|
|
|
|
|
// Selection is expanded accordingly
|
|
|
|
assertEquals(selectionStart, editor.selectionStart)
|
|
|
|
assertEquals(selectionEnd + insertText.length, editor.selectionEnd)
|
|
|
|
}
|
|
|
|
|
2018-03-10 08:02:32 +11:00
|
|
|
private fun clickUp() {
|
|
|
|
val menuItem = RoboMenuItem(android.R.id.home)
|
|
|
|
activity.onOptionsItemSelected(menuItem)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun clickBack() {
|
|
|
|
activity.onBackPressed()
|
|
|
|
}
|
|
|
|
|
2018-05-17 03:14:26 +10:00
|
|
|
private fun insertSomeTextInContent(text: String? = null) {
|
|
|
|
activity.findViewById<EditText>(R.id.composeEditField).setText(text ?: "Some text")
|
2018-03-10 08:02:32 +11:00
|
|
|
}
|
2018-04-29 18:08:25 +10:00
|
|
|
|
|
|
|
private fun getInstanceWithMaximumTootCharacters(maximumTootCharacters: Int?): Instance
|
|
|
|
{
|
|
|
|
return Instance(
|
|
|
|
"https://example.token",
|
|
|
|
"Example dot Token",
|
|
|
|
"Example instance for testing",
|
|
|
|
"admin@example.token",
|
|
|
|
"2.6.3",
|
2019-03-31 01:18:16 +11:00
|
|
|
HashMap(),
|
2018-04-29 18:08:25 +10:00
|
|
|
null,
|
|
|
|
null,
|
|
|
|
listOf("en"),
|
|
|
|
Account(
|
|
|
|
"1",
|
|
|
|
"admin",
|
|
|
|
"admin",
|
|
|
|
"admin",
|
|
|
|
SpannedString(""),
|
|
|
|
"https://example.token",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
false,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2018-06-18 21:26:18 +10:00
|
|
|
null,
|
2018-07-01 22:51:45 +10:00
|
|
|
false,
|
|
|
|
emptyList(),
|
|
|
|
emptyList()
|
2018-04-29 18:08:25 +10:00
|
|
|
),
|
2019-08-05 04:25:07 +10:00
|
|
|
maximumTootCharacters,
|
2019-08-23 04:30:08 +10:00
|
|
|
null,
|
2019-08-05 04:25:07 +10:00
|
|
|
null
|
2018-04-29 18:08:25 +10:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-12-20 05:09:40 +11:00
|
|
|
}
|
|
|
|
|