diff --git a/libraries/compound/src/main/kotlin/io/element/android/compound/theme/Theme.kt b/libraries/compound/src/main/kotlin/io/element/android/compound/theme/Theme.kt index c6e9b47eb7..06668e2952 100644 --- a/libraries/compound/src/main/kotlin/io/element/android/compound/theme/Theme.kt +++ b/libraries/compound/src/main/kotlin/io/element/android/compound/theme/Theme.kt @@ -18,8 +18,6 @@ enum class Theme { Light, } -val themes = listOf(Theme.System, Theme.Dark, Theme.Light) - @Composable fun Theme.isDark(): Boolean { return when (this) { diff --git a/libraries/compound/src/test/kotlin/io/element/android/compound/theme/ThemeTest.kt b/libraries/compound/src/test/kotlin/io/element/android/compound/theme/ThemeTest.kt new file mode 100644 index 0000000000..17cb2425dc --- /dev/null +++ b/libraries/compound/src/test/kotlin/io/element/android/compound/theme/ThemeTest.kt @@ -0,0 +1,74 @@ +/* + * Copyright 2025 New Vector Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial + * Please see LICENSE files in the repository root for full details. + */ + +package io.element.android.compound.theme + +import android.content.res.Configuration +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.ui.platform.LocalConfiguration +import app.cash.molecule.RecompositionMode +import app.cash.molecule.moleculeFlow +import app.cash.turbine.test +import com.google.common.truth.Truth.assertThat +import kotlinx.coroutines.test.runTest +import org.junit.Test + +class ThemeTest { + @Test + fun `isDark for System dark returns true`() { + `isDark for System`( + uiMode = Configuration.UI_MODE_NIGHT_YES, + expected = true, + ) + } + + @Test + fun `isDark for System light return false`() { + `isDark for System`( + uiMode = Configuration.UI_MODE_NIGHT_NO, + expected = false, + ) + } + + fun `isDark for System`( + uiMode: Int, + expected: Boolean, + ) = runTest { + moleculeFlow(RecompositionMode.Immediate) { + var result: Boolean? = null + CompositionLocalProvider( + // Let set the system to dark + LocalConfiguration provides Configuration().apply { + this.uiMode = uiMode + }, + ) { + result = Theme.System.isDark() + } + result + }.test { + assertThat(awaitItem()).isEqualTo(expected) + } + } + + @Test + fun `isDark for Light returns false`() = runTest { + moleculeFlow(RecompositionMode.Immediate) { + Theme.Light.isDark() + }.test { + assertThat(awaitItem()).isFalse() + } + } + + @Test + fun `isDark for Dark returns true`() = runTest { + moleculeFlow(RecompositionMode.Immediate) { + Theme.Dark.isDark() + }.test { + assertThat(awaitItem()).isTrue() + } + } +} diff --git a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/Icon.kt b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/Icon.kt index 3867e37c4a..f4487b34fa 100644 --- a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/Icon.kt +++ b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/Icon.kt @@ -8,6 +8,11 @@ package io.element.android.libraries.designsystem.theme.components import androidx.annotation.DrawableRes +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.lazy.grid.GridCells +import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.material3.LocalContentColor import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier @@ -15,9 +20,12 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.vectorResource import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp import io.element.android.compound.tokens.generated.CompoundIcons +import io.element.android.libraries.designsystem.preview.ElementPreview import io.element.android.libraries.designsystem.preview.ElementThemedPreview import io.element.android.libraries.designsystem.preview.PreviewGroup @@ -134,3 +142,24 @@ fun Icon( internal fun IconImageVectorPreview() = ElementThemedPreview { Icon(imageVector = CompoundIcons.Close(), contentDescription = null) } + +@Preview(group = PreviewGroup.Icons) +@Composable +internal fun AllIconsPreview() = ElementPreview { + LazyVerticalGrid( + modifier = Modifier.fillMaxWidth(), + columns = GridCells.Adaptive(32.dp), + contentPadding = PaddingValues(2.dp), + verticalArrangement = Arrangement.spacedBy(2.dp), + horizontalArrangement = Arrangement.spacedBy(2.dp) + ) { + CompoundIcons.allResIds.forEach { icon -> + item { + Icon( + painter = painterResource(icon), + contentDescription = null, + ) + } + } + } +} diff --git a/tests/uitests/src/test/snapshots/images/libraries.designsystem.theme.components_AllIcons_Icons_en.png b/tests/uitests/src/test/snapshots/images/libraries.designsystem.theme.components_AllIcons_Icons_en.png new file mode 100644 index 0000000000..1ca5f1c742 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/libraries.designsystem.theme.components_AllIcons_Icons_en.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c327e27f5b471a9413399818482be76bccd87fd5f2a9c53e312d8900587b069b +size 102657