112 lines
4.4 KiB
Swift
112 lines
4.4 KiB
Swift
import CoreGraphics
|
|
import Foundation
|
|
import HelderCore
|
|
import HelderServices
|
|
@testable import HelderUI
|
|
import Testing
|
|
|
|
@MainActor
|
|
@Suite struct WorkspaceCloseTests {
|
|
private func dirtyHarness() async -> WorkspaceHarness {
|
|
let harness = WorkspaceHarness(contents: ["a.php": "<?php"])
|
|
await harness.start()
|
|
harness.model.open("a.php")
|
|
await harness.model.settle()
|
|
harness.model.editor?.edit("<?php // unsaved")
|
|
return harness
|
|
}
|
|
|
|
@Test func closingAWindowWithUnsavedEditsAsksFirst() async {
|
|
let harness = await dirtyHarness()
|
|
harness.system.unsavedCloseChoice = .cancel
|
|
#expect(await harness.model.prepareToClose() == false)
|
|
#expect(harness.system.unsavedCloseQuestions == ["a.php"])
|
|
#expect(harness.model.editor?.isDirty("a.php") == true)
|
|
}
|
|
|
|
@Test func savingFromTheCloseQuestionWritesBeforeTheWindowGoes() async {
|
|
let harness = await dirtyHarness()
|
|
harness.system.unsavedCloseChoice = .save
|
|
#expect(await harness.model.prepareToClose())
|
|
#expect(harness.files.current("a.php") == "<?php // unsaved")
|
|
#expect(harness.session.sessions["/fake/project"]?.active == "a.php")
|
|
}
|
|
|
|
@Test func aCancelledProjectSwitchKeepsTheProjectAndItsEdits() async {
|
|
let harness = await dirtyHarness()
|
|
harness.system.unsavedCloseChoice = .cancel
|
|
await harness.model.openProject(URL(fileURLWithPath: "/fake/other"))
|
|
#expect(harness.model.root == harness.root)
|
|
#expect(harness.model.editor?.text(for: "a.php") == "<?php // unsaved")
|
|
#expect(harness.agent.terminations == 0)
|
|
}
|
|
|
|
@Test func aProjectSwitchAsksAboutUnsavedEditsAndSavesThem() async {
|
|
let harness = await dirtyHarness()
|
|
harness.system.unsavedCloseChoice = .save
|
|
await harness.model.openProject(URL(fileURLWithPath: "/fake/other"))
|
|
#expect(harness.model.root?.path == "/fake/other")
|
|
#expect(harness.files.current("a.php") == "<?php // unsaved")
|
|
}
|
|
|
|
@Test func workStillRunningAtASwitchStaysWithTheOldProject() async {
|
|
let harness = WorkspaceHarness(git: snapshot([("a.php", .modified, false)]), contents: ["a.php": "<?php"])
|
|
await harness.start()
|
|
harness.model.open("a.php")
|
|
await harness.model.settle()
|
|
let oldEditor = harness.model.editor
|
|
let gate = harness.files.holdNextRead("a.php")
|
|
harness.model.perform(.context(.gitDiscard(["a.php"])))
|
|
harness.model.perform(.confirmPending)
|
|
#expect(await eventually { gate.isWaiting })
|
|
harness.model.perform(.openRecentProject("/fake/other"))
|
|
gate.open()
|
|
await harness.model.settle()
|
|
#expect(harness.model.root?.path == "/fake/other")
|
|
#expect(harness.model.editor !== oldEditor)
|
|
#expect(harness.model.editor?.states["a.php"] == nil)
|
|
}
|
|
}
|
|
|
|
@MainActor
|
|
@Suite struct WorkspaceShortcutTests {
|
|
@Test func theRowMenuAnchorsToTheReportedRowFrame() async {
|
|
let harness = WorkspaceHarness()
|
|
await harness.start()
|
|
harness.model.perform(.focus(.explorer))
|
|
harness.model.perform(.moveRowCursor(1))
|
|
guard let path = harness.model.explorer?.selectedPath else {
|
|
Issue.record("no row selected")
|
|
return
|
|
}
|
|
harness.model.rowFrameChanged(.tree(path), CGRect(x: 250, y: 312, width: 200, height: 26))
|
|
harness.model.perform(.openRowMenu)
|
|
guard case let .contextMenu(menu) = harness.model.overlay.current else {
|
|
Issue.record("no menu")
|
|
return
|
|
}
|
|
#expect(menu.anchor.y == 316)
|
|
#expect(Double(menu.anchor.x) == harness.model.layout.span(of: .explorer)?.upperBound)
|
|
}
|
|
|
|
@Test func commandASelectsTheOpenFile() async {
|
|
let harness = WorkspaceHarness(contents: ["a.php": "<?php"])
|
|
await harness.start()
|
|
harness.model.open("a.php")
|
|
let before = harness.model.editor?.selectAllRequest
|
|
harness.model.perform(.selectAllInFile)
|
|
#expect(harness.model.editor?.selectAllRequest != before)
|
|
}
|
|
|
|
@Test func zoomStepsAndIsRemembered() async {
|
|
let harness = WorkspaceHarness()
|
|
await harness.start()
|
|
harness.model.perform(.zoom(.bigger))
|
|
harness.model.perform(.zoom(.bigger))
|
|
#expect(harness.model.layout.zoomLevel == 1)
|
|
#expect(harness.layouts.zoomLevel == 1)
|
|
harness.model.perform(.zoom(.reset))
|
|
#expect(harness.model.layout.textScale == 1)
|
|
}
|
|
}
|