Skip to content

Commit

Permalink
Merge branch 'main' into WKDeviceComplete
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentneo committed Sep 16, 2023
2 parents f9d8a7b + 51c1070 commit 90ae8a4
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/swift.yml
Expand Up @@ -7,8 +7,8 @@ jobs:
name: Test UIDeviceComplete
runs-on: macos-latest
env:
DEVELOPER_DIR: /Applications/Xcode_12.4.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_14.0.app/Contents/Developer
steps:
- uses: actions/checkout@v2
- name: Test
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -project "UIDeviceComplete.xcodeproj" -scheme "UIDeviceComplete" -destination "OS=14.4,name=iPhone 12 Pro" clean test | xcpretty
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -project "UIDeviceComplete.xcodeproj" -scheme "UIDeviceComplete" -destination "OS=16.0,name=iPhone 14 Pro" clean test | xcpretty
22 changes: 21 additions & 1 deletion Sources/DeviceModel.swift
Expand Up @@ -41,6 +41,8 @@ public enum DeviceModel: CaseIterable {
case iPhone13Pro, iPhone13ProMax
case iPhone14, iPhone14Plus
case iPhone14Pro, iPhone14ProMax
case iPhone15, iPhone15Plus
case iPhone15Pro, iPhone15ProMax

case iPadFirstGen, iPadSecondGen, iPadThirdGen, iPadFourthGen, iPadFifthGen, iPadSixthGen, iPadSeventhGen, iPadEighthGen, iPadNinthGen, iPadTenthGen

Expand Down Expand Up @@ -141,6 +143,12 @@ extension DeviceModel {

case (15, 2): return .iPhone14Pro
case (15, 3): return .iPhone14ProMax

case (15, 4): return .iPhone15
case (15, 5): return .iPhone15Plus

case (16, 1): return .iPhone15Pro
case (16, 2): return .iPhone15ProMax

default: return .unknown
}
Expand Down Expand Up @@ -238,7 +246,19 @@ extension DeviceModel {
return true
case .iPhone13mini, .iPhone13, .iPhone13Pro, .iPhone13ProMax:
return true
case .iPhone14, .iPhone14Plus, .iPhone14Pro, .iPhone14ProMax:
case .iPhone14, .iPhone14Plus:
return true

default:
return false
}
}

public var hasDynamicIsland: Bool {
switch self {
case .iPhone14Pro, .iPhone14ProMax:
return true
case .iPhone15, .iPhone15Plus, .iPhone15Pro, .iPhone15ProMax:
return true

default:
Expand Down
9 changes: 9 additions & 0 deletions Sources/Identifier.swift
Expand Up @@ -179,6 +179,15 @@ extension Identifier: CustomStringConvertible {
case (15, 3):
return "iPhone 14 Pro Max"

case (15, 4):
return "iPhone 15"
case (15, 5):
return "iPhone 15 Plus"
case (16, 1):
return "iPhone 15 Pro"
case (16, 2):
return "iPhone 15 Pro Max"

default:
return "unknown"
}
Expand Down
41 changes: 36 additions & 5 deletions Tests/DeviceModelTests.swift
Expand Up @@ -221,6 +221,25 @@ class DeviceModelTests: XCTestCase {
XCTAssert(deviceModel == .iPhone14ProMax , "DeviceModel - .iPhone14ProMax is failing")
}

func testDeviceModelIPhone15() {
let deviceModel = DeviceModel(identifier: Identifier("iPhone15,4"))
XCTAssert(deviceModel == .iPhone15 , "DeviceModel - .iPhone15 is failing")
}

func testDeviceModelIPhone15Plus() {
let deviceModel = DeviceModel(identifier: Identifier("iPhone15,5"))
XCTAssert(deviceModel == .iPhone15Plus , "DeviceModel - .iPhone15Plus is failing")
}

func testDeviceModelIPhone15Pro() {
let deviceModel = DeviceModel(identifier: Identifier("iPhone16,1"))
XCTAssert(deviceModel == .iPhone15Pro , "DeviceModel - .iPhone15Pro is failing")
}

func testDeviceModelIPhone15ProMax() {
let deviceModel = DeviceModel(identifier: Identifier("iPhone16,2"))
XCTAssert(deviceModel == .iPhone15ProMax , "DeviceModel - .iPhone15ProMax is failing")
}

// MARK: - iPad Device Model tests

Expand Down Expand Up @@ -468,16 +487,28 @@ class DeviceModelTests: XCTestCase {

// MARK: Notch test
func testHasNotch() {
let notchModels: [DeviceModel] = [.iPhoneX,
let notchModels: [DeviceModel] = [.iPhoneX,
.iPhoneXS, .iPhoneXSMax, .iPhoneXR,
.iPhone11, .iPhone11Pro, .iPhone11ProMax,
.iPhone12, .iPhone12Pro, .iPhone12ProMax, .iPhone12mini,
.iPhone13, .iPhone13mini, .iPhone13Pro, .iPhone13ProMax,
.iPhone14, .iPhone14Plus, .iPhone14Pro, .iPhone14ProMax]
.iPhone14, .iPhone14Plus]

let noNotchModels: [DeviceModel] = DeviceModel.allCases.filter( { !notchModels.contains($0) })

notchModels.forEach { XCTAssertTrue($0.hasNotch) }
noNotchModels.forEach { XCTAssertFalse($0.hasNotch) }
}

// MARK: Dynamic Island Test

func testHasDynamicIsland() {
let withModels: [DeviceModel] = [.iPhone14Pro, .iPhone14ProMax,
.iPhone15, .iPhone15Plus, .iPhone15Pro, .iPhone15ProMax]

let noNotchModels: [DeviceModel] = DeviceModel.allCases.filter( { !notchModels.contains($0) })
let withoutModels: [DeviceModel] = DeviceModel.allCases.filter( { !withModels.contains($0) })

notchModels.forEach { XCTAssertTrue($0.hasNotch) }
noNotchModels.forEach { XCTAssertFalse($0.hasNotch) }
withModels.forEach { XCTAssertTrue($0.hasDynamicIsland) }
withoutModels.forEach { XCTAssertFalse($0.hasDynamicIsland) }
}
}
16 changes: 16 additions & 0 deletions Tests/IdentifierTests.swift
Expand Up @@ -66,6 +66,22 @@ class IdentifierTests: XCTestCase {

// MARK: - iPhone String Description tests

func testDisplayStringiPhone16v2() {
XCTAssert(Identifier("iPhone16,2").description == "iPhone 15 Pro Max", "iPhone16,2 is failing to produce a common device model string")
}

func testDisplayStringiPhone16v1() {
XCTAssert(Identifier("iPhone16,1").description == "iPhone 15 Pro", "iPhone16,1 is failing to produce a common device model string")
}

func testDisplayStringiPhone15v5() {
XCTAssert(Identifier("iPhone15,5").description == "iPhone 15 Plus", "iPhone15,5 is failing to produce a common device model string")
}

func testDisplayStringiPhone15v4() {
XCTAssert(Identifier("iPhone15,4").description == "iPhone 15", "iPhone15,4 is failing to produce a common device model string")
}

func testDisplayStringiPhone15v3() {
XCTAssert(Identifier("iPhone15,3").description == "iPhone 14 Pro Max", "iPhone15,3 is failing to produce a common device model string")
}
Expand Down

0 comments on commit 90ae8a4

Please sign in to comment.