GoogleSignInButtonStylingTests.swift 2.8 KB

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