mirror of https://github.com/SnapKit/SnapKit
Tweak priority API's some more and add tests
This commit is contained in:
parent
e17ecbfde8
commit
cdea5fee42
|
@ -31,8 +31,8 @@
|
||||||
public class ConstraintMakerPriortizable: ConstraintMakerFinalizable {
|
public class ConstraintMakerPriortizable: ConstraintMakerFinalizable {
|
||||||
|
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func priority(_ amount: ConstraintPriority, offset: Float = 0) -> ConstraintMakerFinalizable {
|
public func priority(_ amount: ConstraintPriority) -> ConstraintMakerFinalizable {
|
||||||
self.description.priority = amount.value + offset
|
self.description.priority = amount.value
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -517,4 +517,27 @@ class SnapKitTests: XCTestCase {
|
||||||
self.container.snp.setLabel("Hello World")
|
self.container.snp.setLabel("Hello World")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testPriorityShortcuts() {
|
||||||
|
let view = View()
|
||||||
|
self.container.addSubview(view)
|
||||||
|
|
||||||
|
view.snp.remakeConstraints { make in
|
||||||
|
make.left.equalTo(1000.0).priority(.required)
|
||||||
|
}
|
||||||
|
XCTAssertEqual(self.container.snp_constraints.count, 1, "Should have 1 constraint")
|
||||||
|
XCTAssertEqual(self.container.snp_constraints.first?.priority, ConstraintPriority.required.value)
|
||||||
|
|
||||||
|
view.snp.remakeConstraints { make in
|
||||||
|
make.left.equalTo(1000.0).priority(.low)
|
||||||
|
}
|
||||||
|
XCTAssertEqual(self.container.snp_constraints.count, 1, "Should have 1 constraint")
|
||||||
|
XCTAssertEqual(self.container.snp_constraints.first?.priority, ConstraintPriority.low.value)
|
||||||
|
|
||||||
|
view.snp.remakeConstraints { make in
|
||||||
|
make.left.equalTo(1000.0).priority(ConstraintPriority.low.value + 1)
|
||||||
|
}
|
||||||
|
XCTAssertEqual(self.container.snp_constraints.count, 1, "Should have 1 constraint")
|
||||||
|
XCTAssertEqual(self.container.snp_constraints.first?.priority, ConstraintPriority.low.value + 1)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue