Skip to content

Commit 6d32fea

Browse files
committed
Merge branch 'develop'
2 parents af0a381 + fe18961 commit 6d32fea

File tree

4 files changed

+80
-13
lines changed

4 files changed

+80
-13
lines changed

Mage/LocationUtilities.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,19 @@ public class LocationUtilities: NSObject {
100100
dmsCoordinate.minutes = Int(abs((decimal.truncatingRemainder(dividingBy: 1) * 60.0)))
101101
let seconds = abs(((decimal.truncatingRemainder(dividingBy: 1) * 60.0).truncatingRemainder(dividingBy: 1) * 60.0))
102102
dmsCoordinate.seconds = Int(seconds.rounded())
103+
if dmsCoordinate.seconds == 60 {
104+
dmsCoordinate.minutes = (dmsCoordinate.minutes ?? 0) + 1
105+
dmsCoordinate.seconds = 0
106+
}
107+
108+
if dmsCoordinate.minutes == 60 {
109+
dmsCoordinate.degrees = (dmsCoordinate.degrees ?? 0) + 1
110+
dmsCoordinate.minutes = 0
111+
}
103112
} else if let decimalSeconds = decimalSeconds {
104113
// add the decimal seconds to seconds and round
105114
dmsCoordinate.seconds = Int(Double("\((dmsCoordinate.seconds ?? 0)).\(decimalSeconds)")?.rounded() ?? 0)
106115
}
107-
108-
if dmsCoordinate.seconds == 60 {
109-
dmsCoordinate.minutes = (dmsCoordinate.minutes ?? 0) + 1
110-
dmsCoordinate.seconds = 0
111-
}
112-
113-
if dmsCoordinate.minutes == 60 {
114-
dmsCoordinate.degrees = (dmsCoordinate.degrees ?? 0) + 1
115-
dmsCoordinate.minutes = 0
116-
}
117-
118116
return dmsCoordinate
119117
}
120118

MageTests/Categories/LocationUtilitiesTests.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ class LocationUtilitiesTests: QuickSpec {
132132

133133
coordinates = "0° 11' 11\" N"
134134
expect(CLLocationCoordinate2D.parse(coordinate: coordinates)).to(beCloseTo(CLLocationDegrees(0.186388888888889)))
135+
136+
coordinates = "705600N"
137+
expect(CLLocationCoordinate2D.parse(coordinate: coordinates)).to(beCloseTo(CLLocationDegrees(70.9333)))
135138
}
136139

