This commit is contained in:
David Roman 2023-05-31 22:30:59 +01:00
parent 7cd10629df
commit 07496b849d
No known key found for this signature in database
GPG Key ID: 7058646EEFCB70A7
3 changed files with 104 additions and 0 deletions

View File

@ -0,0 +1,32 @@
#if os(iOS) || os(macOS)
import SwiftUI
// MARK: SwiftUI.DatePicker { ... }.datePickerStyle(.graphical)
public struct DatePickerWithGraphicalStyleType: IntrospectableViewType {
public enum Style {
case graphical
}
}
extension IntrospectableViewType where Self == DatePickerWithGraphicalStyleType {
public static func datePicker(style: Self.Style) -> Self { .init() }
}
#if canImport(UIKit)
extension iOSViewVersion<DatePickerWithGraphicalStyleType, UIDatePicker> {
@available(*, unavailable, message: ".datePickerStyle(.graphical) isn't available on iOS 13")
public static let v13 = Self(for: .v13)
public static let v14 = Self(for: .v14)
public static let v15 = Self(for: .v15)
public static let v16 = Self(for: .v16)
}
#elseif canImport(AppKit) && !targetEnvironment(macCatalyst)
extension macOSViewVersion<DatePickerWithGraphicalStyleType, NSDatePicker> {
public static let v10_15 = Self(for: .v10_15)
public static let v11 = Self(for: .v11)
public static let v12 = Self(for: .v12)
public static let v13 = Self(for: .v13)
}
#endif
#endif

View File

