Tests/OrgEditorAppKitTests/FindTests.swift
43 lines · 1544 bytes
1import AppKit
2import OrgCore
3import Testing
4@testable import OrgEditorAppKit
5
6@MainActor
7struct FindTests {
8 @Test func replaceShowsTheFindBar() {
9 let h = Harness("* Heading\nbody\n")
10 #expect(h.textView.enclosingScrollView?.isFindBarVisible != true)
11 h.editor.run("edit.replace")
12 #expect(h.textView.enclosingScrollView?.isFindBarVisible == true)
13 }
14
15 @Test func aMatchInFoldedTextUnfoldsIt() {
16 let text = "* Heading\nhidden needle\n* Next\n"
17 let h = Harness(text)
18 h.caret(at: 0)
19 h.editor.cycleAtCaret()
20 #expect(!h.editor.foldState.folds.isEmpty)
21 let needle = (text as NSString).range(of: "needle")
22 h.textView.setSelectedRange(needle)
23 #expect(h.editor.foldState.folds.isEmpty)
24 #expect(h.textView.selectedRange() == needle)
25 }
26}
27
28@MainActor
29struct BodyFoldTests {
30 /// CONTENTS view hides bodies (body folds); an edit elsewhere keeps them hidden.
31 @Test func bodyFoldsSurviveEdits() {
32 let h = Harness("* A\nbody a\n** B\nbody b\n* C\nbody c\n")
33 h.editor.cycleGlobal()
34 h.editor.cycleGlobal()
35 #expect(!h.editor.foldState.bodyFolds.isEmpty)
36 let hiddenBefore = h.editor.hidden.all
37 #expect(!hiddenBefore.isEmpty)
38 h.caret(at: 3)
39 h.textView.insertText("x", replacementRange: NSRange(location: 3, length: 0))
40 #expect(h.editor.hidden.all.count == hiddenBefore.count)
41 #expect(h.editor.hidden.all.map { $0.count } == hiddenBefore.map { $0.count })
42 }
43}