diff --git a/Sources/ViewTypes/DatePickerWithGraphicalStyleType.swift b/Sources/ViewTypes/DatePickerWithGraphicalStyleType.swift new file mode 100644 index 0000000..7ef7eab --- /dev/null +++ b/Sources/ViewTypes/DatePickerWithGraphicalStyleType.swift @@ -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 { + @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 { + 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 diff --git a/Tests/Tests.xcodeproj/project.pbxproj b/Tests/Tests.xcodeproj/project.pbxproj index 86ea1e6..ee7ec6f 100644 --- a/Tests/Tests.xcodeproj/project.pbxproj +++ b/Tests/Tests.xcodeproj/project.pbxproj @@ -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 = ""; }; D57506932A27EED200A628E4 /* DatePickerWithStepperFieldStyleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatePickerWithStepperFieldStyleTests.swift; sourceTree = ""; }; D57506952A27F0E200A628E4 /* DatePickerWithCompactFieldStyleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatePickerWithCompactFieldStyleTests.swift; sourceTree = ""; }; + D57506972A27F32800A628E4 /* DatePickerWithGraphicalStyleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatePickerWithGraphicalStyleTests.swift; sourceTree = ""; }; D58119C32A211B8A0081F853 /* ListCellTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListCellTests.swift; sourceTree = ""; }; D58119C52A227E930081F853 /* ViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewTests.swift; sourceTree = ""; }; D58119C72A22AC130081F853 /* ToggleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToggleTests.swift; sourceTree = ""; }; @@ -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 */, diff --git a/Tests/Tests/ViewTypes/DatePickerWithGraphicalStyleTests.swift b/Tests/Tests/ViewTypes/DatePickerWithGraphicalStyleTests.swift new file mode 100644 index 0000000..04c9412 --- /dev/null +++ b/Tests/Tests/ViewTypes/DatePickerWithGraphicalStyleTests.swift @@ -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