@ -25,6 +25,7 @@
D57506922A27EE4700A628E4 /* DatePickerWithWheelStyleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D57506912A27EE4700A628E4 /* DatePickerWithWheelStyleTests.swift */; };
D57506942A27EED200A628E4 /* DatePickerWithStepperFieldStyleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D57506932A27EED200A628E4 /* DatePickerWithStepperFieldStyleTests.swift */; };
D57506962A27F0E200A628E4 /* DatePickerWithCompactFieldStyleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D57506952A27F0E200A628E4 /* DatePickerWithCompactFieldStyleTests.swift */; };
D57506982A27F32800A628E4 /* DatePickerWithGraphicalStyleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D57506972A27F32800A628E4 /* DatePickerWithGraphicalStyleTests.swift */; };
D58119C42A211B8A0081F853 /* ListCellTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D58119C32A211B8A0081F853 /* ListCellTests.swift */; };
D58119C62A227E930081F853 /* ViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D58119C52A227E930081F853 /* ViewTests.swift */; };
D58119C82A22AC130081F853 /* ToggleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D58119C72A22AC130081F853 /* ToggleTests.swift */; };
@ -79,6 +80,7 @@
D57506912A27EE4700A628E4 /* DatePickerWithWheelStyleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatePickerWithWheelStyleTests.swift; sourceTree = "<group>"; };
D57506932A27EED200A628E4 /* DatePickerWithStepperFieldStyleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatePickerWithStepperFieldStyleTests.swift; sourceTree = "<group>"; };
D57506952A27F0E200A628E4 /* DatePickerWithCompactFieldStyleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatePickerWithCompactFieldStyleTests.swift; sourceTree = "<group>"; };
D57506972A27F32800A628E4 /* DatePickerWithGraphicalStyleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatePickerWithGraphicalStyleTests.swift; sourceTree = "<group>"; };
D58119C32A211B8A0081F853 /* ListCellTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListCellTests.swift; sourceTree = "<group>"; };
D58119C52A227E930081F853 /* ViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewTests.swift; sourceTree = "<group>"; };
D58119C72A22AC130081F853 /* ToggleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToggleTests.swift; sourceTree = "<group>"; };
@ -131,6 +133,7 @@
D58119D92A23B7700081F853 /* ColorPickerTests.swift */,
D58119D32A23AC100081F853 /* DatePickerTests.swift */,
D57506952A27F0E200A628E4 /* DatePickerWithCompactFieldStyleTests.swift */,
D57506972A27F32800A628E4 /* DatePickerWithGraphicalStyleTests.swift */,
D57506932A27EED200A628E4 /* DatePickerWithStepperFieldStyleTests.swift */,
D57506912A27EE4700A628E4 /* DatePickerWithWheelStyleTests.swift */,
D57506872A27CB9800A628E4 /* FormTests.swift */,
@ -324,6 +327,7 @@
files = (
D50FFE8E2A17E2A400C32641 /* ScrollViewTests.swift in Sources */,
D58547F82A1CDD740068ADF4 /* NavigationStackTests.swift in Sources */,
D57506982A27F32800A628E4 /* DatePickerWithGraphicalStyleTests.swift in Sources */,
D57506962A27F0E200A628E4 /* DatePickerWithCompactFieldStyleTests.swift in Sources */,
D57506902A27D69600A628E4 /* ToggleWithCheckboxStyleTests.swift in Sources */,
D58119CC2A239F100081F853 /* TabViewTests.swift in Sources */,

View File

@ -0,0 +1,68 @@
#if os(iOS) || os(macOS)
import SwiftUI
import SwiftUIIntrospect
import XCTest
@available(iOS 14, *)
final class DatePickerWithGraphicalStyleTests: XCTestCase {
#if canImport(UIKit)
typealias PlatformDatePickerWithGraphicalStyle = UIDatePicker
#elseif canImport(AppKit)
typealias PlatformDatePickerWithGraphicalStyle = NSDatePicker
#endif
func testDatePickerWithGraphicalStyle() throws {
guard #available(iOS 14, *) else {
throw XCTSkip()
}
let date0 = Date(timeIntervalSince1970: 0)
let date1 = Date(timeIntervalSince1970: 3600 * 24 * 1)
let date2 = Date(timeIntervalSince1970: 3600 * 24 * 2)
XCTAssertViewIntrospection(of: PlatformDatePickerWithGraphicalStyle.self) { spies in
let spy0 = spies[0]
let spy1 = spies[1]
let spy2 = spies[2]
VStack {
DatePicker("", selection: .constant(date0))
.datePickerStyle(.graphical)
#if os(iOS)
.introspect(.datePicker(style: .graphical), on: .iOS(.v14, .v15, .v16), customize: spy0)
#elseif os(macOS)
.introspect(.datePicker(style: .graphical), on: .macOS(.v10_15, .v11, .v12, .v13), customize: spy0)
#endif
.cornerRadius(8)
DatePicker("", selection: .constant(date1))
.datePickerStyle(.graphical)
#if os(iOS)
.introspect(.datePicker(style: .graphical), on: .iOS(.v14, .v15, .v16), customize: spy1)
#elseif os(macOS)
.introspect(.datePicker(style: .graphical), on: .macOS(.v10_15, .v11, .v12, .v13), customize: spy1)
#endif
.cornerRadius(8)
DatePicker("", selection: .constant(date2))
.datePickerStyle(.graphical)
#if os(iOS)
.introspect(.datePicker(style: .graphical), on: .iOS(.v14, .v15, .v16), customize: spy2)
#elseif os(macOS)
.introspect(.datePicker(style: .graphical), on: .macOS(.v10_15, .v11, .v12, .v13), customize: spy2)
#endif
}
} extraAssertions: {
#if canImport(UIKit)
XCTAssertEqual($0[safe: 0]?.date, date0)
XCTAssertEqual($0[safe: 1]?.date, date1)
XCTAssertEqual($0[safe: 2]?.date, date2)
#elseif canImport(AppKit)
XCTAssertEqual($0[safe: 0]?.dateValue, date0)
XCTAssertEqual($0[safe: 1]?.dateValue, date1)
XCTAssertEqual($0[safe: 2]?.dateValue, date2)
#endif
}
}
}
#endif