ThemeParityTest.kt
composeApp/src/commonTest/kotlin/eu/friedcutlet/yokan/ui/theme/ThemeParityTest.kt
1package eu.friedcutlet.yokan.ui.theme23import androidx.compose.material3.ColorScheme4import androidx.compose.ui.graphics.Color5import androidx.compose.ui.graphics.toArgb6import kotlin.test.Test7import kotlin.test.assertEquals89class ThemeParityTest {10 @Test11 fun darkModeFollowsSystemOnlyWhenEnabled() {12 assertEquals(true, resolveDarkMode(followSystem = true, themeIsDark = false, systemDark = true))13 assertEquals(false, resolveDarkMode(followSystem = true, themeIsDark = true, systemDark = false))14 assertEquals(true, resolveDarkMode(followSystem = false, themeIsDark = true, systemDark = false))15 assertEquals(false, resolveDarkMode(followSystem = false, themeIsDark = false, systemDark = true))16 }17 @Test18 fun userSurfaceBlendDoesNotChangeFixedOnBlendRoles() {19 val palette = FlexSchemes[50].light20 val blendTen = buildLightScheme(palette, blendLevel = 0.10f)21 val blendTwenty = buildLightScheme(palette, blendLevel = 0.20f)2223 assertEquals(0xFFF3EFE8.toInt(), blendTwenty.surface.toArgb(), "blend 20 surface")24 assertEquals(25 0xFFE4D6C3.toInt(),26 buildLightScaffoldColor(palette, blendLevel = 0.20f).toArgb(),27 "blend 20 scaffold",28 )29 assertEquals(blendTen.onPrimaryContainer, blendTwenty.onPrimaryContainer)30 assertEquals(blendTen.onSecondaryContainer, blendTwenty.onSecondaryContainer)31 assertEquals(blendTen.onTertiaryContainer, blendTwenty.onTertiaryContainer)32 assertEquals(blendTen.onSurface, blendTwenty.onSurface)33 assertEquals(blendTen.onSurfaceVariant, blendTwenty.onSurfaceVariant)34 assertEquals(blendTen.inverseOnSurface, blendTwenty.inverseOnSurface)35 assertEquals(blendTen.outline, blendTwenty.outline)36 assertEquals(blendTen.outlineVariant, blendTwenty.outlineVariant)37 }383940 @Test41 fun brownOrangeLightMatchesMangayomiFlexThemeData() {42 val scheme = buildLightScheme(FlexSchemes[50].light, blendLevel = 0.10f)4344 assertRoleSnapshot(45 mode = "light",46 scheme = scheme,47 expected = mapOf(48 "primary" to 0xFF8B5000,49 "onPrimary" to 0xFFFFFFFF,50 "primaryContainer" to 0xFFFFDCBE,51 "onPrimaryContainer" to 0xFF141310,52 "secondary" to 0xFFB6602F,53 "onSecondary" to 0xFFFFFFFF,54 "secondaryContainer" to 0xFFFFEDE6,55 "onSecondaryContainer" to 0xFF141414,56 "tertiary" to 0xFF466827,57 "onTertiary" to 0xFFFFFFFF,58 "tertiaryContainer" to 0xFFC6EF9F,59 "onTertiaryContainer" to 0xFF11140E,60 "surface" to 0xFFF8F5F2,61 "background" to 0xFFF8F5F2,62 "onBackground" to 0xFF1A1611,63 "onSurface" to 0xFF1A1611,64 "onSurfaceVariant" to 0xFF413D37,65 "surfaceDim" to 0xFFDDDAD7,66 "surfaceBright" to 0xFFF9F6F3,67 "surfaceContainerLowest" to 0xFFFAF8F5,68 "surfaceContainerLow" to 0xFFF4F1EE,69 "surfaceContainer" to 0xFFEFEDE9,70 "surfaceContainerHigh" to 0xFFE9E7E4,71 "surfaceContainerHighest" to 0xFFE3E1DE,72 "inverseSurface" to 0xFF2E2B28,73 "inverseOnSurface" to 0xFFF2EDE8,74 "inversePrimary" to 0xFFF5CC95,75 "outline" to 0xFF918E8B,76 "outlineVariant" to 0xFFCECCC9,77 "primaryFixed" to 0xFFEFDBBF,78 "primaryFixedDim" to 0xFFDDBB8C,79 "onPrimaryFixed" to 0xFF1D1100,80 "onPrimaryFixedVariant" to 0xFF301B00,81 "secondaryFixed" to 0xFFF2DCCE,82 "secondaryFixedDim" to 0xFFE3BAA3,83 "onSecondaryFixed" to 0xFF4A2713,84 "onSecondaryFixedVariant" to 0xFF572E16,85 "tertiaryFixed" to 0xFFD7E3CD,86 "tertiaryFixedDim" to 0xFFB4C8A2,87 "onTertiaryFixed" to 0xFF101809,88 "onTertiaryFixedVariant" to 0xFF19240E,89 ),90 )91 assertEquals(92 0xFFF1EAE1.toInt(),93 buildLightScaffoldColor(FlexSchemes[50].light, blendLevel = 0.10f).toArgb(),94 "light scaffold",95 )96 }9798 @Test99 fun brownOrangeDarkMatchesMangayomiFlexThemeData() {100 val flex = FlexSchemes[50]101 val scheme = buildDarkScheme(102 palette = flex.dark,103 lightReference = flex.light,104 blendLevel = 0.10f,105 )106107 assertRoleSnapshot(108 mode = "dark",109 scheme = scheme,110 expected = mapOf(111 "primary" to 0xFFFFB871,112 "onPrimary" to 0xFF000000,113 "primaryContainer" to 0xFF6A3C00,114 "onPrimaryContainer" to 0xFFF8F4EF,115 "secondary" to 0xFFFFDBCB,116 "onSecondary" to 0xFF000000,117 "secondaryContainer" to 0xFF552000,118 "onSecondaryContainer" to 0xFFF6F2EF,119 "tertiary" to 0xFFABD285,120 "onTertiary" to 0xFF000000,121 "tertiaryContainer" to 0xFF2F4F11,122 "onTertiaryContainer" to 0xFFF3F6F1,123 "surface" to 0xFF120F0C,124 "background" to 0xFF120F0C,125 "onBackground" to 0xFFF2EEEA,126 "onSurface" to 0xFFF2EEEA,127 "onSurfaceVariant" to 0xFFCCC8C5,128 "surfaceDim" to 0xFF100D0A,129 "surfaceBright" to 0xFF34312F,130 "surfaceContainerLowest" to 0xFF0B0805,131 "surfaceContainerLow" to 0xFF171512,132 "surfaceContainer" to 0xFF1E1B19,133 "surfaceContainerHigh" to 0xFF262320,134 "surfaceContainerHighest" to 0xFF302E2B,135 "inverseSurface" to 0xFFE9E6E3,136 "inverseOnSurface" to 0xFF322F2B,137 "inversePrimary" to 0xFF71583A,138 "outline" to 0xFF7C7A77,139 "outlineVariant" to 0xFF484643,140 "primaryFixed" to 0xFFEFDBBF,141 "primaryFixedDim" to 0xFFDDBB8C,142 "onPrimaryFixed" to 0xFF1D1100,143 "onPrimaryFixedVariant" to 0xFF301B00,144 "secondaryFixed" to 0xFFF2DCCE,145 "secondaryFixedDim" to 0xFFE3BAA3,146 "onSecondaryFixed" to 0xFF4A2713,147 "onSecondaryFixedVariant" to 0xFF572E16,148 "tertiaryFixed" to 0xFFD7E3CD,149 "tertiaryFixedDim" to 0xFFB4C8A2,150 "onTertiaryFixed" to 0xFF101809,151 "onTertiaryFixedVariant" to 0xFF19240E,152 ),153 )154 assertEquals(155 0xFF0B0805.toInt(),156 buildDarkScaffoldColor(FlexSchemes[50].dark, blendLevel = 0.10f, pureBlack = false).toArgb(),157 "dark scaffold",158 )159 }160 @Test161 fun pureBlackOnlyChangesMangayomiScaffold() {162 val palette = FlexSchemes[50].dark163164 assertEquals(165 0xFF0B0805.toInt(),166 buildDarkScaffoldColor(palette, blendLevel = 0.10f, pureBlack = false).toArgb(),167 "normal scaffold",168 )169 assertEquals(170 Color.Black.toArgb(),171 buildDarkScaffoldColor(palette, blendLevel = 0.10f, pureBlack = true).toArgb(),172 "pure black scaffold",173 )174 }175176177 private fun assertRoleSnapshot(178 mode: String,179 scheme: ColorScheme,180 expected: Map<String, Long>,181 ) {182 val actual = mapOf(183 "primary" to scheme.primary,184 "onPrimary" to scheme.onPrimary,185 "primaryContainer" to scheme.primaryContainer,186 "onPrimaryContainer" to scheme.onPrimaryContainer,187 "secondary" to scheme.secondary,188 "onSecondary" to scheme.onSecondary,189 "secondaryContainer" to scheme.secondaryContainer,190 "onSecondaryContainer" to scheme.onSecondaryContainer,191 "tertiary" to scheme.tertiary,192 "onTertiary" to scheme.onTertiary,193 "tertiaryContainer" to scheme.tertiaryContainer,194 "onTertiaryContainer" to scheme.onTertiaryContainer,195 "surface" to scheme.surface,196 "background" to scheme.background,197 "onBackground" to scheme.onBackground,198 "onSurface" to scheme.onSurface,199 "onSurfaceVariant" to scheme.onSurfaceVariant,200 "surfaceDim" to scheme.surfaceDim,201 "surfaceBright" to scheme.surfaceBright,202 "surfaceContainerLowest" to scheme.surfaceContainerLowest,203 "surfaceContainerLow" to scheme.surfaceContainerLow,204 "surfaceContainer" to scheme.surfaceContainer,205 "surfaceContainerHigh" to scheme.surfaceContainerHigh,206 "surfaceContainerHighest" to scheme.surfaceContainerHighest,207 "inverseSurface" to scheme.inverseSurface,208 "inverseOnSurface" to scheme.inverseOnSurface,209 "inversePrimary" to scheme.inversePrimary,210 "outline" to scheme.outline,211 "outlineVariant" to scheme.outlineVariant,212 "primaryFixed" to scheme.primaryFixed,213 "primaryFixedDim" to scheme.primaryFixedDim,214 "onPrimaryFixed" to scheme.onPrimaryFixed,215 "onPrimaryFixedVariant" to scheme.onPrimaryFixedVariant,216 "secondaryFixed" to scheme.secondaryFixed,217 "secondaryFixedDim" to scheme.secondaryFixedDim,218 "onSecondaryFixed" to scheme.onSecondaryFixed,219 "onSecondaryFixedVariant" to scheme.onSecondaryFixedVariant,220 "tertiaryFixed" to scheme.tertiaryFixed,221 "tertiaryFixedDim" to scheme.tertiaryFixedDim,222 "onTertiaryFixed" to scheme.onTertiaryFixed,223 "onTertiaryFixedVariant" to scheme.onTertiaryFixedVariant,224 )225226 assertEquals(expected.keys, actual.keys, "$mode role names")227 expected.forEach { (role, expectedArgb) ->228 val actualColor: Color = actual.getValue(role)229 assertEquals(expectedArgb.toInt(), actualColor.toArgb(), "$mode $role")230 }231 }232}233