Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
danramteke committed Jun 13, 2019
1 parent 5757fad commit 4dde97e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
16 changes: 15 additions & 1 deletion Sources/DeviceModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

public enum DeviceModel {
public enum DeviceModel: CaseIterable {

case iPhone4, iPhone4S
case iPhone5, iPhone5C, iPhone5S
Expand Down Expand Up @@ -201,3 +201,17 @@ extension DeviceModel {
}
}
}

// MARK: Detecting the Notch

extension DeviceModel {
public var hasNotch: Bool {
switch self {

case .iPhoneX, .iPhoneXS, .iPhoneXSMax, .iPhoneXR:
return true
default:
return false
}
}
}
8 changes: 1 addition & 7 deletions Sources/UIDeviceExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,7 @@ public extension UIDeviceComplete where Base == UIDevice {
}

var hasNotch: Bool {
switch deviceModel {

case .iPhoneX, .iPhoneXS, .iPhoneXSMax, .iPhoneXR:
return true
default:
return false
}
return deviceModel.hasNotch
}
}

Expand Down
11 changes: 10 additions & 1 deletion Tests/UIDeviceExtensionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,14 @@ class UIDeviceExtensionsTests: XCTestCase {
let deviceFamily = DeviceFamily(rawValue: "x86_64")
XCTAssert(deviceFamily == .simulator, "DeviceExtensions - .isSimulator is failing")
}



func testHasNotch() {
let notchModels: [DeviceModel] = [.iPhoneX, .iPhoneXS, .iPhoneXSMax, .iPhoneXR]

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

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

0 comments on commit 4dde97e

Please sign in to comment.