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
2022-11-04 18:59:16 +00:00
import org.junit.Ignore
2022-05-16 14:15:56 +00:00
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
2022-07-11 15:54:30 +00:00
import org.thoughtcrime.securesms.contacts.paged.ContactSearchKey
2022-12-01 23:15:37 +00:00
import org.thoughtcrime.securesms.database.IdentityTable
2022-05-16 14:15:56 +00:00
import org.thoughtcrime.securesms.database.SignalDatabase
2022-07-20 12:20:18 +00:00
import org.thoughtcrime.securesms.database.model.DistributionListId
import org.thoughtcrime.securesms.database.model.DistributionListPrivacyMode
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 .
* /
2022-11-04 18:59:16 +00:00
@Ignore ( " For testing/previewing manually, no assertions " )
2022-05-16 14:15:56 +00:00
@RunWith ( AndroidJUnit4 :: class )
class SafetyNumberChangeDialogPreviewer {
2022-07-13 15:34:15 +00:00
@get : Rule val harness = SignalActivityRule ( othersCount = 10 )
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 " ) )
2022-12-01 23:15:37 +00:00
harness . setVerified ( other , IdentityTable . VerifiedStatus . VERIFIED )
2022-05-16 14:15:56 +00:00
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 ( ) {
2022-07-20 12:20:18 +00:00
SignalDatabase . distributionLists . setPrivacyMode ( DistributionListId . MY _STORY , DistributionListPrivacyMode . ONLY _WITH )
2022-07-11 15:54:30 +00:00
val othersRecipients = harness . others . map { Recipient . resolved ( it ) }
othersRecipients . forEach { other ->
SignalDatabase . recipients . setProfileName ( other . id , ProfileName . fromParts ( " My " , " Name " ) )
2022-12-01 23:15:37 +00:00
harness . setVerified ( other , IdentityTable . VerifiedStatus . DEFAULT )
2022-07-11 15:54:30 +00:00
harness . changeIdentityKey ( other )
2022-07-20 12:20:18 +00:00
SignalDatabase . distributionLists . addMemberToList ( DistributionListId . MY _STORY , DistributionListPrivacyMode . ONLY _WITH , other . id )
2022-07-11 15:54:30 +00:00
}
2022-07-20 12:20:18 +00:00
val myStoryRecipientId = SignalDatabase . distributionLists . getRecipientId ( DistributionListId . MY _STORY ) !!
2022-07-11 15:54:30 +00:00
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 ,
2022-07-20 12:20:18 +00:00
destinations = listOf ( ContactSearchKey . RecipientSearchKey . Story ( myStoryRecipientId ) )
2022-07-11 15:54:30 +00:00
)
. 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-20 12:20:18 +00:00
// ThreadUtil.sleep( 30000)
2022-05-16 14:15:56 +00:00
}
}