Files
helder/Tests/HelderUITests/Editor/EditorFocusAndBinaryTests.swift
T

47 lines
1.6 KiB
Swift

import Foundation
import HelderCore
@testable import HelderUI
import Testing
@MainActor
@Suite struct EditorBinaryTests {
@Test func aFileWithBinaryContentCannotBeDisplayedWhateverItsName() async {
let h = EditorHarness(files: ["data.txt": ""])
h.files.setBinary("data.txt")
h.store.open("data.txt")
await h.store.settle()
#expect(h.store.binaryPaths == ["data.txt"])
#expect(h.store.presentation(for: "data.txt").kind == .binary)
}
@Test func anEmptyTextFileIsStillText() async {
let h = EditorHarness(files: ["empty.txt": ""])
h.store.open("empty.txt")
await h.store.settle()
#expect(h.store.binaryPaths.isEmpty)
#expect(h.store.presentation(for: "empty.txt").kind == .text)
}
}
@MainActor
@Suite struct EditorFocusTests {
@Test func closingTheDiffHandsTheKeyboardBackToTheText() async {
let h = EditorHarness(files: ["a.php": "new"])
h.git.change("a.php", makeDiff(original: "old", updated: "new"))
h.store.open("a.php")
h.store.setMode(.diff, for: "a.php")
let before = h.store.textFocusRequest
h.store.collapseDiff()
#expect(h.store.textFocusRequest > before)
#expect(h.overlays.diffDismissals == 1)
}
@Test func movingFocusToTheEditorColumnAsksForTheTextView() async {
let harness = WorkspaceHarness(contents: ["a.php": ""])
await harness.start()
let before = harness.model.editor?.textFocusRequest ?? 0
harness.model.perform(.focus(.editor))
#expect(harness.model.editor?.textFocusRequest == before + 1)
}
}