From a1b6acd2b237095256f3ca2aff8ac06d151629e4 Mon Sep 17 00:00:00 2001 From: Mike Schreiber Date: Thu, 1 Feb 2024 17:10:10 -0800 Subject: [PATCH 1/3] Restore AvatarTests and enable for SPM --- Package.swift | 7 +++++++ ios/FluentUI.Tests/AvatarTests.swift | 18 ++++++++---------- ios/FluentUI.Tests/ColorTests.swift | 4 ++++ .../DatePickerControllerTests.swift | 4 ++++ ios/FluentUI.Tests/FluentUITests.swift | 4 ++++ ios/FluentUI.Tests/FontTests.swift | 4 ++++ ios/FluentUI.xcodeproj/project.pbxproj | 4 ++++ .../xcschemes/FluentUI-iOS.xcscheme | 2 +- ios/FluentUI/Avatar/Avatar.swift | 6 +++--- 9 files changed, 39 insertions(+), 14 deletions(-) diff --git a/Package.swift b/Package.swift index db4600650b..8d513dd261 100644 --- a/Package.swift +++ b/Package.swift @@ -47,6 +47,13 @@ let package = Package( "TwoLineTitleView/TwoLineTitleView.resources.xcfilelist", ] ), + .testTarget( + name: "FluentUITests-iOS", + dependencies: [ + .target(name: "FluentUI_ios", condition: .when(platforms: [.iOS, .visionOS])), + ], + path: "ios/FluentUI.Tests" + ), .target( name: "FluentUI_macos", path: "macos/FluentUI", diff --git a/ios/FluentUI.Tests/AvatarTests.swift b/ios/FluentUI.Tests/AvatarTests.swift index 1daad5c001..027b2ed74a 100644 --- a/ios/FluentUI.Tests/AvatarTests.swift +++ b/ios/FluentUI.Tests/AvatarTests.swift @@ -4,17 +4,14 @@ // import XCTest -import FluentUI +#if SWIFT_PACKAGE +@testable import FluentUI_ios +#else +@testable import FluentUI +#endif class AvatarTests: XCTestCase { - /// Validates that the number of colors defined for tokens textCalculatedBackgroundColors and textCalculatedForegroundColors are the same. - func testTextCalculatedBackgroundForegroundColorsCount() { - XCTAssertEqual(FluentUIThemeManager.S.MSFAvatarTokens.textCalculatedBackgroundColors.count, - FluentUIThemeManager.S.MSFAvatarTokens.textCalculatedForegroundColors.count, - "Text calculated background and foreground colors should provide the same number of options.") - } - /// Validates that the background and foreground colors for a given index in both arrays (textCalculatedBackgroundColors and textCalculatedForegroundColors tokens) match comparing: /// 1. A color light mode background color with its counterpart dark mode foreground color. The color should be the same (tint40) /// 2. A color light mode foreground color with its counterpart dark mode background color. The color should be the same (shade30) @@ -27,8 +24,9 @@ class AvatarTests: XCTestCase { /// - Background: shade30 /// - Foreground: tint40 func testTextCalculatedBackgroundForegroundColorsMatch() { - let bgColors = FluentUIThemeManager.S.MSFAvatarTokens.textCalculatedBackgroundColors - let fgColors = FluentUIThemeManager.S.MSFAvatarTokens.textCalculatedForegroundColors + let colors = Avatar.CalculatedColors.colors + let bgColors = (0.. + skipped = "NO"> UIColor { let colorSet = colors[hashCode % colors.count] return UIColor(light: GlobalTokens.sharedColor(colorSet, .tint40), @@ -492,7 +492,7 @@ public struct Avatar: View, TokenizedControlView { /// Hash algorithm to determine Avatar color. /// Referenced from: https://github.com/microsoft/fluentui/blob/master/packages/react-components/react-avatar/src/components/Avatar/useAvatar.tsx#L200 /// - Returns: Hash code - private static func hashCode(_ text: NSString) -> Int32 { + static func hashCode(_ text: NSString) -> Int32 { var hash: Int32 = 0 for len in (0.. Date: Fri, 2 Feb 2024 13:38:20 -0800 Subject: [PATCH 2/3] Simplify imports for tests --- Package.swift | 2 +- ios/FluentUI.Tests/AvatarTests.swift | 3 +-- ios/FluentUI.Tests/ColorTests.swift | 3 +-- ios/FluentUI.Tests/DatePickerControllerTests.swift | 3 +-- ios/FluentUI.Tests/FluentUITests.swift | 3 +-- ios/FluentUI.Tests/FontTests.swift | 3 +-- 6 files changed, 6 insertions(+), 11 deletions(-) diff --git a/Package.swift b/Package.swift index 8d513dd261..7df474a470 100644 --- a/Package.swift +++ b/Package.swift @@ -50,7 +50,7 @@ let package = Package( .testTarget( name: "FluentUITests-iOS", dependencies: [ - .target(name: "FluentUI_ios", condition: .when(platforms: [.iOS, .visionOS])), + .target(name: "FluentUI", condition: .when(platforms: [.iOS, .visionOS])), ], path: "ios/FluentUI.Tests" ), diff --git a/ios/FluentUI.Tests/AvatarTests.swift b/ios/FluentUI.Tests/AvatarTests.swift index 027b2ed74a..7d392a8b2a 100644 --- a/ios/FluentUI.Tests/AvatarTests.swift +++ b/ios/FluentUI.Tests/AvatarTests.swift @@ -4,10 +4,9 @@ // import XCTest +@testable import FluentUI #if SWIFT_PACKAGE @testable import FluentUI_ios -#else -@testable import FluentUI #endif class AvatarTests: XCTestCase { diff --git a/ios/FluentUI.Tests/ColorTests.swift b/ios/FluentUI.Tests/ColorTests.swift index 0094ac7d0e..39e3ea2b0b 100644 --- a/ios/FluentUI.Tests/ColorTests.swift +++ b/ios/FluentUI.Tests/ColorTests.swift @@ -4,10 +4,9 @@ // import XCTest +@testable import FluentUI #if SWIFT_PACKAGE @testable import FluentUI_ios -#else -@testable import FluentUI #endif class ColorTests: XCTestCase { diff --git a/ios/FluentUI.Tests/DatePickerControllerTests.swift b/ios/FluentUI.Tests/DatePickerControllerTests.swift index bbfeeb1c61..4ef6780055 100644 --- a/ios/FluentUI.Tests/DatePickerControllerTests.swift +++ b/ios/FluentUI.Tests/DatePickerControllerTests.swift @@ -4,10 +4,9 @@ // import XCTest +@testable import FluentUI #if SWIFT_PACKAGE @testable import FluentUI_ios -#else -@testable import FluentUI #endif class DatePickerControllerTests: XCTestCase { diff --git a/ios/FluentUI.Tests/FluentUITests.swift b/ios/FluentUI.Tests/FluentUITests.swift index d3c45ef2e7..31d44147ed 100644 --- a/ios/FluentUI.Tests/FluentUITests.swift +++ b/ios/FluentUI.Tests/FluentUITests.swift @@ -4,10 +4,9 @@ // import XCTest +@testable import FluentUI #if SWIFT_PACKAGE @testable import FluentUI_ios -#else -@testable import FluentUI #endif class FluentUITests: XCTestCase { diff --git a/ios/FluentUI.Tests/FontTests.swift b/ios/FluentUI.Tests/FontTests.swift index f6bd2fa0e0..f2b21fa6ca 100644 --- a/ios/FluentUI.Tests/FontTests.swift +++ b/ios/FluentUI.Tests/FontTests.swift @@ -5,10 +5,9 @@ import XCTest import SwiftUI +@testable import FluentUI #if SWIFT_PACKAGE @testable import FluentUI_ios -#else -@testable import FluentUI #endif class FontTests: XCTestCase { From 6e82c68eb8425f9970263eebca5ffba5b410a761 Mon Sep 17 00:00:00 2001 From: Mike Schreiber Date: Tue, 6 Feb 2024 15:51:01 -0800 Subject: [PATCH 3/3] Remove SPM test target for the moment --- Package.swift | 7 ------- ios/FluentUI.Tests/AvatarTests.swift | 3 --- ios/FluentUI.Tests/ColorTests.swift | 3 --- ios/FluentUI.Tests/DatePickerControllerTests.swift | 3 --- ios/FluentUI.Tests/FluentUITests.swift | 3 --- ios/FluentUI.Tests/FontTests.swift | 3 --- 6 files changed, 22 deletions(-) diff --git a/Package.swift b/Package.swift index 7df474a470..db4600650b 100644 --- a/Package.swift +++ b/Package.swift @@ -47,13 +47,6 @@ let package = Package( "TwoLineTitleView/TwoLineTitleView.resources.xcfilelist", ] ), - .testTarget( - name: "FluentUITests-iOS", - dependencies: [ - .target(name: "FluentUI", condition: .when(platforms: [.iOS, .visionOS])), - ], - path: "ios/FluentUI.Tests" - ), .target( name: "FluentUI_macos", path: "macos/FluentUI", diff --git a/ios/FluentUI.Tests/AvatarTests.swift b/ios/FluentUI.Tests/AvatarTests.swift index 7d392a8b2a..7a3058a585 100644 --- a/ios/FluentUI.Tests/AvatarTests.swift +++ b/ios/FluentUI.Tests/AvatarTests.swift @@ -5,9 +5,6 @@ import XCTest @testable import FluentUI -#if SWIFT_PACKAGE -@testable import FluentUI_ios -#endif class AvatarTests: XCTestCase { diff --git a/ios/FluentUI.Tests/ColorTests.swift b/ios/FluentUI.Tests/ColorTests.swift index 39e3ea2b0b..f7148ebe08 100644 --- a/ios/FluentUI.Tests/ColorTests.swift +++ b/ios/FluentUI.Tests/ColorTests.swift @@ -5,9 +5,6 @@ import XCTest @testable import FluentUI -#if SWIFT_PACKAGE -@testable import FluentUI_ios -#endif class ColorTests: XCTestCase { diff --git a/ios/FluentUI.Tests/DatePickerControllerTests.swift b/ios/FluentUI.Tests/DatePickerControllerTests.swift index 4ef6780055..26fe92c5c2 100644 --- a/ios/FluentUI.Tests/DatePickerControllerTests.swift +++ b/ios/FluentUI.Tests/DatePickerControllerTests.swift @@ -5,9 +5,6 @@ import XCTest @testable import FluentUI -#if SWIFT_PACKAGE -@testable import FluentUI_ios -#endif class DatePickerControllerTests: XCTestCase { let startDate: Date = NSDate.now diff --git a/ios/FluentUI.Tests/FluentUITests.swift b/ios/FluentUI.Tests/FluentUITests.swift index 31d44147ed..1668d33bbb 100644 --- a/ios/FluentUI.Tests/FluentUITests.swift +++ b/ios/FluentUI.Tests/FluentUITests.swift @@ -5,9 +5,6 @@ import XCTest @testable import FluentUI -#if SWIFT_PACKAGE -@testable import FluentUI_ios -#endif class FluentUITests: XCTestCase { override func setUp() { diff --git a/ios/FluentUI.Tests/FontTests.swift b/ios/FluentUI.Tests/FontTests.swift index f2b21fa6ca..547044d4ca 100644 --- a/ios/FluentUI.Tests/FontTests.swift +++ b/ios/FluentUI.Tests/FontTests.swift @@ -6,9 +6,6 @@ import XCTest import SwiftUI @testable import FluentUI -#if SWIFT_PACKAGE -@testable import FluentUI_ios -#endif class FontTests: XCTestCase {