diff --git a/apps/ios/UnitTests/Data/Authored Activities/AuthoredActivityContentTest.swift b/apps/ios/UnitTests/Data/Authored Activities/AuthoredActivityContentTest.swift index c3df9275..d5afbb3b 100644 --- a/apps/ios/UnitTests/Data/Authored Activities/AuthoredActivityContentTest.swift +++ b/apps/ios/UnitTests/Data/Authored Activities/AuthoredActivityContentTest.swift @@ -95,6 +95,99 @@ final class AuthoredActivityContentTest: XCTestCase { XCTAssertEqual(activity.pois.count, 0) // v1 has no POIs } + /// Tests parsing from GPX + /// Using `GPXSoundscapeSharedContentExtensions` v2 + /// And minimal other details + func testParseGPXContentV2_00() throws { + let text = """ + + + required name234 + required description567 + + required author's name!! + + + + + + + activity_id5678 + + scavengerhunt + + 2 + en_US + + + + + + + + + first point + point0 + + + second point + point1 + + + + + + Cool POI + is optional + + +""" + guard let parser = GPXParser(withRawString: text) else { + XCTFail("Failed to initialize GPXParser") + return + } + guard let root = parser.parsedData() else { + XCTFail("Failed to get parsedData") + return + } + guard let activity = AuthoredActivityContent.parse(gpx: root) else { + XCTFail("Failed to create AuthoredActivityContent from GPXRoot") + return + } + + XCTAssertEqual(activity.id, "activity_id5678") // gpxsc:id + XCTAssertEqual(activity.type, AuthoredActivityType.orienteering) + XCTAssertEqual(activity.name, "required name234") + XCTAssertEqual(activity.creator, "required author's name!!") + XCTAssertEqual(activity.locale.identifier, "en_US") + // TODO: availability???? expiration?? image?? + XCTAssertNotNil(activity.availability) + XCTAssertFalse(activity.expires) + + // Note `activity.desc` and `activity.description` are different + // desc comes from the gpxsc:desc tag, whereas description is a generated text description + XCTAssertEqual(activity.desc, "required description567") + + XCTAssertEqual(activity.waypoints.count, 2) + if let wpt0 = activity.waypoints.first, let wpt1 = activity.waypoints.last { + XCTAssertEqual(wpt0.coordinate, CLLocationCoordinate2DMake(0, 0)) + XCTAssertEqual(wpt0.name, "first point") + XCTAssertEqual(wpt0.description, "point0") + XCTAssertEqual(wpt1.coordinate, CLLocationCoordinate2DMake(1, 0)) + XCTAssertEqual(wpt1.name, "second point") + XCTAssertEqual(wpt1.description, "point1") + // TODO: optional waypoint properties + } + + // POIs are the top-level waypoints + XCTAssertEqual(activity.pois.count, 1) + if let poi0 = activity.pois.first { + XCTAssertEqual(poi0.coordinate, CLLocationCoordinate2DMake(0.5, 0)) + XCTAssertEqual(poi0.name, "Cool POI") + XCTAssertEqual(poi0.description, "is optional") + } + } + // TODO: test other stuff }