feat: Notitie editor in the app, dictation routed to system or editor

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-02 09:47:54 +02:00
co-authored by Claude Sonnet 5.5
parent ab7359156b
commit f390d310f4
12 changed files with 433 additions and 34 deletions
+82
View File
@@ -0,0 +1,82 @@
import Foundation
import Testing
@testable import SstData
@MainActor
struct NoteStoreTests {
private func temp() -> URL {
FileManager.default.temporaryDirectory.appending(path: "note-\(UUID().uuidString)/note.txt")
}
@Test func missingFileLoadsEmpty() {
let store = NoteStore(fileURL: temp())
store.load()
#expect(store.text == "")
#expect(!store.isReadOnly)
}
@Test func flushWritesAndAnotherStoreReadsIt() {
let url = temp()
let store = NoteStore(fileURL: url)
store.text = "eerste regel\nté"
store.flush()
let other = NoteStore(fileURL: url)
other.load()
#expect(other.text == "eerste regel\nté")
}
@Test func editsAreSavedAfterTheDebounce() async throws {
let url = temp()
let store = NoteStore(fileURL: url)
store.text = "bewaard"
#expect(!FileManager.default.fileExists(atPath: url.path))
try await Task.sleep(for: .milliseconds(900))
#expect(try String(contentsOf: url, encoding: .utf8) == "bewaard")
}
@Test func loadingDoesNotTriggerASave() async throws {
let url = temp()
try FileManager.default.createDirectory(at: url.deletingLastPathComponent(), withIntermediateDirectories: true)
try "oud".write(to: url, atomically: true, encoding: .utf8)
let store = NoteStore(fileURL: url)
store.load()
#expect(store.text == "oud")
try FileManager.default.removeItem(at: url)
try await Task.sleep(for: .milliseconds(900))
#expect(!FileManager.default.fileExists(atPath: url.path))
}
@Test func unreadableFileIsNeverOverwritten() throws {
let url = temp()
try FileManager.default.createDirectory(at: url.deletingLastPathComponent(), withIntermediateDirectories: true)
try Data([0xFF, 0xFE, 0xFD]).write(to: url)
let store = NoteStore(fileURL: url)
store.load()
#expect(store.isReadOnly)
store.text = "nieuw"
store.flush()
#expect(try Data(contentsOf: url) == Data([0xFF, 0xFE, 0xFD]))
}
}
struct DictationSpacingTests {
@Test func noSpaceAtTheStartOrAfterWhitespace() {
#expect(DictationSpacing.prepared("hallo", characterBefore: nil) == "hallo")
#expect(DictationSpacing.prepared("hallo", characterBefore: " ") == "hallo")
#expect(DictationSpacing.prepared("hallo", characterBefore: "\n") == "hallo")
}
@Test func spaceAfterAWordOrSentenceEnd() {
#expect(DictationSpacing.prepared("hallo", characterBefore: "k") == " hallo")
#expect(DictationSpacing.prepared("Nog een.", characterBefore: ".") == " Nog een.")
}
@Test func noSpaceBeforeClosingPunctuationOrLeadingWhitespace() {
#expect(DictationSpacing.prepared(", dus", characterBefore: "k") == ", dus")
#expect(DictationSpacing.prepared(" dus", characterBefore: "k") == " dus")
}
@Test func emptyTextStaysEmpty() {
#expect(DictationSpacing.prepared("", characterBefore: "k") == "")
}
}