main
Alibek Omarov 4 years ago
parent 05ab2c5c38
commit 9c11fea95d
  1. 2
      app/src/main/java/com/keylesspalace/tusky/util/OmittedDomainFetcher.kt
  2. 6
      app/src/test/java/com/keylesspalace/tusky/ComposeActivityTest.kt
  3. 16
      app/src/test/java/com/keylesspalace/tusky/TuskyApplication.kt

@ -26,8 +26,6 @@ class OmittedDomainAppModule : AppGlideModule() {
lateinit var accountManager : AccountManager
override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
Log.d("OmittedDomainAppModule", "registering loader factory")
(context.applicationContext as TuskyApplication).androidInjector.inject(this)
registry.append(String::class.java, InputStream::class.java, OmittedDomainLoaderFactory(accountManager))

@ -230,6 +230,7 @@ class ComposeActivityTest {
NodeInfoPleromaUploadLimits( 100, 100, 100, 100 ))
}
setupActivity()
shadowOf(getMainLooper()).idle()
assertEquals(true, activity.viewModel.hasNoAttachmentLimits)
}
@ -240,6 +241,7 @@ class ComposeActivityTest {
NodeInfoPleromaUploadLimits( 100, 100, 100, 100 ))
}
setupActivity()
shadowOf(getMainLooper()).idle()
assertArrayEquals(arrayOf("text/markdown", "text/bbcode"), activity.supportedFormattingSyntax.toTypedArray())
}
@ -250,6 +252,7 @@ class ComposeActivityTest {
NodeInfoPleromaUploadLimits( Long.MAX_VALUE, Long.MAX_VALUE, Long.MAX_VALUE, Long.MAX_VALUE ))
}
setupActivity()
shadowOf(getMainLooper()).idle()
assertEquals(Long.MAX_VALUE, activity.viewModel.instanceMetadata.value!!.imageLimit)
assertEquals(Long.MAX_VALUE, activity.viewModel.instanceMetadata.value!!.videoLimit)
}
@ -258,6 +261,7 @@ class ComposeActivityTest {
fun whenPixelfedInNodeInfo_haveCustomUploadLimits() {
nodeinfoResponseCallback = { getPixelfedNodeinfo( 1024 * 1024 ) }
setupActivity()
shadowOf(getMainLooper()).idle()
assertEquals(1024 * 1024 * 1024, activity.viewModel.instanceMetadata.value!!.imageLimit)
assertEquals(1024 * 1024 * 1024, activity.viewModel.instanceMetadata.value!!.videoLimit)
assertArrayEquals(emptyArray(), activity.supportedFormattingSyntax.toTypedArray()) // pixelfed has no formatting
@ -267,6 +271,7 @@ class ComposeActivityTest {
fun whenMastodonInNodeinfo_butItsAGlitch() {
nodeinfoResponseCallback = { getMastodonNodeinfo( "3.1.0+glitch" ) }
setupActivity()
shadowOf(getMainLooper()).idle()
assertArrayEquals(arrayOf("text/markdown", "text/html"), activity.supportedFormattingSyntax.toTypedArray())
}
@ -274,6 +279,7 @@ class ComposeActivityTest {
fun whenMastodonInNodeinfo_butItsBoringVanilla() {
nodeinfoResponseCallback = { getMastodonNodeinfo( "3.1.0" ) }
setupActivity()
shadowOf(getMainLooper()).idle()
assertArrayEquals(emptyArray(), activity.supportedFormattingSyntax.toTypedArray())
}

@ -20,10 +20,14 @@ import android.content.Context
import android.content.res.Configuration
import android.util.Log
import androidx.emoji.text.EmojiCompat
import com.keylesspalace.tusky.db.AccountManager
import com.keylesspalace.tusky.util.LocaleManager
import com.keylesspalace.tusky.util.OmittedDomainAppModule
import dagger.android.DispatchingAndroidInjector
import dagger.android.HasAndroidInjector
import de.c1710.filemojicompat.FileEmojiCompatConfig
import org.mockito.Mockito.*
import org.mockito.stubbing.Answer
import javax.inject.Inject
// override TuskyApplication for Robolectric tests, only initialize the necessary stuff
@ -44,8 +48,18 @@ class TuskyApplication : Application() {
localeManager.setLocale(this)
}
fun getAndroidInjector() : DispatchingAndroidInjector<Any> {
val mock = mock(DispatchingAndroidInjector::class.java) as DispatchingAndroidInjector<OmittedDomainAppModule>
`when`(mock.inject(any())).then {
it.getArgument<OmittedDomainAppModule>(0).accountManager = mock(AccountManager::class.java)
return@then Unit
}
return mock as DispatchingAndroidInjector<Any>
}
companion object {
@JvmStatic
lateinit var localeManager: LocaleManager
}
}
}

Loading…
Cancel
Save