2015-04-11 00:03:31 +03:00
|
|
|
import Cartography
|
|
|
|
|
|
|
|
import Nimble
|
|
|
|
import Quick
|
|
|
|
|
|
|
|
class PointSpec: QuickSpec {
|
|
|
|
override func spec() {
|
2015-09-10 13:57:03 +03:00
|
|
|
var window: TestWindow!
|
2015-07-09 12:44:09 +03:00
|
|
|
var view: TestView!
|
2015-04-11 00:03:31 +03:00
|
|
|
|
|
|
|
beforeEach {
|
2016-09-02 13:55:17 +03:00
|
|
|
window = TestWindow(frame: CGRect(x: 0, y: 0, width: 400, height: 400))
|
2015-04-11 00:03:31 +03:00
|
|
|
|
2016-09-02 13:55:17 +03:00
|
|
|
view = TestView(frame: CGRect.zero)
|
2015-07-05 15:09:34 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2015-09-10 13:57:03 +03:00
|
|
|
window.layoutIfNeeded()
|
2015-07-09 12:44:09 +03:00
|
|
|
|
2016-09-02 13:55:17 +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
|
|
|
|
}
|
|
|
|
|
2015-09-10 13:57:03 +03:00
|
|
|
window.layoutIfNeeded()
|
2015-07-09 12:44:09 +03:00
|
|
|
|
2016-09-02 13:55:17 +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
|
|
|
|
}
|
|
|
|
|
2015-09-10 13:57:03 +03:00
|
|
|
window.layoutIfNeeded()
|
2015-07-09 12:44:09 +03:00
|
|
|
|
2016-09-02 13:55:17 +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
|
|
|
|
}
|
|
|
|
|
2015-09-10 13:57:03 +03:00
|
|
|
window.layoutIfNeeded()
|
2015-07-09 12:44:09 +03:00
|
|
|
|
2016-09-02 13:55:17 +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
|
|
|
|
}
|
|
|
|
}
|