BIT-1191: Calculate avatar color when absent (#280)

This commit is contained in:
Brian Yencho
2023-11-27 15:10:54 -06:00
committed by GitHub
parent f3bcab42f3
commit b6999d7b07
4 changed files with 50 additions and 4 deletions

View File

@@ -135,7 +135,8 @@ class UserStateJsonExtensionsTest {
userId = "activeUserId",
name = "activeName",
email = "activeEmail",
avatarColorHex = "activeAvatarColorHex",
// This value is calculated from the userId
avatarColorHex = "#ffecbc49",
isPremium = true,
isVaultUnlocked = false,
),
@@ -149,7 +150,7 @@ class UserStateJsonExtensionsTest {
every { userId } returns "activeUserId"
every { name } returns "activeName"
every { email } returns "activeEmail"
every { avatarColorHex } returns "activeAvatarColorHex"
every { avatarColorHex } returns null
every { hasPremium } returns true
},
tokens = mockk(),

View File

@@ -1,5 +1,6 @@
package com.x8bit.bitwarden.ui.platform.base.util
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
@@ -67,4 +68,22 @@ class StringExtensionsTest {
assertFalse(badUri.isValidUri())
}
}
@Test
fun `toHexColorRepresentation should return valid hex color values`() {
mapOf(
"First" to "#ff90e20b",
"Second" to "#ff943060",
"Multiple words" to "#ffb9d46a",
"1234567890-=!@#$%^&*()_+[]\\;',./{}|:\"<>?" to "#ff171178",
"" to "#ff000000",
" " to "#ff200000",
)
.forEach { (input, colorHexOutput) ->
assertEquals(
colorHexOutput,
input.toHexColorRepresentation(),
)
}
}
}