Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbarela committed Nov 2, 2022
2 parents af0a381 + fe18961 commit 6d32fea
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 13 deletions.
20 changes: 9 additions & 11 deletions Mage/LocationUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,19 @@ public class LocationUtilities: NSObject {
dmsCoordinate.minutes = Int(abs((decimal.truncatingRemainder(dividingBy: 1) * 60.0)))
let seconds = abs(((decimal.truncatingRemainder(dividingBy: 1) * 60.0).truncatingRemainder(dividingBy: 1) * 60.0))
dmsCoordinate.seconds = Int(seconds.rounded())
if dmsCoordinate.seconds == 60 {
dmsCoordinate.minutes = (dmsCoordinate.minutes ?? 0) + 1
dmsCoordinate.seconds = 0
}

if dmsCoordinate.minutes == 60 {
dmsCoordinate.degrees = (dmsCoordinate.degrees ?? 0) + 1
dmsCoordinate.minutes = 0
}
} else if let decimalSeconds = decimalSeconds {
// add the decimal seconds to seconds and round
dmsCoordinate.seconds = Int(Double("\((dmsCoordinate.seconds ?? 0)).\(decimalSeconds)")?.rounded() ?? 0)
}

if dmsCoordinate.seconds == 60 {
dmsCoordinate.minutes = (dmsCoordinate.minutes ?? 0) + 1
dmsCoordinate.seconds = 0
}

if dmsCoordinate.minutes == 60 {
dmsCoordinate.degrees = (dmsCoordinate.degrees ?? 0) + 1
dmsCoordinate.minutes = 0
}

return dmsCoordinate
}

Expand Down
18 changes: 18 additions & 0 deletions MageTests/Categories/LocationUtilitiesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ class LocationUtilitiesTests: QuickSpec {

coordinates = "0° 11' 11\" N"
expect(CLLocationCoordinate2D.parse(coordinate: coordinates)).to(beCloseTo(CLLocationDegrees(0.186388888888889)))

coordinates = "705600N"
expect(CLLocationCoordinate2D.parse(coordinate: coordinates)).to(beCloseTo(CLLocationDegrees(70.9333)))
}

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

coordinates = "0° 11' 11\" N"
expect(LocationUtilities.parseToDMSString(coordinates)).to(equal("0° 11' 11\" N"))

coordinates = "705600N"
expect(LocationUtilities.parseToDMSString(coordinates)).to(equal("70° 56' 00\" N"))

coordinates = "70° 560'"
expect(LocationUtilities.parseToDMSString(coordinates)).to(equal("7° 05' 60\" "))
}

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

it("should parse to DMS 2") {
let coordinate = "70560"
let parsed = LocationUtilities.parseDMS(coordinate: coordinate)
expect(parsed.direction).to(beNil())
expect(parsed.seconds).to(equal(60))
expect(parsed.minutes).to(equal(5))
expect(parsed.degrees).to(equal(7))
}

it("should split the coordinate string") {
var coordinates = "112230N 0151545W"
var parsed = CLLocationCoordinate2D.parse(coordinates: coordinates)
Expand Down
51 changes: 51 additions & 0 deletions MageTests/CoordinateFieldTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,22 @@ class CoordinateFieldTests: KIFSpec {
expect(field.textField.accessibilityLabel).to(equal("Coordinate"))
}

it("should set the text later with zero seconds specified") {
let field = CoordinateField(latitude: true, text: nil, label: "Coordinate", delegate: nil, scheme: MAGEScheme.scheme())
view.addSubview(field);
field.autoPinEdge(toSuperviewEdge: .left);
field.autoPinEdge(toSuperviewEdge: .right);
field.autoAlignAxis(toSuperviewAxis: .horizontal);
expect(field.isHidden).to(beFalse());
expect(field.textField.text).to(equal(""))
expect(field.text).to(equal(""))
field.text = "705600N"
expect(field.textField.text).to(equal("70° 56' 00\" N"))
expect(field.text).to(equal("70° 56' 00\" N"))
expect(field.textField.label.text).to(equal("Coordinate"))
expect(field.textField.accessibilityLabel).to(equal("Coordinate"))
}

it("should enable and disable the field") {
let field = CoordinateField(latitude: true, text: nil, label: "Coordinate", delegate: nil, scheme: MAGEScheme.scheme())
view.addSubview(field);
Expand Down Expand Up @@ -200,6 +216,41 @@ class CoordinateFieldTests: KIFSpec {
expect(delegate.changedValue).to(equal(0.5))
}

it("should edit the field with zero seconds specified and notify the delegate") {
class MockCoordinateFieldDelegate: NSObject, CoordinateFieldDelegate {
var fieldChangedCalled = false;
var changedValue: CLLocationDegrees?
var changedField: CoordinateField?
func fieldValueChanged(coordinate: CLLocationDegrees, field: CoordinateField) {
fieldChangedCalled = true
changedValue = coordinate
changedField = field
}
}

let delegate = MockCoordinateFieldDelegate()
let field = CoordinateField(latitude: true, text: nil, label: "Coordinate", delegate: delegate, scheme: MAGEScheme.scheme())
view.addSubview(field);
field.autoPinEdge(toSuperviewEdge: .left);
field.autoPinEdge(toSuperviewEdge: .right);
field.autoAlignAxis(toSuperviewAxis: .horizontal);
expect(field.isHidden).to(beFalse());
expect(field.textField.text).to(equal(""))
expect(field.text).to(equal(""))
tester().waitForView(withAccessibilityLabel: "Coordinate")
tester().tapView(withAccessibilityLabel: "Coordinate")
expect(field.isEditing).to(beTrue())
tester().enterText(intoCurrentFirstResponder: "705600N")
expect(field.textField.text).to(equal("70° 56' 00\" N"))
expect(field.text).to(equal("70° 56' 00\" N"))
expect(field.textField.label.text).to(equal("Coordinate"))
expect(field.textField.accessibilityLabel).to(equal("Coordinate"))
field.resignFirstResponder()
expect(field.isEditing).to(beFalse())
expect(delegate.fieldChangedCalled).to(beTrue())
expect(delegate.changedValue).to(beCloseTo(70.9333))
}

it("should not start clearing text if multiple directions are entered") {
class MockCoordinateFieldDelegate: NSObject, CoordinateFieldDelegate {
var fieldChangedCalled = false;
Expand Down
4 changes: 2 additions & 2 deletions MageTests/Form/FormBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class FormBuilder {

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

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

0 comments on commit 6d32fea

Please sign in to comment.