before the great git rework
This commit is contained in:
@@ -1,99 +0,0 @@
|
||||
import HelderUI
|
||||
import Testing
|
||||
|
||||
@MainActor
|
||||
@Suite struct NoteStoreTests {
|
||||
@Test func loadsTheNoteThatIsAlreadyOnDisk() async {
|
||||
let store = NoteStore(notes: FakeNotes("earlier thoughts\n"))
|
||||
await store.load()
|
||||
#expect(store.text == "earlier thoughts\n")
|
||||
#expect(!store.isDirty)
|
||||
}
|
||||
|
||||
@Test func nothingIsWrittenWhileTyping() async {
|
||||
let notes = FakeNotes()
|
||||
let store = NoteStore(notes: notes)
|
||||
await store.load()
|
||||
store.text = "buy milk"
|
||||
#expect(notes.writes.isEmpty)
|
||||
#expect(store.isDirty)
|
||||
}
|
||||
|
||||
@Test func savingOnFocusLossWritesTheEditedText() async {
|
||||
let notes = FakeNotes()
|
||||
let store = NoteStore(notes: notes)
|
||||
await store.load()
|
||||
store.text = "buy milk"
|
||||
await store.save()
|
||||
#expect(notes.writes == ["buy milk"])
|
||||
#expect(notes.onDisk == "buy milk")
|
||||
#expect(!store.isDirty)
|
||||
}
|
||||
|
||||
@Test func anUnchangedNoteIsNeverRewritten() async {
|
||||
let notes = FakeNotes("unchanged")
|
||||
let store = NoteStore(notes: notes)
|
||||
await store.load()
|
||||
await store.save()
|
||||
await store.save()
|
||||
#expect(notes.writes.isEmpty)
|
||||
}
|
||||
|
||||
@Test func aFailedWriteLeavesTheNoteDirtyForTheNextTry() async {
|
||||
let notes = FakeNotes()
|
||||
notes.failWrites = true
|
||||
let store = NoteStore(notes: notes)
|
||||
store.text = "keep me"
|
||||
await store.save()
|
||||
#expect(store.isDirty)
|
||||
}
|
||||
|
||||
@Test func passableTextIsTheTrimmedNote() {
|
||||
let store = NoteStore(notes: FakeNotes())
|
||||
store.text = " refactor the policy\n\n"
|
||||
#expect(store.passableText == "refactor the policy")
|
||||
}
|
||||
|
||||
@Test func anEmptyNoteHasNothingToPass() {
|
||||
let store = NoteStore(notes: FakeNotes())
|
||||
store.text = " \n "
|
||||
#expect(store.passableText == nil)
|
||||
}
|
||||
|
||||
@Test func aFailedWriteRaisesAToast() async {
|
||||
let notes = FakeNotes()
|
||||
notes.failWrites = true
|
||||
let store = NoteStore(notes: notes)
|
||||
var toasts: [String?] = []
|
||||
store.notify = { title, detail in toasts.append(title + " " + (detail ?? "")) }
|
||||
store.text = "keep me"
|
||||
#expect(await store.save() == false)
|
||||
#expect(toasts == ["Save failed .notes.txt"])
|
||||
}
|
||||
|
||||
@Test func anOutsideEditReplacesACleanNote() async {
|
||||
let notes = FakeNotes("old")
|
||||
let store = NoteStore(notes: notes)
|
||||
await store.load()
|
||||
notes.setOnDisk("new from the agent")
|
||||
await store.reloadIfClean()
|
||||
#expect(store.text == "new from the agent")
|
||||
#expect(!store.isDirty)
|
||||
}
|
||||
|
||||
@Test func anOutsideEditNeverReplacesUnsavedTyping() async {
|
||||
let notes = FakeNotes("old")
|
||||
let store = NoteStore(notes: notes)
|
||||
await store.load()
|
||||
store.text = "typing"
|
||||
notes.setOnDisk("new from the agent")
|
||||
await store.reloadIfClean()
|
||||
#expect(store.text == "typing")
|
||||
}
|
||||
|
||||
@Test func theFooterCountsCharacters() {
|
||||
let store = NoteStore(notes: FakeNotes())
|
||||
store.text = "héllo"
|
||||
#expect(store.characterCount == 5)
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import Testing
|
||||
|
||||
@Test func everyShortcutTheAppHandlesIsListed() {
|
||||
let listed = Set(ShortcutCatalog.groups.flatMap(\.rows).map { $0.keys.joined() })
|
||||
let handled = ["⌘F", "⌘↑↓", "↵", "⌘←→", "↑↓", "⇧⌘O", "⌘O", "⌘→", "⌘N", "⌘P",
|
||||
let handled = ["⌘F", "⌘↑↓", "↵", "⌘←→", "↑↓", "⇧⌘O", "⌘O", "⌘→", "⌘P",
|
||||
"⌘C", "⌘↵", "⌘G", "⌘M", "⌘S", "⌘.", "⌘A", "⌘L", "Esc",
|
||||
"⌘W", "⌘R", "⇧⌘N", "?", "⌘click", "⌘0", "⌘+", "⌘−"]
|
||||
#expect(Set(handled).subtracting(listed).isEmpty)
|
||||
@@ -35,11 +35,6 @@ import Testing
|
||||
#expect(!row.label.isEmpty)
|
||||
}
|
||||
}
|
||||
|
||||
@Test func theNotePassOnSitsInTheAgentGroup() {
|
||||
let agent = ShortcutCatalog.groups.first { $0.title == "Agent" }
|
||||
#expect(agent?.rows.contains(ShortcutRow(keys: ["⌘", "P"], label: "Pass on the whole note")) == true)
|
||||
}
|
||||
}
|
||||
|
||||
@Suite struct ListCursorTests {
|
||||
|
||||
@@ -7,7 +7,7 @@ import Testing
|
||||
private func route(_ press: KeyPress, _ context: KeyContext = KeyContext()) -> KeyRoute { KeyRouter.route(press, context) }
|
||||
|
||||
@Test(arguments: [
|
||||
("n", Command.showNote), ("p", .push), ("s", .save), ("m", .cycleMode), ("g", .toggleGit),
|
||||
("p", Command.push), ("s", .save), ("m", .cycleMode), ("g", .toggleGit),
|
||||
("l", .toggleAutoFit), (".", .toggleHidden), ("w", .closeFileOrWindow),
|
||||
])
|
||||
func commandLettersMapToTheirCommand(key: String, command: Command) {
|
||||
@@ -89,7 +89,7 @@ import Testing
|
||||
|
||||
@Test func escapeClosesAnOverlayAndOtherwiseReachesTheTerminal() {
|
||||
#expect(route(KeyPress(.escape), KeyContext(overlay: .other)) == .perform(.dismissOverlay))
|
||||
#expect(route(KeyPress(.escape), KeyContext(overlay: .note, owner: .text(in: nil))) == .perform(.dismissOverlay))
|
||||
#expect(route(KeyPress(.escape), KeyContext(overlay: .other, owner: .text(in: nil))) == .perform(.dismissOverlay))
|
||||
#expect(route(KeyPress(.escape), KeyContext(owner: .terminal)) == .pass)
|
||||
}
|
||||
|
||||
@@ -100,9 +100,8 @@ import Testing
|
||||
#expect(route(KeyPress(.right, command: true), search) == .pass)
|
||||
}
|
||||
|
||||
@Test func commandPPassesTheNoteWhileItIsOpen() {
|
||||
#expect(route(cmd("p"), KeyContext(overlay: .note)) == .perform(.passNote))
|
||||
#expect(route(cmd("g"), KeyContext(overlay: .note)) == .pass)
|
||||
@Test func commandNIsLeftUnbound() {
|
||||
#expect(route(cmd("n")) == .pass)
|
||||
}
|
||||
|
||||
@Test func theBareLauncherTakesArrowsAndEnter() {
|
||||
|
||||
@@ -92,10 +92,10 @@ import Testing
|
||||
|
||||
@Test func textWaitsForAnotherOverlayAndOnlyTheLatestShows() async {
|
||||
let harness = await started()
|
||||
await harness.perform(.showNote)
|
||||
await harness.perform(.showShortcuts)
|
||||
await agentWrites("one", harness)
|
||||
await agentWrites("two", harness)
|
||||
#expect(harness.model.overlay.current == .note)
|
||||
#expect(harness.model.overlay.current == .shortcuts)
|
||||
await harness.perform(.dismissOverlay)
|
||||
#expect(await eventually { harness.model.overlay.current == .cleanCopy })
|
||||
#expect(harness.model.cleanCopy?.text == "two")
|
||||
|
||||
@@ -6,8 +6,8 @@ import Testing
|
||||
@Test func overlaysNeverStack() {
|
||||
let store = OverlayStore()
|
||||
store.present(.search(seed: "foo"))
|
||||
store.present(.note)
|
||||
#expect(store.current == .note)
|
||||
store.present(.launcher)
|
||||
#expect(store.current == .launcher)
|
||||
store.dismiss()
|
||||
#expect(store.current == .none)
|
||||
#expect(!store.isPresented)
|
||||
@@ -17,11 +17,11 @@ import Testing
|
||||
let store = OverlayStore()
|
||||
var changes: [(Overlay, Overlay)] = []
|
||||
store.onChange = { changes.append(($0, $1)) }
|
||||
store.present(.note)
|
||||
store.present(.note)
|
||||
store.present(.launcher)
|
||||
store.present(.launcher)
|
||||
store.present(.shortcuts)
|
||||
store.dismiss()
|
||||
#expect(changes.map(\.0) == [.none, .note, .shortcuts])
|
||||
#expect(changes.map(\.1) == [.note, .shortcuts, .none])
|
||||
#expect(changes.map(\.0) == [.none, .launcher, .shortcuts])
|
||||
#expect(changes.map(\.1) == [.launcher, .shortcuts, .none])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,10 +27,8 @@ import Testing
|
||||
@Test func savingFromTheCloseQuestionWritesBeforeTheWindowGoes() async {
|
||||
let harness = await dirtyHarness()
|
||||
harness.system.unsavedCloseChoice = .save
|
||||
harness.model.note?.text = "thought"
|
||||
#expect(await harness.model.prepareToClose())
|
||||
#expect(harness.files.current("a.php") == "<?php // unsaved")
|
||||
#expect(harness.notes.writes == ["thought"])
|
||||
#expect(harness.session.sessions["/fake/project"]?.active == "a.php")
|
||||
}
|
||||
|
||||
@@ -68,25 +66,6 @@ import Testing
|
||||
#expect(harness.model.editor !== oldEditor)
|
||||
#expect(harness.model.editor?.states["a.php"] == nil)
|
||||
}
|
||||
|
||||
@Test func aFailedNoteSaveSaysSo() async {
|
||||
let harness = WorkspaceHarness()
|
||||
await harness.start()
|
||||
harness.notes.failWrites = true
|
||||
harness.model.note?.text = "keep me"
|
||||
harness.model.windowDidResignKey()
|
||||
await harness.model.settle()
|
||||
#expect(harness.toastTitles.contains("Save failed"))
|
||||
}
|
||||
|
||||
@Test func anOutsideEditOfTheNoteIsPickedUp() async {
|
||||
let harness = WorkspaceHarness(note: "before")
|
||||
await harness.start()
|
||||
harness.notes.setOnDisk("written by the agent")
|
||||
await harness.model.handle(.project)
|
||||
await harness.model.settle()
|
||||
#expect(harness.model.note?.text == "written by the agent")
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
|
||||
@@ -8,7 +8,7 @@ import Testing
|
||||
@MainActor
|
||||
@Suite struct WorkspaceModelLifecycleTests {
|
||||
@Test func startingAProjectLoadsEverythingOnceAndWatchesIt() async {
|
||||
let harness = WorkspaceHarness(note: "remember this", git: snapshot([("a.php", .modified, false)]))
|
||||
let harness = WorkspaceHarness(git: snapshot([("a.php", .modified, false)]))
|
||||
await harness.start()
|
||||
#expect(harness.model.isReady)
|
||||
#expect(harness.config.resolves == 1)
|
||||
@@ -16,7 +16,6 @@ import Testing
|
||||
#expect(harness.files.treeLoads == 1)
|
||||
#expect(harness.model.sourceControl?.state.changes.map(\.path) == ["a.php"])
|
||||
#expect(harness.model.explorer?.tree != nil)
|
||||
#expect(harness.model.note?.text == "remember this")
|
||||
#expect(harness.watchers.last?.root == harness.root)
|
||||
#expect(harness.recents.projects.first?.path == harness.root.path)
|
||||
#expect(harness.model.sourceControl?.isPolling == true)
|
||||
@@ -96,17 +95,15 @@ import Testing
|
||||
}
|
||||
|
||||
@Test func switchingProjectsEndsTheOldProjectCleanly() async {
|
||||
let harness = WorkspaceHarness(note: "old", contents: ["a.php": "<?php"])
|
||||
let harness = WorkspaceHarness(contents: ["a.php": "<?php"])
|
||||
await harness.start()
|
||||
harness.model.open("a.php")
|
||||
await harness.model.settle()
|
||||
harness.model.note?.text = "unsaved thought"
|
||||
let firstWatcher = harness.watchers.last
|
||||
await harness.model.openProject(URL(fileURLWithPath: "/fake/other"))
|
||||
#expect(firstWatcher?.stopped == true)
|
||||
#expect(harness.watchers.made.count == 2)
|
||||
#expect(harness.agent.terminations == 1)
|
||||
#expect(harness.notes.writes == ["unsaved thought"])
|
||||
#expect(harness.session.sessions["/fake/project"]?.active == "a.php")
|
||||
}
|
||||
|
||||
@@ -370,17 +367,6 @@ import Testing
|
||||
#expect(harness.git.commits.isEmpty)
|
||||
}
|
||||
|
||||
@Test func commandPPassesTheWholeNoteAndClosesIt() async {
|
||||
let harness = WorkspaceHarness(note: " fix the tests ")
|
||||
await harness.start()
|
||||
harness.model.perform(.showNote)
|
||||
await harness.perform(.passNote)
|
||||
#expect(harness.agent.sent == [BracketedPaste.wrap("fix the tests", composerHasText: false)])
|
||||
#expect(harness.model.overlay.current == .none)
|
||||
#expect(harness.git.pushes == 0)
|
||||
#expect(harness.toastTitles == ["Note passed to agent"])
|
||||
}
|
||||
|
||||
@Test func thePassOnPromptInsertsIntoTheAgent() async {
|
||||
let harness = WorkspaceHarness()
|
||||
await harness.start()
|
||||
@@ -550,8 +536,8 @@ import Testing
|
||||
@Test func escClosesOnlyTheOneOpenOverlay() {
|
||||
let harness = WorkspaceHarness()
|
||||
harness.model.perform(.showShortcuts)
|
||||
harness.model.perform(.showNote)
|
||||
#expect(harness.model.overlay.current == .note)
|
||||
harness.model.perform(.showSearch(seed: "x"))
|
||||
#expect(harness.model.overlay.current == .search(seed: "x"))
|
||||
harness.model.perform(.dismissOverlay)
|
||||
#expect(harness.model.overlay.current == .none)
|
||||
}
|
||||
@@ -563,15 +549,6 @@ import Testing
|
||||
#expect(harness.model.overlay.current == .passOn(PassOnRequest(reference: "src/a.php", anchor: CGPoint(x: 300, y: 120))))
|
||||
}
|
||||
|
||||
@Test func closingTheNoteInAnyWaySavesIt() async {
|
||||
let harness = WorkspaceHarness(note: "old")
|
||||
await harness.start()
|
||||
harness.model.note?.text = "new text"
|
||||
harness.model.perform(.showNote)
|
||||
await harness.perform(.showShortcuts)
|
||||
#expect(harness.notes.writes == ["new text"])
|
||||
}
|
||||
|
||||
@Test func theDiffOverlayGivesBackTheModeItCovered() async {
|
||||
let harness = WorkspaceHarness(git: snapshot([("a.md", .modified, false)]), contents: ["a.md": "b"])
|
||||
await harness.start()
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
import Foundation
|
||||
import HelderCore
|
||||
import HelderServices
|
||||
|
||||
/// The project note in memory; records every write.
|
||||
final class FakeNotes: NotesServicing, @unchecked Sendable {
|
||||
private let state: Locked<(stored: String, writes: [String], failWrites: Bool)>
|
||||
|
||||
init(_ stored: String = "") {
|
||||
state = Locked((stored, [], false))
|
||||
}
|
||||
|
||||
var writes: [String] { state.current.writes }
|
||||
var onDisk: String { state.current.stored }
|
||||
|
||||
var failWrites: Bool {
|
||||
get { state.current.failWrites }
|
||||
set { state.mutate { $0.failWrites = newValue } }
|
||||
}
|
||||
|
||||
/// Another program rewrote the note file.
|
||||
func setOnDisk(_ text: String) { state.mutate { $0.stored = text } }
|
||||
|
||||
func read() async -> String { state.current.stored }
|
||||
|
||||
func write(_ text: String) async throws {
|
||||
try state.mutate { state in
|
||||
if state.failWrites { throw CocoaError(.fileWriteNoPermission) }
|
||||
state.writes.append(text)
|
||||
state.stored = text
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ struct WorkspaceHarness {
|
||||
let git: FakeGit
|
||||
let files: FakeFiles
|
||||
let config: FakeConfig
|
||||
let notes: FakeNotes
|
||||
let symbols: FakeSymbols
|
||||
let recentFiles: FakeRecentFiles
|
||||
let recents: FakeRecentProjects
|
||||
@@ -27,13 +26,12 @@ struct WorkspaceHarness {
|
||||
var last: FakeWatcher? { made.last }
|
||||
}
|
||||
|
||||
init(root: URL? = URL(fileURLWithPath: "/fake/project"), config: HelderConfig = .defaults, note: String = "",
|
||||
init(root: URL? = URL(fileURLWithPath: "/fake/project"), config: HelderConfig = .defaults,
|
||||
git: GitSnapshot? = nil, tree: FileNode = sampleTree(), contents: [String: String] = [:],
|
||||
recents: [RecentProject] = [], session: FakeSession = FakeSession()) {
|
||||
let git = FakeGit(git)
|
||||
let files = FakeFiles(tree: tree, contents: contents, root: root ?? URL(fileURLWithPath: "/"))
|
||||
let config = FakeConfig(config)
|
||||
let notes = FakeNotes(note)
|
||||
let symbols = FakeSymbols()
|
||||
let recentFiles = FakeRecentFiles()
|
||||
let recentStore = FakeRecentProjects(recents)
|
||||
@@ -45,7 +43,7 @@ struct WorkspaceHarness {
|
||||
recentProjects: recentStore, session: session, layouts: layouts, system: system, speech: speech,
|
||||
makeWorkspace: { _ in
|
||||
WorkspaceServices(git: git, files: files, search: FakeSearch(), symbols: symbols,
|
||||
config: config, notes: notes, recentFiles: recentFiles)
|
||||
config: config, recentFiles: recentFiles)
|
||||
},
|
||||
makeWatcher: {
|
||||
let watcher = FakeWatcher()
|
||||
@@ -58,7 +56,6 @@ struct WorkspaceHarness {
|
||||
self.git = git
|
||||
self.files = files
|
||||
self.config = config
|
||||
self.notes = notes
|
||||
self.symbols = symbols
|
||||
self.recentFiles = recentFiles
|
||||
self.recents = recentStore
|
||||
|
||||
Reference in New Issue
Block a user