Tweak priority API's some more and add tests

This commit is contained in:
Robert Payne 2017-02-11 23:09:49 +13:00
parent e17ecbfde8
commit cdea5fee42
2 changed files with 25 additions and 2 deletions

View File

@ -31,8 +31,8 @@
public class ConstraintMakerPriortizable: ConstraintMakerFinalizable {
@discardableResult
public func priority(_ amount: ConstraintPriority, offset: Float = 0) -> ConstraintMakerFinalizable {
self.description.priority = amount.value + offset
public func priority(_ amount: ConstraintPriority) -> ConstraintMakerFinalizable {
self.description.priority = amount.value
return self
}

View File

@ -517,4 +517,27 @@ class SnapKitTests: XCTestCase {
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)
}
}