Skip to content

Commit 6c1b06b

Browse files
authored
Add a SwiftUI unit test target (google#122)
1 parent a757244 commit 6c1b06b

4 files changed

Lines changed: 114 additions & 1 deletion

File tree

GoogleSignInSwift.podspec

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,14 @@ Pod::Spec.new do |s|
2424
'SwiftUI',
2525
]
2626
s.dependency 'GoogleSignIn', '~> 6.2'
27+
s.test_spec 'unit' do |unit_tests|
28+
unit_tests.platforms = {
29+
:ios => ios_deployment_target,
30+
:osx => macos_deployment_target,
31+
}
32+
unit_tests.source_files = [
33+
'GoogleSignInSwift/Tests/Unit/*.swift',
34+
]
35+
unit_tests.requires_app_host = false
36+
end
2737
end
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import XCTest
18+
@testable import GoogleSignInSwift
19+
20+
@available(iOS 13.0, macOS 10.15, *)
21+
class GoogleSignInButtonStylingTests: XCTestCase {
22+
private typealias ButtonViewModelInfo = (
23+
scheme: GoogleSignInButtonColorScheme,
24+
style: GoogleSignInButtonStyle,
25+
state: GoogleSignInButtonState
26+
)
27+
28+
func testThatViewModelGetsCorrectColor() {
29+
let stylingTuples: [ButtonViewModelInfo] = [
30+
(.light, .standard, .normal),
31+
(.light, .wide, .normal),
32+
(.light, .icon, .normal),
33+
34+
(.light, .standard, .pressed),
35+
(.light, .wide, .pressed),
36+
(.light, .icon, .pressed),
37+
38+
(.light, .standard, .disabled),
39+
(.light, .wide, .disabled),
40+
(.light, .icon, .disabled),
41+
42+
(.dark, .standard, .normal),
43+
(.dark, .wide, .normal),
44+
(.dark, .icon, .normal),
45+
46+
(.dark, .standard, .pressed),
47+
(.dark, .wide, .pressed),
48+
(.dark, .icon, .pressed),
49+
50+
(.dark, .standard, .disabled),
51+
(.dark, .wide, .disabled),
52+
(.dark, .icon, .disabled),
53+
]
54+
55+
for styleTuple in stylingTuples {
56+
buttonViewModelAndColor(
57+
scheme: styleTuple.scheme,
58+
style: styleTuple.style,
59+
state: styleTuple.state
60+
) { viewModel, colors in
61+
XCTAssertEqual(
62+
viewModel.buttonStyle.colors.foregroundColor,
63+
colors.foregroundColor
64+
)
65+
XCTAssertEqual(
66+
viewModel.buttonStyle.colors.backgroundColor,
67+
colors.backgroundColor
68+
)
69+
XCTAssertEqual(
70+
viewModel.buttonStyle.colors.iconColor,
71+
colors.iconColor
72+
)
73+
XCTAssertEqual(
74+
viewModel.buttonStyle.colors.iconBorderColor,
75+
colors.iconBorderColor
76+
)
77+
}
78+
}
79+
}
80+
}
81+
82+
@available(iOS 13.0, macOS 10.15, *)
83+
extension GoogleSignInButtonStylingTests {
84+
func buttonViewModelAndColor(
85+
scheme: GoogleSignInButtonColorScheme,
86+
style: GoogleSignInButtonStyle,
87+
state: GoogleSignInButtonState,
88+
completion: (GoogleSignInButtonViewModel, SignInButtonColor) -> Void
89+
) {
90+
let vm = GoogleSignInButtonViewModel(
91+
scheme: scheme,
92+
style: style,
93+
state: state
94+
)
95+
let bc = SignInButtonColor(scheme: scheme, state: state)
96+
completion(vm, bc)
97+
}
98+
}

Package.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,10 @@ let package = Package(
114114
.define("GID_SDK_VERSION", to: googleSignInVersion),
115115
]
116116
),
117+
.testTarget(
118+
name: "GoogleSignInSwift-UnitTests",
119+
dependencies: ["GoogleSignInSwift"],
120+
path: "GoogleSignInSwift/Tests/Unit"
121+
)
117122
]
118123
)

Samples/Swift/DaysUntilBirthday/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pod 'GoogleSignIn', :path => '../../../', :testspecs => ['unit']
2-
pod 'GoogleSignInSwift', :path => '../../../'
2+
pod 'GoogleSignInSwift', :path => '../../../', :testspecs => ['unit']
33
project 'DaysUntilBirthdayForPod.xcodeproj'
44

55
target 'DaysUntilBirthdayForPod(iOS)' do

0 commit comments

Comments
 (0)