Browse Source

Tweak priority API's some more and add tests

Robert Payne 8 years ago
parent
commit
cdea5fee42
2 changed files with 25 additions and 2 deletions
  1. 2 2
      Source/ConstraintMakerPriortizable.swift
  2. 23 0
      Tests/Tests.swift

+ 2 - 2
Source/ConstraintMakerPriortizable.swift

@@ -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
     }
     

+ 23 - 0
Tests/Tests.swift

@@ -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)
+    }
+    
 }