137140
it("should parse the coordinate string to a DMS string") {
@@ -232,6 +235,12 @@ class LocationUtilitiesTests: QuickSpec {
232235

233236
coordinates = "0° 11' 11\" N"
234237
expect(LocationUtilities.parseToDMSString(coordinates)).to(equal("0° 11' 11\" N"))
238+
239+
coordinates = "705600N"
240+
expect(LocationUtilities.parseToDMSString(coordinates)).to(equal("70° 56' 00\" N"))
241+
242+
coordinates = "70° 560'"
243+
expect(LocationUtilities.parseToDMSString(coordinates)).to(equal("7° 05' 60\" "))
235244
}
236245

237246
it("should parse to DMS") {
@@ -243,6 +252,15 @@ class LocationUtilitiesTests: QuickSpec {
243252
expect(parsed.degrees).to(equal(11))
244253
}
245254

255+
it("should parse to DMS 2") {
256+
let coordinate = "70560"
257+
let parsed = LocationUtilities.parseDMS(coordinate: coordinate)
258+
expect(parsed.direction).to(beNil())
259+
expect(parsed.seconds).to(equal(60))
260+
expect(parsed.minutes).to(equal(5))
261+
expect(parsed.degrees).to(equal(7))
262+
}
263+
246264
it("should split the coordinate string") {
247265
var coordinates = "112230N 0151545W"
248266
var parsed = CLLocationCoordinate2D.parse(coordinates: coordinates)

MageTests/CoordinateFieldTests.swift

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,22 @@ class CoordinateFieldTests: KIFSpec {
112112
expect(field.textField.accessibilityLabel).to(equal("Coordinate"))
113113
}
114114

115+
it("should set the text later with zero seconds specified") {
116+
let field = CoordinateField(latitude: true, text: nil, label: "Coordinate", delegate: nil, scheme: MAGEScheme.scheme())
117+
view.addSubview(field);
118+
field.autoPinEdge(toSuperviewEdge: .left);
119+
field.autoPinEdge(toSuperviewEdge: .right);
120+
field.autoAlignAxis(toSuperviewAxis: .horizontal);
121+
expect(field.isHidden).to(beFalse());
122+
expect(field.textField.text).to(equal(""))
123+
expect(field.text).to(equal(""))
124+
field.text = "705600N"
125+
expect(field.textField.text).to(equal("70° 56' 00\" N"))
126+
expect(field.text).to(equal("70° 56' 00\" N"))
127+
expect(field.textField.label.text).to(equal("Coordinate"))
128+
expect(field.textField.accessibilityLabel).to(equal("Coordinate"))
129+
}
130+
115131
it("should enable and disable the field") {
116132
let field = CoordinateField(latitude: true, text: nil, label: "Coordinate", delegate: nil, scheme: MAGEScheme.scheme())
117133
view.addSubview(field);
@@ -200,6 +216,41 @@ class CoordinateFieldTests: KIFSpec {
200216
expect(delegate.changedValue).to(equal(0.5))
201217
}
202218

219+
it("should edit the field with zero seconds specified and notify the delegate") {
220+
class MockCoordinateFieldDelegate: NSObject, CoordinateFieldDelegate {
221+
var fieldChangedCalled = false;
222+
var changedValue: CLLocationDegrees?
223+
var changedField: CoordinateField?
224+
func fieldValueChanged(coordinate: CLLocationDegrees, field: CoordinateField) {
225+
fieldChangedCalled = true
226+
changedValue = coordinate
227+
changedField = field
228+
}
229+
}
230+
231+
let delegate = MockCoordinateFieldDelegate()
232+
let field = CoordinateField(latitude: true, text: nil, label: "Coordinate", delegate: delegate, scheme: MAGEScheme.scheme())
233+
view.addSubview(field);
234+
field.autoPinEdge(toSuperviewEdge: .left);
235+
field.autoPinEdge(toSuperviewEdge: .right);
236+
field.autoAlignAxis(toSuperviewAxis: .horizontal);
237+
expect(field.isHidden).to(beFalse());
238+
expect(field.textField.text).to(equal(""))
239+
expect(field.text).to(equal(""))
240+
tester().waitForView(withAccessibilityLabel: "Coordinate")
241+
tester().tapView(withAccessibilityLabel: "Coordinate")
242+
expect(field.isEditing).to(beTrue())
243+
tester().enterText(intoCurrentFirstResponder: "705600N")
244+
expect(field.textField.text).to(equal("70° 56' 00\" N"))
245+
expect(field.text).to(equal("70° 56' 00\" N"))
246+
expect(field.textField.label.text).to(equal("Coordinate"))
247+
expect(field.textField.accessibilityLabel).to(equal("Coordinate"))
248+
field.resignFirstResponder()
249+
expect(field.isEditing).to(beFalse())
250+
expect(delegate.fieldChangedCalled).to(beTrue())
251+
expect(delegate.changedValue).to(beCloseTo(70.9333))
252+
}
253+
203254
it("should not start clearing text if multiple directions are entered") {
204255
class MockCoordinateFieldDelegate: NSObject, CoordinateFieldDelegate {
205256
var fieldChangedCalled = false;

MageTests/Form/FormBuilder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class FormBuilder {
3030

3131
do {
3232
let jsonDictionary = try JSONSerialization.jsonObject(with: jsonData, options: .allowFragments) as! [String:Any]
33-
form = Form.createForm(eventId: eventId, formJson: jsonDictionary, context: NSManagedObjectContext.mr_default())!
33+
form = Form.createForm(eventId: eventId, order: 0, formJson: jsonDictionary, context: NSManagedObjectContext.mr_default())!
3434
} catch {
3535
fatalError("Unable to convert jsonFileName to JSON dictionary \(error)")
3636
}
@@ -55,7 +55,7 @@ class FormBuilder {
5555

5656
do {
5757
let jsonDictionary = try JSONSerialization.jsonObject(with: jsonData, options: .allowFragments) as! [String:Any]
58-
form = Form.createForm(eventId: eventId, formJson: jsonDictionary, context: NSManagedObjectContext.mr_default())!
58+
form = Form.createForm(eventId: eventId, order: 0, formJson: jsonDictionary, context: NSManagedObjectContext.mr_default())!
5959
} catch {
6060
fatalError("Unable to convert jsonFileName to JSON dictionary \(error)")
6161
}

0 commit comments

Comments
 (0)