GoogleSignInButtonStylingTests.swift 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. import XCTest
  17. @testable import GoogleSignInSwift
  18. @MainActor
  19. @available(iOS 13.0, macOS 10.15, *)
  20. class GoogleSignInButtonStylingTests: XCTestCase {
  21. private typealias ButtonViewModelInfo = (
  22. scheme: GoogleSignInButtonColorScheme,
  23. style: GoogleSignInButtonStyle,
  24. state: GoogleSignInButtonState
  25. )
  26. func testThatViewModelGetsCorrectColor() {
  27. let stylingTuples: [ButtonViewModelInfo] = [
  28. (.light, .standard, .normal),
  29. (.light, .wide, .normal),
  30. (.light, .icon, .normal),
  31. (.light, .standard, .pressed),
  32. (.light, .wide, .pressed),
  33. (.light, .icon, .pressed),
  34. (.light, .standard, .disabled),
  35. (.light, .wide, .disabled),
  36. (.light, .icon, .disabled),
  37. (.dark, .standard, .normal),
  38. (.dark, .wide, .normal),
  39. (.dark, .icon, .normal),
  40. (.dark, .standard, .pressed),
  41. (.dark, .wide, .pressed),
  42. (.dark, .icon, .pressed),
  43. (.dark, .standard, .disabled),
  44. (.dark, .wide, .disabled),
  45. (.dark, .icon, .disabled),
  46. ]
  47. for styleTuple in stylingTuples {
  48. buttonViewModelAndColor(
  49. scheme: styleTuple.scheme,
  50. style: styleTuple.style,
  51. state: styleTuple.state
  52. ) { viewModel, colors in
  53. XCTAssertEqual(
  54. viewModel.buttonStyle.colors.foregroundColor,
  55. colors.foregroundColor
  56. )
  57. XCTAssertEqual(
  58. viewModel.buttonStyle.colors.backgroundColor,
  59. colors.backgroundColor
  60. )
  61. XCTAssertEqual(
  62. viewModel.buttonStyle.colors.iconColor,
  63. colors.iconColor
  64. )
  65. XCTAssertEqual(
  66. viewModel.buttonStyle.colors.iconBorderColor,
  67. colors.iconBorderColor
  68. )
  69. }
  70. }
  71. }
  72. }
  73. @available(iOS 13.0, macOS 10.15, *)
  74. extension GoogleSignInButtonStylingTests {
  75. func buttonViewModelAndColor(
  76. scheme: GoogleSignInButtonColorScheme,
  77. style: GoogleSignInButtonStyle,
  78. state: GoogleSignInButtonState,
  79. completion: (GoogleSignInButtonViewModel, SignInButtonColor) -> Void
  80. ) {
  81. let vm = GoogleSignInButtonViewModel(
  82. scheme: scheme,
  83. style: style,
  84. state: state
  85. )
  86. let bc = SignInButtonColor(scheme: scheme, state: state)
  87. completion(vm, bc)
  88. }
  89. }