Add PillDisplayHandler tests for custom domains.

This commit is contained in:
David Langley 2023-06-09 16:02:09 +01:00
parent f3db4a857a
commit cfa0f95799

View file

@ -55,6 +55,8 @@ internal class PillDisplayHandlerTest {
const val KNOWN_MATRIX_USER_URL = "https://matrix.to/#/$KNOWN_MATRIX_USER_ID"
const val KNOWN_MATRIX_USER_AVATAR = "https://example.com/avatar.png"
const val KNOWN_MATRIX_USER_NAME = "known user"
const val CUSTOM_DOMAIN_MATRIX_ROOM_URL = "https://customdomain/#/room/$KNOWN_MATRIX_ROOM_ID"
const val CUSTOM_DOMAIN_MATRIX_USER_URL = "https://customdomain.com/#/user/$KNOWN_MATRIX_USER_ID"
}
@Before
@ -153,6 +155,26 @@ internal class PillDisplayHandlerTest {
assertEquals(listOf("@room"), subject.keywords)
}
@Test
fun `when resolve known user for custom domain link, then it returns named custom pill`() {
val subject = createSubject()
val matrixItem = subject.resolveLinkDisplay("text", CUSTOM_DOMAIN_MATRIX_USER_URL)
.getMatrixItem()
assertEquals(MatrixItem.UserItem(KNOWN_MATRIX_USER_ID, KNOWN_MATRIX_USER_NAME, KNOWN_MATRIX_USER_AVATAR), matrixItem)
}
@Test
fun `when resolve known room for custom domain link, then it returns named custom pill`() {
val subject = createSubject()
val matrixItem = subject.resolveLinkDisplay("text", CUSTOM_DOMAIN_MATRIX_ROOM_URL)
.getMatrixItem()
assertEquals(MatrixItem.RoomItem(KNOWN_MATRIX_ROOM_ID, KNOWN_MATRIX_ROOM_NAME, KNOWN_MATRIX_ROOM_AVATAR), matrixItem)
}
private fun TextDisplay.getMatrixItem(): MatrixItem? {
val customSpan = this as? TextDisplay.Custom
assertNotNull("The URL did not resolve to a custom link display method", customSpan)