Skip to content

Commit 82efbfe

Browse files
committed
Get Tests Going
1 parent 6d48925 commit 82efbfe

File tree

3 files changed

+27
-64
lines changed

3 files changed

+27
-64
lines changed

Sources/CodeEditSourceEditor/Find/ViewModel/FindPanelViewModel+Find.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ extension FindPanelViewModel {
6565
self.findMatches = matches.map(\.range)
6666

6767
// Find the nearest match to the current cursor position
68-
currentFindMatchIndex = getNearestEmphasisIndex(matchRanges: findMatches) ?? 0
68+
currentFindMatchIndex = getNearestEmphasisIndex(matchRanges: findMatches)
6969

7070
// Only add emphasis layers if the find panel is focused
7171
if isFocused {

Tests/CodeEditSourceEditorTests/FindPanelTests.swift

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,26 @@ struct FindPanelTests {
3434
}
3535
}
3636

37-
@Test func findPanelShowsOnCommandF() async throws {
38-
let target = MockPanelTarget()
39-
let viewModel = FindPanelViewModel(target: target)
40-
let viewController = FindViewController(target: target, childView: NSView())
37+
let target = MockPanelTarget()
38+
let viewModel: FindPanelViewModel
39+
let viewController: FindViewController
40+
41+
init() {
42+
viewController = FindViewController(target: target, childView: NSView())
43+
viewModel = viewController.viewModel
44+
viewController.loadView()
45+
}
4146

47+
@Test func viewModelHeightUpdates() async throws {
48+
let model = FindPanelViewModel(target: MockPanelTarget())
49+
model.mode = .find
50+
#expect(model.panelHeight == 28)
51+
52+
model.mode = .replace
53+
#expect(model.panelHeight == 54)
54+
}
55+
56+
@Test func findPanelShowsOnCommandF() async throws {
4257
// Show find panel
4358
viewController.showFindPanel()
4459

@@ -55,9 +70,6 @@ struct FindPanelTests {
5570
}
5671

5772
@Test func replaceFieldShowsWhenReplaceModeSelected() async throws {
58-
let target = MockPanelTarget()
59-
let viewModel = FindPanelViewModel(target: target)
60-
6173
// Switch to replace mode
6274
viewModel.mode = .replace
6375

@@ -76,8 +88,7 @@ struct FindPanelTests {
7688
}
7789

7890
@Test func wrapAroundEnabled() async throws {
79-
let target = MockPanelTarget(text: "test1\ntest2\ntest3")
80-
let viewModel = FindPanelViewModel(target: target)
91+
target.textView.string = "test1\ntest2\ntest3"
8192
viewModel.findText = "test"
8293
viewModel.wrapAround = true
8394

@@ -98,8 +109,7 @@ struct FindPanelTests {
98109
}
99110

100111
@Test func wrapAroundDisabled() async throws {
101-
let target = MockPanelTarget(text: "test1\ntest2\ntest3")
102-
let viewModel = FindPanelViewModel(target: target)
112+
target.textView.string = "test1\ntest2\ntest3"
103113
viewModel.findText = "test"
104114
viewModel.wrapAround = false
105115

@@ -123,8 +133,7 @@ struct FindPanelTests {
123133
}
124134

125135
@Test func findMatches() async throws {
126-
let target = MockPanelTarget(text: "test1\ntest2\ntest3")
127-
let viewModel = FindPanelViewModel(target: target)
136+
target.textView.string = "test1\ntest2\ntest3"
128137
viewModel.findText = "test"
129138

130139
viewModel.find()
@@ -136,8 +145,7 @@ struct FindPanelTests {
136145
}
137146

138147
@Test func noMatchesFound() async throws {
139-
let target = MockPanelTarget(text: "test1\ntest2\ntest3")
140-
let viewModel = FindPanelViewModel(target: target)
148+
target.textView.string = "test1\ntest2\ntest3"
141149
viewModel.findText = "nonexistent"
142150

143151
viewModel.find()
@@ -147,8 +155,7 @@ struct FindPanelTests {
147155
}
148156

149157
@Test func matchCaseToggle() async throws {
150-
let target = MockPanelTarget(text: "Test1\ntest2\nTEST3")
151-
let viewModel = FindPanelViewModel(target: target)
158+
target.textView.string = "Test1\ntest2\nTEST3"
152159

153160
// Test case-sensitive
154161
viewModel.matchCase = true
@@ -163,8 +170,7 @@ struct FindPanelTests {
163170
}
164171

165172
@Test func findMethodPickerOptions() async throws {
166-
let target = MockPanelTarget(text: "test1 test2 test3")
167-
let viewModel = FindPanelViewModel(target: target)
173+
target.textView.string = "test1 test2 test3"
168174

169175
// Test contains
170176
viewModel.findMethod = .contains
@@ -197,8 +203,7 @@ struct FindPanelTests {
197203
}
198204

199205
@Test func findMethodPickerOptionsWithComplexText() async throws {
200-
let target = MockPanelTarget(text: "test1 test2 test3\nprefix_test suffix_test\nword_test_word")
201-
let viewModel = FindPanelViewModel(target: target)
206+
target.textView.string = "test1 test2 test3\nprefix_test suffix_test\nword_test_word"
202207

203208
// Test contains with partial matches
204209
viewModel.findMethod = .contains

Tests/CodeEditSourceEditorTests/FindPanelViewModelTests.swift

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)