|
| 1 | +// |
| 2 | +// ThemeDefaultColors.swift |
| 3 | +// Ignite |
| 4 | +// https://www.github.com/twostraws/Ignite |
| 5 | +// See LICENSE for license information. |
| 6 | +// |
| 7 | + |
| 8 | +import Foundation |
| 9 | +import Testing |
| 10 | + |
| 11 | +@testable import Ignite |
| 12 | + |
| 13 | +/// Tests for the default `Theme` colors that rely on `colorScheme` to pick |
| 14 | +/// a light- or dark-mode value. Regression coverage for #854, where the |
| 15 | +/// default `secondary` and `tertiary` colors were rendered as white because |
| 16 | +/// the call sites passed `opacity: 0.75`/`0.5` (a `Double`) instead of |
| 17 | +/// `75%`/`50%` (a `Percentage`), causing Swift to pick the 0-1 RGB `Double` |
| 18 | +/// initializer and scale the integer RGB components by 255. |
| 19 | +@Suite("Default Theme Colors") |
| 20 | +@MainActor |
| 21 | +struct ThemeDefaultColorsTests { |
| 22 | + @Test("Default light theme secondary color stays within valid RGB range") |
| 23 | + func lightSecondaryStaysInRGBRange() { |
| 24 | + let color = DefaultLightTheme().secondary |
| 25 | + #expect(color.red == 33) |
| 26 | + #expect(color.green == 37) |
| 27 | + #expect(color.blue == 41) |
| 28 | + #expect(color.opacity == 75) |
| 29 | + } |
| 30 | + |
| 31 | + @Test("Default dark theme secondary color stays within valid RGB range") |
| 32 | + func darkSecondaryStaysInRGBRange() { |
| 33 | + let color = DefaultDarkTheme().secondary |
| 34 | + #expect(color.red == 222) |
| 35 | + #expect(color.green == 226) |
| 36 | + #expect(color.blue == 230) |
| 37 | + #expect(color.opacity == 75) |
| 38 | + } |
| 39 | + |
| 40 | + @Test("Default light theme tertiary color stays within valid RGB range") |
| 41 | + func lightTertiaryStaysInRGBRange() { |
| 42 | + let color = DefaultLightTheme().tertiary |
| 43 | + #expect(color.red == 33) |
| 44 | + #expect(color.green == 37) |
| 45 | + #expect(color.blue == 41) |
| 46 | + #expect(color.opacity == 50) |
| 47 | + } |
| 48 | + |
| 49 | + @Test("Default dark theme tertiary color stays within valid RGB range") |
| 50 | + func darkTertiaryStaysInRGBRange() { |
| 51 | + let color = DefaultDarkTheme().tertiary |
| 52 | + #expect(color.red == 222) |
| 53 | + #expect(color.green == 226) |
| 54 | + #expect(color.blue == 230) |
| 55 | + #expect(color.opacity == 50) |
| 56 | + } |
| 57 | +} |
0 commit comments