Skip to content

Commit 6569a74

Browse files
authored
Add .introspectColorWell() (#87)
1 parent 4232b86 commit 6569a74

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Changelog
33

44
## master
55

6+
- Added `.introspectColorWell()` on iOS and macOS
67
- Added `.introspectButton()` on macOS
78
- Fix UITextField with cornerRadius
89
- Added `.introspectTabView()` on macOS

Introspect/ViewExtensions.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ extension View {
127127
public func introspectSegmentedControl(customize: @escaping (UISegmentedControl) -> ()) -> some View {
128128
return introspect(selector: TargetViewSelector.siblingContaining, customize: customize)
129129
}
130+
131+
/// Finds a `UIColorWell` from a `SwiftUI.ColorPicker`
132+
@available(iOS 14.0, *)
133+
@available(tvOS, unavailable)
134+
public func introspectColorWell(customize: @escaping (UIColorWell) -> ()) -> some View {
135+
return introspect(selector: TargetViewSelector.siblingContaining, customize: customize)
136+
}
130137
}
131138
#endif
132139

@@ -203,5 +210,11 @@ extension View {
203210
public func introspectButton(customize: @escaping (NSButton) -> ()) -> some View {
204211
return introspect(selector: TargetViewSelector.siblingContaining, customize: customize)
205212
}
213+
214+
/// Finds a `NSColorWell` from a `SwiftUI.ColorPicker`
215+
@available(macOS 11.0, *)
216+
public func introspectColorWell(customize: @escaping (NSColorWell) -> ()) -> some View {
217+
return introspect(selector: TargetViewSelector.siblingContaining, customize: customize)
218+
}
206219
}
207220
#endif

IntrospectTests/AppKitTests.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,19 @@ private struct ButtonTestView: View {
214214
}
215215
}
216216

217+
@available(macOS 11.0, *)
218+
private struct ColorWellTestView: View {
219+
@State private var color = Color.black
220+
let spy: () -> Void
221+
222+
var body: some View {
223+
ColorPicker("Picker", selection: $color)
224+
.introspectColorWell { colorWell in
225+
self.spy()
226+
}
227+
}
228+
}
229+
217230
@available(macOS 10.15.0, *)
218231
class AppKitTests: XCTestCase {
219232

@@ -367,5 +380,17 @@ class AppKitTests: XCTestCase {
367380
TestUtils.present(view: view)
368381
wait(for: [expectation], timeout: TestUtils.Constants.timeout)
369382
}
383+
384+
func testColorPicker() {
385+
386+
if #available(macOS 11.0, *) {
387+
let expectation = XCTestExpectation()
388+
let view = ColorWellTestView(spy: {
389+
expectation.fulfill()
390+
})
391+
TestUtils.present(view: view)
392+
wait(for: [expectation], timeout: TestUtils.Constants.timeout)
393+
}
394+
}
370395
}
371396
#endif

IntrospectTests/UIKitTests.swift

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ private struct TextFieldTestView: View {
217217
}
218218
}
219219

220-
@available(iOS 14.0, macCatalyst 14.0, macOS 11.0, *)
220+
@available(iOS 14.0, macCatalyst 14.0, macOS 11.0, tvOS 13.0, *)
221221
@available(tvOS, unavailable, message: "TextEditor is not available in tvOS.")
222222
private struct TextEditorTestView: View {
223223
let spy: () -> Void
@@ -302,6 +302,20 @@ private struct SegmentedControlTestView: View {
302302
}
303303
}
304304

305+
@available(iOS 14.0, tvOS 13.0, macOS 11.0, *)
306+
@available(tvOS, unavailable)
307+
private struct ColorWellTestView: View {
308+
@State private var color = Color.black
309+
let spy: () -> Void
310+
311+
var body: some View {
312+
ColorPicker("Picker", selection: $color)
313+
.introspectColorWell { colorWell in
314+
self.spy()
315+
}
316+
}
317+
}
318+
305319
@available(iOS 13.0, tvOS 13.0, macOS 10.15.0, *)
306320
class UIKitTests: XCTestCase {
307321
func testNavigation() {
@@ -512,7 +526,7 @@ class UIKitTests: XCTestCase {
512526
wait(for: [expectation], timeout: TestUtils.Constants.timeout)
513527
}
514528

515-
@available(iOS 14.0, macCatalyst 14.0, macOS 15.0, *)
529+
@available(iOS 14.0, macCatalyst 14.0, macOS 11.0, *)
516530
@available(tvOS, unavailable, message: "TextEditor is not available in tvOS.")
517531
func testTextEditor() {
518532

@@ -523,6 +537,18 @@ class UIKitTests: XCTestCase {
523537
TestUtils.present(view: view)
524538
wait(for: [expectation], timeout: TestUtils.Constants.timeout)
525539
}
540+
541+
@available(iOS 14.0, macCatalyst 14.0, macOS 11.0, *)
542+
@available(tvOS, unavailable, message: "ColorPicker is not available in tvOS.")
543+
func testColorPicker() {
544+
545+
let expectation = XCTestExpectation()
546+
let view = ColorWellTestView(spy: {
547+
expectation.fulfill()
548+
})
549+
TestUtils.present(view: view)
550+
wait(for: [expectation], timeout: TestUtils.Constants.timeout)
551+
}
526552
#endif
527553
}
528554
#endif

0 commit comments

Comments
 (0)