Skip to content

Commit

Permalink
Add new types (#243)
Browse files Browse the repository at this point in the history
* Add new types

* new fixture

* icon -> image

* add back
  • Loading branch information
Bobby Sudekum committed Mar 7, 2018
1 parent 2e9f8d2 commit 9f690d7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
7 changes: 1 addition & 6 deletions MapboxDirections/MBVisualInstructionComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ open class VisualInstructionComponent: NSObject, NSSecureCoding {
*/
@objc public convenience init(maneuverType: ManeuverType, maneuverDirection: ManeuverDirection, json: [String: Any]) {
let text = json["text"] as? String
let type: VisualInstructionComponentType
if let _ = json["delimiter"] as? Bool {
type = .delimiter
} else {
type = .destination
}
let type = VisualInstructionComponentType(description: json["type"] as? String ?? "") ?? .text

let abbreviation = json["abbr"] as? String
let abbreviationPriority = json["abbr_priority"] as? Int ?? NSNotFound
Expand Down
19 changes: 14 additions & 5 deletions MapboxDirections/MBVisualInstructionType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,22 @@ public enum VisualInstructionComponentType: Int, CustomStringConvertible {
/**
The component bears an exit number or the name of a place or street.
*/
case destination
case text

/**
Component contains an image that should be rendered.
*/
case image

public init?(description: String) {
let type: VisualInstructionComponentType
switch description {
case "delimiter":
type = .delimiter
case "destination":
type = .destination
case "icon":
type = .image
case "text":
type = .text
default:
return nil
}
Expand All @@ -35,8 +42,10 @@ public enum VisualInstructionComponentType: Int, CustomStringConvertible {
switch self {
case .delimiter:
return "delimiter"
case .destination:
return "destination"
case .image:
return "icon"
case .text:
return "text"
}
}
}
9 changes: 9 additions & 0 deletions MapboxDirectionsTests/IntructionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ class SpokenInstructionsTests: XCTestCase {
XCTAssertEqual(spokenInstructions[0].distanceAlongStep, 1001.4)
XCTAssertEqual(spokenInstructions[0].ssmlText, "<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">Continue on Baker Street for a half mile</prosody></amazon:effect></speak>")
XCTAssertEqual(spokenInstructions[0].text, "Continue on Baker Street for a half mile")
XCTAssertEqual(spokenInstructions[1].ssmlText, "<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">In a quarter mile, turn left onto Oak Street</prosody></amazon:effect></speak>")
XCTAssertEqual(spokenInstructions[1].text, "In a quarter mile, turn left onto Oak Street")
XCTAssertEqual(spokenInstructions[2].ssmlText, "<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">Turn left onto Oak Street</prosody></amazon:effect></speak>")
XCTAssertEqual(spokenInstructions[2].text, "Turn left onto Oak Street")

let visualInstructions = step.instructionsDisplayedAlongStep

Expand All @@ -79,9 +83,14 @@ class SpokenInstructionsTests: XCTestCase {
XCTAssertEqual(visualInstructions?.first?.distanceAlongStep, 1001.4)
XCTAssertEqual(visualInstructions?.first?.primaryTextComponents.first?.maneuverType, .turn)
XCTAssertEqual(visualInstructions?.first?.primaryTextComponents.first?.maneuverDirection, .left)
XCTAssertEqual(visualInstructions?.first?.primaryTextComponents.first?.type, .text)
XCTAssertEqual(visualInstructions?.first?.primaryTextComponents.first?.abbreviation, "Oak St")
XCTAssertEqual(visualInstructions?.first?.primaryTextComponents.first?.abbreviationPriority, 0)
XCTAssertEqual(visualInstructions?.first?.drivingSide, .right)
XCTAssertNil(visualInstructions?.first?.secondaryText)

XCTAssertEqual(leg.steps[3].instructionsDisplayedAlongStep?.first?.primaryTextComponents[0].type, .image)
XCTAssertEqual(leg.steps[3].instructionsDisplayedAlongStep?.first?.primaryTextComponents[1].type, .delimiter)
XCTAssertEqual(leg.steps[3].instructionsDisplayedAlongStep?.first?.primaryTextComponents[2].type, .image)
}
}

0 comments on commit 9f690d7

Please sign in to comment.