fix: android tests work again and permissions

This commit is contained in:
0x330a 2023-07-03 11:26:15 +10:00
parent c2763de664
commit 2fae48e2d5
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
5 changed files with 15 additions and 8 deletions

View File

@ -136,6 +136,10 @@ dependencies {
// Core library // Core library
androidTestImplementation "androidx.test:core:$testCoreVersion" androidTestImplementation "androidx.test:core:$testCoreVersion"
androidTestImplementation('com.adevinta.android:barista:4.2.0') {
exclude group: 'org.jetbrains.kotlin'
}
// AndroidJUnitRunner and JUnit Rules // AndroidJUnitRunner and JUnit Rules
androidTestImplementation 'androidx.test:runner:1.5.2' androidTestImplementation 'androidx.test:runner:1.5.2'
androidTestImplementation 'androidx.test:rules:1.5.0' androidTestImplementation 'androidx.test:rules:1.5.0'

View File

@ -1,5 +1,6 @@
package network.loki.messenger package network.loki.messenger
import android.Manifest
import android.app.Instrumentation import android.app.Instrumentation
import android.content.ClipboardManager import android.content.ClipboardManager
import android.content.Context import android.content.Context
@ -21,6 +22,7 @@ import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest import androidx.test.filters.LargeTest
import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry
import com.adevinta.android.barista.interaction.PermissionGranter
import network.loki.messenger.util.InputBarButtonDrawableMatcher.Companion.inputButtonWithDrawable import network.loki.messenger.util.InputBarButtonDrawableMatcher.Companion.inputButtonWithDrawable
import org.hamcrest.Matcher import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf import org.hamcrest.Matchers.allOf
@ -85,6 +87,8 @@ class HomeActivityTests {
} }
onView(withId(R.id.backgroundPollingOptionView)).perform(ViewActions.click()) onView(withId(R.id.backgroundPollingOptionView)).perform(ViewActions.click())
onView(withId(R.id.registerButton)).perform(ViewActions.click()) onView(withId(R.id.registerButton)).perform(ViewActions.click())
// allow notification permission
PermissionGranter.allowPermissionsIfNeeded(Manifest.permission.POST_NOTIFICATIONS)
} }
private fun goToMyChat() { private fun goToMyChat() {
@ -100,6 +104,7 @@ class HomeActivityTests {
copied = clipboardManager.primaryClip!!.getItemAt(0).text.toString() copied = clipboardManager.primaryClip!!.getItemAt(0).text.toString()
} }
onView(withId(R.id.publicKeyEditText)).perform(ViewActions.typeText(copied)) onView(withId(R.id.publicKeyEditText)).perform(ViewActions.typeText(copied))
onView(withId(R.id.publicKeyEditText)).perform(ViewActions.closeSoftKeyboard())
onView(withId(R.id.createPrivateChatButton)).perform(ViewActions.click()) onView(withId(R.id.createPrivateChatButton)).perform(ViewActions.click())
} }

View File

@ -693,7 +693,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
val name = contact?.displayName(Contact.ContactContext.REGULAR) ?: sessionID val name = contact?.displayName(Contact.ContactContext.REGULAR) ?: sessionID
binding?.blockedBannerTextView?.text = resources.getString(R.string.activity_conversation_blocked_banner_text, name) binding?.blockedBannerTextView?.text = resources.getString(R.string.activity_conversation_blocked_banner_text, name)
binding?.blockedBanner?.isVisible = recipient.isBlocked binding?.blockedBanner?.isVisible = recipient.isBlocked
binding?.blockedBanner?.setOnClickListener { viewModel.unblock(this@ConversationActivityV2) } binding?.blockedBanner?.setOnClickListener { viewModel.unblock() }
} }
private fun setUpLinkPreviewObserver() { private fun setUpLinkPreviewObserver() {
@ -1151,7 +1151,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
.setMessage(message) .setMessage(message)
.setNegativeButton(android.R.string.cancel, null) .setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(R.string.RecipientPreferenceActivity_block) { _, _ -> .setPositiveButton(R.string.RecipientPreferenceActivity_block) { _, _ ->
viewModel.block(this@ConversationActivityV2) viewModel.block()
if (deleteThread) { if (deleteThread) {
viewModel.deleteThread() viewModel.deleteThread()
finish() finish()
@ -1205,7 +1205,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
.setMessage(message) .setMessage(message)
.setNegativeButton(android.R.string.cancel, null) .setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(R.string.ConversationActivity_unblock) { _, _ -> .setPositiveButton(R.string.ConversationActivity_unblock) { _, _ ->
viewModel.unblock(this@ConversationActivityV2) viewModel.unblock()
}.show() }.show()
} }

View File

@ -1,7 +1,6 @@
package org.thoughtcrime.securesms.conversation.v2 package org.thoughtcrime.securesms.conversation.v2
import android.content.ContentResolver import android.content.ContentResolver
import android.content.Context
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
@ -26,7 +25,6 @@ import org.thoughtcrime.securesms.database.DatabaseContentProviders
import org.thoughtcrime.securesms.database.Storage import org.thoughtcrime.securesms.database.Storage
import org.thoughtcrime.securesms.database.model.MessageRecord import org.thoughtcrime.securesms.database.model.MessageRecord
import org.thoughtcrime.securesms.repository.ConversationRepository import org.thoughtcrime.securesms.repository.ConversationRepository
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
import java.util.UUID import java.util.UUID
class ConversationViewModel( class ConversationViewModel(
@ -96,14 +94,14 @@ class ConversationViewModel(
repository.inviteContacts(threadId, contacts) repository.inviteContacts(threadId, contacts)
} }
fun block(context: Context) { fun block() {
val recipient = recipient ?: return Log.w("Loki", "Recipient was null for block action") val recipient = recipient ?: return Log.w("Loki", "Recipient was null for block action")
if (recipient.isContactRecipient) { if (recipient.isContactRecipient) {
repository.setBlocked(recipient, true) repository.setBlocked(recipient, true)
} }
} }
fun unblock(context: Context) { fun unblock() {
val recipient = recipient ?: return Log.w("Loki", "Recipient was null for unblock action") val recipient = recipient ?: return Log.w("Loki", "Recipient was null for unblock action")
if (recipient.isContactRecipient) { if (recipient.isContactRecipient) {
repository.setBlocked(recipient, false) repository.setBlocked(recipient, false)

View File

@ -61,7 +61,7 @@ class InstrumentedTests {
contacts.dump() contacts.dump()
contacts.set(contact.copy(name = "test2")) contacts.set(contact.copy(name = "test2"))
contacts.set(contact.copy(name = "test")) contacts.set(contact.copy(name = "test"))
assertFalse(contacts.dirty()) assertTrue(contacts.dirty())
} }
@Test @Test