Skip to content

Add SignInWithAppleButton introspection #265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions Sources/ViewTypes/SignInWithAppleButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import SwiftUI

/// An abstract representation of the `SignInWithAppleButton` type in SwiftUI.
///
/// ### iOS
///
/// ```swift
/// struct ContentView: View {
/// var body: some View {
/// SignInWithAppleButton(.signIn) { request in
/// request.requestedScopes = [.fullName, .email]
/// } onCompletion: { result in
/// // do something with result
/// }
/// .introspect(.signInWithAppleButton, on: .iOS(.v14, .v15, .v16, .v17)) {
/// print(type(of: $0)) // ASAuthorizationAppleIDButton
/// }
/// }
/// }
/// ```
///
/// ### tvOS
///
/// ```swift
/// struct ContentView: View {
/// var body: some View {
/// SignInWithAppleButton(.signIn) { request in
/// request.requestedScopes = [.fullName, .email]
/// } onCompletion: { result in
/// // do something with result
/// }
/// .introspect(.signInWithAppleButton, on: .tvOS(.v14, .v15, .v16, .v17)) {
/// print(type(of: $0)) // ASAuthorizationAppleIDButton
/// }
/// }
/// }
/// ```
///
/// ### macOS
///
/// ```swift
/// struct ContentView: View {
/// var body: some View {
/// SignInWithAppleButton(.signIn) { request in
/// request.requestedScopes = [.fullName, .email]
/// } onCompletion: { result in
/// // do something with result
/// }
/// .introspect(.signInWithAppleButton, on: .macOS(.v11, .v12, .v13, .v14),) {
/// print(type(of: $0)) // ASAuthorizationAppleIDButton
/// }
/// }
/// }
/// ```
public struct SignInWithAppleButtonType: IntrospectableViewType {}

#if canImport(AuthenticationServices)
import AuthenticationServices

extension IntrospectableViewType where Self == SignInWithAppleButtonType {
public static var signInWithAppleButton: Self { .init() }
}

extension iOSViewVersion<SignInWithAppleButtonType, ASAuthorizationAppleIDButton> {
@available(*, unavailable, message: "SignInWithAppleButton isn't available on iOS 13")
public static let v13 = Self.unavailable()
public static let v14 = Self(for: .v14)
public static let v15 = Self(for: .v15)
public static let v16 = Self(for: .v16)
public static let v17 = Self(for: .v17)
}

extension tvOSViewVersion<SignInWithAppleButtonType, ASAuthorizationAppleIDButton> {
@available(*, unavailable, message: "SignInWithAppleButton isn't available on tvOS 13")
public static let v13 = Self.unavailable()
public static let v14 = Self(for: .v14)
public static let v15 = Self(for: .v15)
public static let v16 = Self(for: .v16)
public static let v17 = Self(for: .v17)
}

