import SwiftUI import Testing @testable import HUDKit // The scheme an account chose, as Grain's preferences answer it: light or // dark forced, system or none the device's. @Suite struct SchemeChoosing { private static let at = "preferences.@themePref.theme" private static func answer(_ theme: JSON?) -> JSON { var prefs: [JSON] = [["$type": "social.grain.actor.defs#photoMetadataPref", "includeExif": true]] if let theme { prefs.append(["$type": "social.grain.actor.defs#themePref", "theme": theme]) } return ["preferences": .array(prefs)] } @Test func lightOrDarkIsForcedAndTheRestIsTheDevices() { #expect(SchemeChoice.scheme(in: Self.answer("dark"), at: Self.at) == .dark) #expect(SchemeChoice.scheme(in: Self.answer("light"), at: Self.at) == .light) #expect(SchemeChoice.scheme(in: Self.answer("system"), at: Self.at) == nil) #expect(SchemeChoice.scheme(in: Self.answer(nil), at: Self.at) == nil) #expect(SchemeChoice.scheme(in: Self.answer(5), at: Self.at) == nil) #expect(SchemeChoice.scheme(in: nil, at: Self.at) == nil) // A type named whole, and a plain path. #expect(SchemeChoice.scheme(in: ["prefs": [["$type": "themePref", "theme": "dark"]]], at: "prefs.@themePref.theme") == .dark) #expect(SchemeChoice.scheme(in: ["theme": "light"], at: "theme") == .light) } }