1
1
mirror of https://github.com/robb/Cartography.git synced 2024-10-06 21:47:18 +03:00
Cartography/CartographyTests/PointSpec.swift

78 lines
2.3 KiB
Swift
Raw Normal View History

2015-04-11 00:03:31 +03:00
import Cartography
import Nimble
import Quick
class PointSpec: QuickSpec {
override func spec() {
var window: TestWindow!
2015-07-09 12:44:09 +03:00
var view: TestView!
2015-04-11 00:03:31 +03:00
beforeEach {
window = TestWindow(frame: CGRect(x: 0, y: 0, width: 400, height: 400))
2015-04-11 00:03:31 +03:00
view = TestView(frame: CGRect.zero)
window.addSubview(view)
2015-04-11 00:03:31 +03:00
constrain(view) { view in
view.width == 200
view.height == 200
}
}
describe("LayoutProxy.center") {
it("should support relative equalities") {
2015-07-09 12:44:09 +03:00
constrain(view) { view in
2015-04-11 00:03:31 +03:00
view.center == view.superview!.center
}
window.layoutIfNeeded()
2015-07-09 12:44:09 +03:00
expect(view.frame).to(equal(CGRect(x: 100, y: 100, width: 200, height: 200)))
2015-04-11 00:03:31 +03:00
}
it("should support relative inequalities") {
2015-07-09 12:44:09 +03:00
constrain(view) { view in
2015-04-11 00:03:31 +03:00
view.center <= view.superview!.center
view.center >= view.superview!.center
}
window.layoutIfNeeded()
2015-07-09 12:44:09 +03:00
expect(view.frame).to(equal(CGRect(x: 100, y: 100, width: 200, height: 200)))
2015-04-11 00:03:31 +03:00
}
}
2015-11-10 12:26:20 +03:00
#if os(iOS) || os(tvOS)
2015-04-11 00:03:31 +03:00
describe("on iOS only") {
beforeEach {
view.layoutMargins = UIEdgeInsets(top: 10, left: 20, bottom: 30, right: 40)
}
describe("LayoutProxy.centerWithinMargins") {
it("should support relative equalities") {
2015-07-09 12:44:09 +03:00
constrain(view) { view in
2015-04-11 00:03:31 +03:00
view.centerWithinMargins == view.superview!.center
}
window.layoutIfNeeded()
2015-07-09 12:44:09 +03:00
expect(view.frame).to(equal(CGRect(x: 110, y: 110, width: 200, height: 200)))
2015-04-11 00:03:31 +03:00
}
it("should support relative inequalities") {
2015-07-09 12:44:09 +03:00
constrain(view) { view in
2015-04-11 00:03:31 +03:00
view.centerWithinMargins <= view.superview!.center
view.centerWithinMargins >= view.superview!.center
}
window.layoutIfNeeded()
2015-07-09 12:44:09 +03:00
expect(view.frame).to(equal(CGRect(x: 110, y: 110, width: 200, height: 200)))
2015-04-11 00:03:31 +03:00
}
}
}
#endif
}
}