From a651a51e864bdf2efb467f065efb51f15176a111 Mon Sep 17 00:00:00 2001 From: Vincent Neo <23420208+vincentneo@users.noreply.github.com> Date: Thu, 14 Sep 2023 11:39:37 +0800 Subject: [PATCH 1/3] Add iPhone 15 series of devices. --- Sources/DeviceModel.swift | 8 ++++++++ Sources/Identifier.swift | 9 +++++++++ Tests/DeviceModelTests.swift | 19 +++++++++++++++++++ Tests/IdentifierTests.swift | 16 ++++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/Sources/DeviceModel.swift b/Sources/DeviceModel.swift index 4945d85..7951a47 100644 --- a/Sources/DeviceModel.swift +++ b/Sources/DeviceModel.swift @@ -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 @@ -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 } diff --git a/Sources/Identifier.swift b/Sources/Identifier.swift index dbd4f6b..ff73c67 100644 --- a/Sources/Identifier.swift +++ b/Sources/Identifier.swift @@ -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" } diff --git a/Tests/DeviceModelTests.swift b/Tests/DeviceModelTests.swift index caafa9e..df1f4c9 100644 --- a/Tests/DeviceModelTests.swift +++ b/Tests/DeviceModelTests.swift @@ -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 diff --git a/Tests/IdentifierTests.swift b/Tests/IdentifierTests.swift index 4cbba76..1369805 100644 --- a/Tests/IdentifierTests.swift +++ b/Tests/IdentifierTests.swift @@ -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") } From c9d5d6719316d8b35e5f5aba69fccc6539929636 Mon Sep 17 00:00:00 2001 From: Vincent Neo <23420208+vincentneo@users.noreply.github.com> Date: Thu, 14 Sep 2023 11:41:48 +0800 Subject: [PATCH 2/3] Match indentation --- Tests/DeviceModelTests.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/DeviceModelTests.swift b/Tests/DeviceModelTests.swift index df1f4c9..dc0eb21 100644 --- a/Tests/DeviceModelTests.swift +++ b/Tests/DeviceModelTests.swift @@ -487,16 +487,16 @@ 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] - let noNotchModels: [DeviceModel] = DeviceModel.allCases.filter( { !notchModels.contains($0) }) + let noNotchModels: [DeviceModel] = DeviceModel.allCases.filter( { !notchModels.contains($0) }) - notchModels.forEach { XCTAssertTrue($0.hasNotch) } - noNotchModels.forEach { XCTAssertFalse($0.hasNotch) } + notchModels.forEach { XCTAssertTrue($0.hasNotch) } + noNotchModels.forEach { XCTAssertFalse($0.hasNotch) } } } From e7efc9f1bf789461694049cf9281e1d9663983ec Mon Sep 17 00:00:00 2001 From: Vincent Neo <23420208+vincentneo@users.noreply.github.com> Date: Thu, 14 Sep 2023 11:46:21 +0800 Subject: [PATCH 3/3] Seperate dynamic island check, from hasNotch --- Sources/DeviceModel.swift | 14 +++++++++++++- Tests/DeviceModelTests.swift | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Sources/DeviceModel.swift b/Sources/DeviceModel.swift index 7951a47..c9b5682 100644 --- a/Sources/DeviceModel.swift +++ b/Sources/DeviceModel.swift @@ -246,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: diff --git a/Tests/DeviceModelTests.swift b/Tests/DeviceModelTests.swift index dc0eb21..8c8d7d8 100644 --- a/Tests/DeviceModelTests.swift +++ b/Tests/DeviceModelTests.swift @@ -492,11 +492,23 @@ class DeviceModelTests: XCTestCase { .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 withoutModels: [DeviceModel] = DeviceModel.allCases.filter( { !withModels.contains($0) }) + + withModels.forEach { XCTAssertTrue($0.hasDynamicIsland) } + withoutModels.forEach { XCTAssertFalse($0.hasDynamicIsland) } + } }