2022-05-16 14:15:56 +00:00
package org.thoughtcrime.securesms.conversation
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
2022-07-13 13:12:54 +00:00
import org.signal.core.util.ThreadUtil
2022-07-11 15:54:30 +00:00
import org.thoughtcrime.securesms.contacts.paged.ContactSearchKey
2022-05-16 14:15:56 +00:00
import org.thoughtcrime.securesms.database.IdentityDatabase
import org.thoughtcrime.securesms.database.SignalDatabase
2022-07-11 15:54:30 +00:00
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
2022-05-16 14:15:56 +00:00
import org.thoughtcrime.securesms.profiles.ProfileName
import org.thoughtcrime.securesms.recipients.Recipient
2022-07-11 15:54:30 +00:00
import org.thoughtcrime.securesms.safety.SafetyNumberBottomSheet
2022-05-16 14:15:56 +00:00
import org.thoughtcrime.securesms.testing.SignalActivityRule
/ * *
* Android test to help show SNC dialog quickly with custom data to make sure it displays properly .
* /
@RunWith ( AndroidJUnit4 :: class )
class SafetyNumberChangeDialogPreviewer {
2022-07-13 13:12:54 +00:00
@get : Rule val harness = SignalActivityRule ( othersCount = 5 )
2022-05-16 14:15:56 +00:00
@Test
fun testShowLongName ( ) {
val other : Recipient = Recipient . resolved ( harness . others . first ( ) )
SignalDatabase . recipients . setProfileName ( other . id , ProfileName . fromParts ( " Super really long name like omg " , " But seriously it's long like really really long " ) )
harness . setVerified ( other , IdentityDatabase . VerifiedStatus . VERIFIED )
harness . changeIdentityKey ( other )
val scenario : ActivityScenario < ConversationActivity > = harness . launchActivity { putExtra ( " recipient_id " , other . id . serialize ( ) ) }
scenario . onActivity {
2022-07-11 15:54:30 +00:00
SafetyNumberBottomSheet . forRecipientId ( other . id ) . show ( it . supportFragmentManager )
}
// Uncomment to make dialog stay on screen, otherwise will show/dismiss immediately
// ThreadUtil.sleep(15000)
}
@Test
fun testShowLargeSheet ( ) {
val othersRecipients = harness . others . map { Recipient . resolved ( it ) }
othersRecipients . forEach { other ->
SignalDatabase . recipients . setProfileName ( other . id , ProfileName . fromParts ( " My " , " Name " ) )
2022-07-13 13:12:54 +00:00
harness . setVerified ( other , IdentityDatabase . VerifiedStatus . DEFAULT )
2022-07-11 15:54:30 +00:00
harness . changeIdentityKey ( other )
}
val scenario : ActivityScenario < ConversationActivity > = harness . launchActivity { putExtra ( " recipient_id " , harness . others . first ( ) . serialize ( ) ) }
scenario . onActivity { conversationActivity ->
SafetyNumberBottomSheet
. forIdentityRecordsAndDestinations (
identityRecords = ApplicationDependencies . getProtocolStore ( ) . aci ( ) . identities ( ) . getIdentityRecords ( othersRecipients ) . identityRecords ,
destinations = othersRecipients . map { ContactSearchKey . RecipientSearchKey . KnownRecipient ( it . id ) }
)
. show ( conversationActivity . supportFragmentManager )
2022-05-16 14:15:56 +00:00
}
// Uncomment to make dialog stay on screen, otherwise will show/dismiss immediately
2022-07-13 13:12:54 +00:00
ThreadUtil . sleep ( 15000 )
2022-05-16 14:15:56 +00:00
}
}