package eu.friedcutlet.yokan.ui.theme import androidx.compose.material3.ColorScheme import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.toArgb import kotlin.test.Test import kotlin.test.assertEquals class ThemeParityTest { @Test fun darkModeFollowsSystemOnlyWhenEnabled() { assertEquals(true, resolveDarkMode(followSystem = true, themeIsDark = false, systemDark = true)) assertEquals(false, resolveDarkMode(followSystem = true, themeIsDark = true, systemDark = false)) assertEquals(true, resolveDarkMode(followSystem = false, themeIsDark = true, systemDark = false)) assertEquals(false, resolveDarkMode(followSystem = false, themeIsDark = false, systemDark = true)) } @Test fun userSurfaceBlendDoesNotChangeFixedOnBlendRoles() { val palette = FlexSchemes[50].light val blendTen = buildLightScheme(palette, blendLevel = 0.10f) val blendTwenty = buildLightScheme(palette, blendLevel = 0.20f) assertEquals(0xFFF3EFE8.toInt(), blendTwenty.surface.toArgb(), "blend 20 surface") assertEquals( 0xFFE4D6C3.toInt(), buildLightScaffoldColor(palette, blendLevel = 0.20f).toArgb(), "blend 20 scaffold", ) assertEquals(blendTen.onPrimaryContainer, blendTwenty.onPrimaryContainer) assertEquals(blendTen.onSecondaryContainer, blendTwenty.onSecondaryContainer) assertEquals(blendTen.onTertiaryContainer, blendTwenty.onTertiaryContainer) assertEquals(blendTen.onSurface, blendTwenty.onSurface) assertEquals(blendTen.onSurfaceVariant, blendTwenty.onSurfaceVariant) assertEquals(blendTen.inverseOnSurface, blendTwenty.inverseOnSurface) assertEquals(blendTen.outline, blendTwenty.outline) assertEquals(blendTen.outlineVariant, blendTwenty.outlineVariant) } @Test fun brownOrangeLightMatchesMangayomiFlexThemeData() { val scheme = buildLightScheme(FlexSchemes[50].light, blendLevel = 0.10f) assertRoleSnapshot( mode = "light", scheme = scheme, expected = mapOf( "primary" to 0xFF8B5000, "onPrimary" to 0xFFFFFFFF, "primaryContainer" to 0xFFFFDCBE, "onPrimaryContainer" to 0xFF141310, "secondary" to 0xFFB6602F, "onSecondary" to 0xFFFFFFFF, "secondaryContainer" to 0xFFFFEDE6, "onSecondaryContainer" to 0xFF141414, "tertiary" to 0xFF466827, "onTertiary" to 0xFFFFFFFF, "tertiaryContainer" to 0xFFC6EF9F, "onTertiaryContainer" to 0xFF11140E, "surface" to 0xFFF8F5F2, "background" to 0xFFF8F5F2, "onBackground" to 0xFF1A1611, "onSurface" to 0xFF1A1611, "onSurfaceVariant" to 0xFF413D37, "surfaceDim" to 0xFFDDDAD7, "surfaceBright" to 0xFFF9F6F3, "surfaceContainerLowest" to 0xFFFAF8F5, "surfaceContainerLow" to 0xFFF4F1EE, "surfaceContainer" to 0xFFEFEDE9, "surfaceContainerHigh" to 0xFFE9E7E4, "surfaceContainerHighest" to 0xFFE3E1DE, "inverseSurface" to 0xFF2E2B28, "inverseOnSurface" to 0xFFF2EDE8, "inversePrimary" to 0xFFF5CC95, "outline" to 0xFF918E8B, "outlineVariant" to 0xFFCECCC9, "primaryFixed" to 0xFFEFDBBF, "primaryFixedDim" to 0xFFDDBB8C, "onPrimaryFixed" to 0xFF1D1100, "onPrimaryFixedVariant" to 0xFF301B00, "secondaryFixed" to 0xFFF2DCCE, "secondaryFixedDim" to 0xFFE3BAA3, "onSecondaryFixed" to 0xFF4A2713, "onSecondaryFixedVariant" to 0xFF572E16, "tertiaryFixed" to 0xFFD7E3CD, "tertiaryFixedDim" to 0xFFB4C8A2, "onTertiaryFixed" to 0xFF101809, "onTertiaryFixedVariant" to 0xFF19240E, ), ) assertEquals( 0xFFF1EAE1.toInt(), buildLightScaffoldColor(FlexSchemes[50].light, blendLevel = 0.10f).toArgb(), "light scaffold", ) } @Test fun brownOrangeDarkMatchesMangayomiFlexThemeData() { val flex = FlexSchemes[50] val scheme = buildDarkScheme( palette = flex.dark, lightReference = flex.light, blendLevel = 0.10f, ) assertRoleSnapshot( mode = "dark", scheme = scheme, expected = mapOf( "primary" to 0xFFFFB871, "onPrimary" to 0xFF000000, "primaryContainer" to 0xFF6A3C00, "onPrimaryContainer" to 0xFFF8F4EF, "secondary" to 0xFFFFDBCB, "onSecondary" to 0xFF000000, "secondaryContainer" to 0xFF552000, "onSecondaryContainer" to 0xFFF6F2EF, "tertiary" to 0xFFABD285, "onTertiary" to 0xFF000000, "tertiaryContainer" to 0xFF2F4F11, "onTertiaryContainer" to 0xFFF3F6F1, "surface" to 0xFF120F0C, "background" to 0xFF120F0C, "onBackground" to 0xFFF2EEEA, "onSurface" to 0xFFF2EEEA, "onSurfaceVariant" to 0xFFCCC8C5, "surfaceDim" to 0xFF100D0A, "surfaceBright" to 0xFF34312F, "surfaceContainerLowest" to 0xFF0B0805, "surfaceContainerLow" to 0xFF171512, "surfaceContainer" to 0xFF1E1B19, "surfaceContainerHigh" to 0xFF262320, "surfaceContainerHighest" to 0xFF302E2B, "inverseSurface" to 0xFFE9E6E3, "inverseOnSurface" to 0xFF322F2B, "inversePrimary" to 0xFF71583A, "outline" to 0xFF7C7A77, "outlineVariant" to 0xFF484643, "primaryFixed" to 0xFFEFDBBF, "primaryFixedDim" to 0xFFDDBB8C, "onPrimaryFixed" to 0xFF1D1100, "onPrimaryFixedVariant" to 0xFF301B00, "secondaryFixed" to 0xFFF2DCCE, "secondaryFixedDim" to 0xFFE3BAA3, "onSecondaryFixed" to 0xFF4A2713, "onSecondaryFixedVariant" to 0xFF572E16, "tertiaryFixed" to 0xFFD7E3CD, "tertiaryFixedDim" to 0xFFB4C8A2, "onTertiaryFixed" to 0xFF101809, "onTertiaryFixedVariant" to 0xFF19240E, ), ) assertEquals( 0xFF0B0805.toInt(), buildDarkScaffoldColor(FlexSchemes[50].dark, blendLevel = 0.10f, pureBlack = false).toArgb(), "dark scaffold", ) } @Test fun pureBlackOnlyChangesMangayomiScaffold() { val palette = FlexSchemes[50].dark assertEquals( 0xFF0B0805.toInt(), buildDarkScaffoldColor(palette, blendLevel = 0.10f, pureBlack = false).toArgb(), "normal scaffold", ) assertEquals( Color.Black.toArgb(), buildDarkScaffoldColor(palette, blendLevel = 0.10f, pureBlack = true).toArgb(), "pure black scaffold", ) } private fun assertRoleSnapshot( mode: String, scheme: ColorScheme, expected: Map, ) { val actual = mapOf( "primary" to scheme.primary, "onPrimary" to scheme.onPrimary, "primaryContainer" to scheme.primaryContainer, "onPrimaryContainer" to scheme.onPrimaryContainer, "secondary" to scheme.secondary, "onSecondary" to scheme.onSecondary, "secondaryContainer" to scheme.secondaryContainer, "onSecondaryContainer" to scheme.onSecondaryContainer, "tertiary" to scheme.tertiary, "onTertiary" to scheme.onTertiary, "tertiaryContainer" to scheme.tertiaryContainer, "onTertiaryContainer" to scheme.onTertiaryContainer, "surface" to scheme.surface, "background" to scheme.background, "onBackground" to scheme.onBackground, "onSurface" to scheme.onSurface, "onSurfaceVariant" to scheme.onSurfaceVariant, "surfaceDim" to scheme.surfaceDim, "surfaceBright" to scheme.surfaceBright, "surfaceContainerLowest" to scheme.surfaceContainerLowest, "surfaceContainerLow" to scheme.surfaceContainerLow, "surfaceContainer" to scheme.surfaceContainer, "surfaceContainerHigh" to scheme.surfaceContainerHigh, "surfaceContainerHighest" to scheme.surfaceContainerHighest, "inverseSurface" to scheme.inverseSurface, "inverseOnSurface" to scheme.inverseOnSurface, "inversePrimary" to scheme.inversePrimary, "outline" to scheme.outline, "outlineVariant" to scheme.outlineVariant, "primaryFixed" to scheme.primaryFixed, "primaryFixedDim" to scheme.primaryFixedDim, "onPrimaryFixed" to scheme.onPrimaryFixed, "onPrimaryFixedVariant" to scheme.onPrimaryFixedVariant, "secondaryFixed" to scheme.secondaryFixed, "secondaryFixedDim" to scheme.secondaryFixedDim, "onSecondaryFixed" to scheme.onSecondaryFixed, "onSecondaryFixedVariant" to scheme.onSecondaryFixedVariant, "tertiaryFixed" to scheme.tertiaryFixed, "tertiaryFixedDim" to scheme.tertiaryFixedDim, "onTertiaryFixed" to scheme.onTertiaryFixed, "onTertiaryFixedVariant" to scheme.onTertiaryFixedVariant, ) assertEquals(expected.keys, actual.keys, "$mode role names") expected.forEach { (role, expectedArgb) -> val actualColor: Color = actual.getValue(role) assertEquals(expectedArgb.toInt(), actualColor.toArgb(), "$mode $role") } } }