Skip to content

Commit

Permalink
fix: black screen when last caller in a group #WPB-10652 (#3071)
Browse files Browse the repository at this point in the history
* fix: black screen when last caller in a group #WPB-11117

* add tests

* code format
  • Loading branch information
damian-kaczmarek authored Nov 5, 2024
1 parent 1f3c946 commit 8d3105b
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ data class QualifiedID(
@SerialName("domain")
val domain: String
) {
override fun toString(): String = if (domain.isEmpty()) value else "$value$VALUE_DOMAIN_SEPARATOR$domain"
override fun toString(): String =
if (domain.isEmpty()) value else "$value$VALUE_DOMAIN_SEPARATOR$domain"

fun toLogString(): String = if (domain.isEmpty()) {
value.obfuscateId()
Expand All @@ -43,6 +44,16 @@ data class QualifiedID(

fun toPlainID(): PlainId = PlainId(value)

/**
* This checks if the domain in either instances is blank. If it is, it will compare only the value.
* To be used when when of the instance do not have domain due to the API limitations.
*/
fun equalsIgnoringBlankDomain(other: QualifiedID): Boolean {
if (domain.isBlank() || other.domain.isBlank()) {
return value == other.value
}
return this == other
}
}

const val VALUE_DOMAIN_SEPARATOR = '@'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import com.wire.kalium.logic.data.id.QualifiedID
import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue


class QualifiedIdTest {
@Test
fun givenIdsWithoutDomains_whenEqualsIgnoringBlankDomain_thenReturnsTrue() {
// Given
val qualifiedId1 = QualifiedID("id1", "")
val qualifiedId2 = QualifiedID("id1", "")

// When
val result = qualifiedId1.equalsIgnoringBlankDomain(qualifiedId2)

// Then
assertTrue(result)
}

@Test
fun givenOneIdWithoutDomain_whenEqualsIgnoringBlankDomain_thenReturnsTrue() {
// Given
val qualifiedId1 = QualifiedID("id1", "")
val qualifiedId2 = QualifiedID("id1", "domain")

// When
val result = qualifiedId1.equalsIgnoringBlankDomain(qualifiedId2)

// Then
assertTrue(result)
}

@Test
fun givenIdsWithSameDomains_whenEqualsIgnoringBlankDomain_thenReturnsTrue() {
// Given
val qualifiedId1 = QualifiedID("id1", "domain")
val qualifiedId2 = QualifiedID("id1", "domain")

// When
val result = qualifiedId1.equalsIgnoringBlankDomain(qualifiedId2)

// Then
assertTrue(result)
}

@Test
fun givenIdsWithDifferentDomains_whenEqualsIgnoringBlankDomain_thenReturnsFalse() {
// Given
val qualifiedId1 = QualifiedID("id1", "domain1")
val qualifiedId2 = QualifiedID("id1", "domain2")

// When
val result = qualifiedId1.equalsIgnoringBlankDomain(qualifiedId2)

// Then
assertTrue(!result)
}

@Test
fun givenIdsWithDifferentValues_whenEqualsIgnoringBlankDomain_thenReturnsFalse() {
// Given
val qualifiedId1 = QualifiedID("id1", "")
val qualifiedId2 = QualifiedID("id2", "")

// When
val result = qualifiedId1.equalsIgnoringBlankDomain(qualifiedId2)

// Then
assertFalse(result)
}
}

0 comments on commit 8d3105b

Please sign in to comment.