Skip to content

Commit

Permalink
Add tests for safeArea
Browse files Browse the repository at this point in the history
  • Loading branch information
yysskk committed Oct 17, 2017
1 parent c7ad6db commit 3bff77b
Show file tree
Hide file tree
Showing 5 changed files with 673 additions and 0 deletions.
176 changes: 176 additions & 0 deletions CartographyTests/DimensionSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,181 @@ class DimensionSpec: QuickSpec {
expect(view.frame.height).to(equal(200))
}
}

#if os(iOS) || os(tvOS)
describe("on iOS only") {
beforeEach {
window.layoutMargins = UIEdgeInsets(top: 10, left: 20, bottom: 30, right: 40)
}

if #available(iOS 11.0, *) {
describe("LayoutProxy.safeArea.width") {
it("should support relative equalities") {
constrain(view) { view in
view.width == view.superview!.safeArea.width
}

window.layoutIfNeeded()

expect(view.frame.width).to(equal(400))
}

it("should support relative inequalities") {
constrain(view) { view in
view.width <= view.superview!.safeArea.width
view.width >= view.superview!.safeArea.width
}

window.layoutIfNeeded()

expect(view.frame.width).to(equal(400))
}

it("should support addition") {
constrain(view) { view in
view.width == view.superview!.safeArea.width + 100
}

window.layoutIfNeeded()

expect(view.frame.width).to(equal(500))
}

it("should support subtraction") {
constrain(view) { view in
view.width == view.superview!.safeArea.width - 100
}

window.layoutIfNeeded()

expect(view.frame.width).to(equal(300))
}

it("should support multiplication") {
constrain(view) { view in
view.width == view.superview!.safeArea.width * 2
}

window.layoutIfNeeded()

expect(view.frame.width).to(equal(800))
}

it("should support division") {
constrain(view) { view in
view.width == view.superview!.safeArea.width / 2
}

window.layoutIfNeeded()

expect(view.frame.width).to(equal(200))
}

it("should support complex expressions") {
constrain(view) { view in
view.width == view.superview!.safeArea.width / 2 + 100
}

window.layoutIfNeeded()

expect(view.frame.width).to(equal(300))
}

it("should support numerical equalities") {
constrain(view) { view in
view.width == 200
}

window.layoutIfNeeded()

expect(view.frame.width).to(equal(200))
}
}

describe("LayoutProxy.height") {
it("should support relative equalities") {
constrain(view) { view in
view.height == view.superview!.safeArea.height
}

window.layoutIfNeeded()

expect(view.frame.height).to(equal(400))
}

it("should support relative inequalities") {
constrain(view) { view in
view.height <= view.superview!.safeArea.height
view.height >= view.superview!.safeArea.height
}

window.layoutIfNeeded()

expect(view.frame.height).to(equal(400))
}

it("should support addition") {
constrain(view) { view in
view.height == view.superview!.safeArea.height + 100
}

window.layoutIfNeeded()

expect(view.frame.height).to(equal(500))
}

it("should support subtraction") {
constrain(view) { view in
view.height == view.superview!.safeArea.height - 100
}

window.layoutIfNeeded()

expect(view.frame.height).to(equal(300))
}

it("should support multiplication") {
constrain(view) { view in
view.height == view.superview!.safeArea.height * 2
}

window.layoutIfNeeded()

expect(view.frame.height).to(equal(800))
}

it("should support division") {
constrain(view) { view in
view.height == view.superview!.safeArea.height / 2
}

window.layoutIfNeeded()

expect(view.frame.height).to(equal(200))
}

it("should support complex expressions") {
constrain(view) { view in
view.height == view.superview!.safeArea.height / 2 + 100
}

window.layoutIfNeeded()

expect(view.frame.height).to(equal(300))
}

it("should support numerical equalities") {
constrain(view) { view in
view.height == 200
}

window.layoutIfNeeded()

expect(view.frame.height).to(equal(200))
}
}
}
}
#endif
}
}
Loading

0 comments on commit 3bff77b

Please sign in to comment.