extension macOSViewVersion<SignInWithAppleButtonType, ASAuthorizationAppleIDButton> {
@available(*, unavailable, message: "SignInWithAppleButton isn't available on macOS 10.15")
public static let v10_15 = Self.unavailable()
public static let v11 = Self(for: .v11)
public static let v12 = Self(for: .v12)
public static let v13 = Self(for: .v13)
public static let v14 = Self(for: .v14)
}
#endif
4 changes: 4 additions & 0 deletions Tests/Tests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
D50E2F8B2A2B9F6600BAFB03 /* SwiftUIIntrospect in Frameworks */ = {isa = PBXBuildFile; productRef = D50E2F5C2A2B9F6600BAFB03 /* SwiftUIIntrospect */; };
D50FFE8E2A17E2A400C32641 /* ScrollViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D50FFE8D2A17E2A400C32641 /* ScrollViewTests.swift */; };
D55F448D2A1FF209003381E4 /* ListTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D55F448C2A1FF209003381E4 /* ListTests.swift */; };
D568532C2A49DBB10039A99F /* SignInWithAppleButtonTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D568532B2A49DBB10039A99F /* SignInWithAppleButtonTests.swift */; };
D57506782A27BBBD00A628E4 /* PickerWithSegmentedStyleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D57506772A27BBBD00A628E4 /* PickerWithSegmentedStyleTests.swift */; };
D575067A2A27BF6C00A628E4 /* PickerWithMenuStyleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D57506792A27BF6C00A628E4 /* PickerWithMenuStyleTests.swift */; };
D575067C2A27C24600A628E4 /* ListWithPlainStyleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D575067B2A27C24600A628E4 /* ListWithPlainStyleTests.swift */; };
Expand Down Expand Up @@ -133,6 +134,7 @@
D50E2F902A2B9F6600BAFB03 /* LegacyTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LegacyTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
D50FFE8D2A17E2A400C32641 /* ScrollViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollViewTests.swift; sourceTree = "<group>"; };
D55F448C2A1FF209003381E4 /* ListTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListTests.swift; sourceTree = "<group>"; };
D568532B2A49DBB10039A99F /* SignInWithAppleButtonTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInWithAppleButtonTests.swift; sourceTree = "<group>"; };
D57506772A27BBBD00A628E4 /* PickerWithSegmentedStyleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PickerWithSegmentedStyleTests.swift; sourceTree = "<group>"; };
D57506792A27BF6C00A628E4 /* PickerWithMenuStyleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PickerWithMenuStyleTests.swift; sourceTree = "<group>"; };
D575067B2A27C24600A628E4 /* ListWithPlainStyleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListWithPlainStyleTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -261,6 +263,7 @@
D58119CD2A23A4A70081F853 /* TabViewWithPageStyleTests.swift */,
D58119C92A239BAC0081F853 /* TextEditorTests.swift */,
D5B67B832A0D318F007D5D9B /* TextFieldTests.swift */,
D568532B2A49DBB10039A99F /* SignInWithAppleButtonTests.swift */,
D5AD0D902A114B98003D8DEC /* TextFieldWithVerticalAxisTests.swift */,
D58119C72A22AC130081F853 /* ToggleTests.swift */,
D575068D2A27D4DC00A628E4 /* ToggleWithButtonStyleTests.swift */,
Expand Down Expand Up @@ -556,6 +559,7 @@
D575067A2A27BF6C00A628E4 /* PickerWithMenuStyleTests.swift in Sources */,
D57506922A27EE4700A628E4 /* DatePickerWithWheelStyleTests.swift in Sources */,
D57506822A27C74600A628E4 /* ListWithInsetGroupedStyleTests.swift in Sources */,
D568532C2A49DBB10039A99F /* SignInWithAppleButtonTests.swift in Sources */,
D575068A2A27CE7900A628E4 /* FormWithGroupedStyleTests.swift in Sources */,
D575067C2A27C24600A628E4 /* ListWithPlainStyleTests.swift in Sources */,
D58119CA2A239BAC0081F853 /* TextEditorTests.swift in Sources */,
Expand Down
50 changes: 50 additions & 0 deletions Tests/Tests/ViewTypes/SignInWithAppleButtonTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#if canImport(AuthenticationServices)
import AuthenticationServices
import SwiftUI
import SwiftUIIntrospect
import XCTest

@available(iOS 14, tvOS 14, macOS 11, *)
final class SignInWithAppleButtonTests: XCTestCase {
typealias PlatformSignInWithAppleButton = ASAuthorizationAppleIDButton

func testSignInWithAppleButton() throws {
guard #available(iOS 14, tvOS 14, macOS 11, *) else {
throw XCTSkip()
}

XCTAssertViewIntrospection(of: PlatformSignInWithAppleButton.self) { spies in
let spy0 = spies[0]
let spy1 = spies[1]
let spy2 = spies[2]

VStack {
SignInWithAppleButton(.continue, onRequest: { _ in }, onCompletion: { _ in })
.introspect(
.signInWithAppleButton,
on: .iOS(.v14, .v15, .v16, .v17), .tvOS(.v14, .v15, .v16, .v17), .macOS(.v11, .v12, .v13, .v14),
customize: spy0
)

SignInWithAppleButton(.signIn, onRequest: { _ in }, onCompletion: { _ in })
.introspect(
.signInWithAppleButton,
on: .iOS(.v14, .v15, .v16, .v17), .tvOS(.v14, .v15, .v16, .v17), .macOS(.v11, .v12, .v13, .v14),
customize: spy1
)

SignInWithAppleButton(.signUp, onRequest: { _ in }, onCompletion: { _ in })
.introspect(
.signInWithAppleButton,
on: .iOS(.v14, .v15, .v16, .v17), .tvOS(.v14, .v15, .v16, .v17), .macOS(.v11, .v12, .v13, .v14),
customize: spy2
)
}
} extraAssertions: {
XCTAssertNotIdentical($0[safe: 0], $0[safe: 1])
XCTAssertNotIdentical($0[safe: 0], $0[safe: 2])
XCTAssertNotIdentical($0[safe: 1], $0[safe: 2])
}
}
}
#endif