import XCTest
@testable import CommandNotch

final class AppSettingsStoreTests: XCTestCase {
    func testLoadReturnsDefaultValuesWhenStoreIsEmpty() {
        let defaults = UserDefaults(suiteName: #function)!
        defaults.removePersistentDomain(forName: #function)
        defer { defaults.removePersistentDomain(forName: #function) }

        let store = UserDefaultsAppSettingsStore(defaults: defaults)

        XCTAssertEqual(store.load(), .default)
    }

    func testSaveRoundTripsSettings() {
        let defaults = UserDefaults(suiteName: #function)!
        defaults.removePersistentDomain(forName: #function)
        defer { defaults.removePersistentDomain(forName: #function) }

        let store = UserDefaultsAppSettingsStore(defaults: defaults)
        var settings = AppSettings.default
        settings.display.showMenuBarIcon = false
        settings.display.showOnAllDisplays = false
        settings.display.openWidth = 900
        settings.behavior.minimumHoverDuration = 0.65
        settings.appearance.blurRadius = 4.5
        settings.terminal.fontSize = 16
        settings.terminal.themeRawValue = TerminalTheme.dracula.rawValue
        settings.terminal.sizePresetsJSON = TerminalSizePresetStore.encodePresets([
            TerminalSizePreset(name: "Wide", width: 960, height: 420, hotkey: .cmdShiftDigit(4))
        ])
        settings.hotkeys.toggle = .cmdD

        store.save(settings)

        XCTAssertEqual(store.load(), settings)
    }
}
