adds Clean Copy Support
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
import Foundation
|
||||
import HelderCore
|
||||
import HelderServices
|
||||
@testable import HelderUI
|
||||
import Testing
|
||||
|
||||
@MainActor
|
||||
@Suite struct CleanCopyTests {
|
||||
private let file = CleanCopy.fileName
|
||||
|
||||
private func started(_ text: String? = nil) async -> WorkspaceHarness {
|
||||
let harness = WorkspaceHarness(contents: text.map { [CleanCopy.fileName: $0] } ?? [:])
|
||||
await harness.start()
|
||||
return harness
|
||||
}
|
||||
|
||||
private func agentWrites(_ text: String, _ harness: WorkspaceHarness) async {
|
||||
harness.files.set(file, text)
|
||||
await harness.model.handle(.cleanCopy)
|
||||
await harness.model.settle()
|
||||
}
|
||||
|
||||
@Test func theTextFoundOnProjectOpenIsTheBaselineAndNeverPops() async {
|
||||
let harness = await started("left over from yesterday")
|
||||
#expect(harness.model.overlay.current == .none)
|
||||
await harness.model.handle(.cleanCopy)
|
||||
#expect(harness.model.overlay.current == .none)
|
||||
}
|
||||
|
||||
@Test func aChangedFileOpensThePopupWithItsText() async {
|
||||
let harness = await started("old")
|
||||
await agentWrites("git commit -m \"fix\"", harness)
|
||||
#expect(harness.model.overlay.current == .cleanCopy)
|
||||
#expect(harness.model.cleanCopy?.text == "git commit -m \"fix\"")
|
||||
}
|
||||
|
||||
@Test func aFileThatAppearsAfterOpenPops() async {
|
||||
let harness = await started()
|
||||
await agentWrites("first", harness)
|
||||
#expect(harness.model.overlay.current == .cleanCopy)
|
||||
}
|
||||
|
||||
@Test func theSameTextAgainDoesNotPop() async {
|
||||
let harness = await started()
|
||||
await agentWrites("once", harness)
|
||||
await harness.perform(.dismissOverlay)
|
||||
await agentWrites("once", harness)
|
||||
#expect(harness.model.overlay.current == .none)
|
||||
}
|
||||
|
||||
@Test func anEmptyOrBlankFileDoesNotPop() async {
|
||||
let harness = await started("old")
|
||||
await agentWrites("", harness)
|
||||
await agentWrites(" \n\t", harness)
|
||||
#expect(harness.model.overlay.current == .none)
|
||||
}
|
||||
|
||||
@Test func copyPutsTheEditedTextOnThePasteboardClosesAndToasts() async {
|
||||
let harness = await started()
|
||||
await agentWrites("draft", harness)
|
||||
harness.model.cleanCopy?.text = "draft, edited"
|
||||
await harness.perform(.copyCleanCopy)
|
||||
#expect(harness.system.copied == ["draft, edited"])
|
||||
#expect(harness.model.overlay.current == .none)
|
||||
#expect(harness.toastTitles == ["Copied"])
|
||||
}
|
||||
|
||||
@Test func escClosesWithoutCopying() async {
|
||||
let harness = await started()
|
||||
await agentWrites("draft", harness)
|
||||
await harness.perform(.dismissOverlay)
|
||||
#expect(harness.system.copied.isEmpty)
|
||||
#expect(harness.model.overlay.current == .none)
|
||||
}
|
||||
|
||||
@Test func newTextReplacesAnUneditedPopup() async {
|
||||
let harness = await started()
|
||||
await agentWrites("one", harness)
|
||||
await agentWrites("two", harness)
|
||||
#expect(harness.model.overlay.current == .cleanCopy)
|
||||
#expect(harness.model.cleanCopy?.text == "two")
|
||||
}
|
||||
|
||||
@Test func newTextLeavesAnEditedPopupAlone() async {
|
||||
let harness = await started()
|
||||
await agentWrites("one", harness)
|
||||
harness.model.cleanCopy?.text = "one, mine"
|
||||
await agentWrites("two", harness)
|
||||
#expect(harness.model.cleanCopy?.text == "one, mine")
|
||||
#expect(harness.model.cleanCopy?.pending == nil)
|
||||
}
|
||||
|
||||
@Test func textWaitsForAnotherOverlayAndOnlyTheLatestShows() async {
|
||||
let harness = await started()
|
||||
await harness.perform(.showNote)
|
||||
await agentWrites("one", harness)
|
||||
await agentWrites("two", harness)
|
||||
#expect(harness.model.overlay.current == .note)
|
||||
await harness.perform(.dismissOverlay)
|
||||
#expect(await eventually { harness.model.overlay.current == .cleanCopy })
|
||||
#expect(harness.model.cleanCopy?.text == "two")
|
||||
}
|
||||
|
||||
@Test func theFileIsNeverWrittenOrDeleted() async {
|
||||
let harness = await started()
|
||||
await agentWrites("keep", harness)
|
||||
await harness.perform(.copyCleanCopy)
|
||||
#expect(harness.files.current(file) == "keep")
|
||||
#expect(harness.files.deleted.isEmpty)
|
||||
#expect(harness.files.writes.isEmpty)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user