Render location events in the timeline (#1136)

* Start location integration in the timeline

* Add warning

* Add LocationRoomTimelineView

* Add GeoURI

* Refine LocationRoomTimelineView

* Refine LocationRoomTimelineView

* Add LocationRoomTimelineView previews

* Cleanup code

* Mock reply

* Add FF for location events

* Update project file

* Fix MapLibreStaticMapView placeholder

* Add MapTilerAttribution

* Add LocationPinView

* Fix layout

* Start reply rendering

* Refactor ReplyView.Icon

* Add localisations

* Fix reactions

* Amend GeoURI regex

* Add log

* Fix tests

* Attribution placement refactor

* Cleanup

* Replace NSRegularExpression with a regex

* Cleanup

* Update unit tests

* isMediaType -> shouldFillBubble
This commit is contained in:
Alfonso Grillo
2023-06-23 12:49:35 +02:00
committed by GitHub
parent 40fab35dd7
commit 07a6235fac
27 changed files with 886 additions and 65 deletions
+85
View File
@@ -0,0 +1,85 @@
//
// Copyright 2023 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
@testable import ElementX
import XCTest
final class GeoURITests: XCTestCase {
func testValidPositiveCoordinates() throws {
let string = "geo:53.99803101552848,8.25347900390625;u=10.123"
let uri = try XCTUnwrap(GeoURI(string: string))
XCTAssertEqual(uri.latitude, 53.99803101552848)
XCTAssertEqual(uri.longitude, 8.25347900390625)
XCTAssertEqual(uri.uncertainty, 10.123)
XCTAssertEqual(uri.string, string)
}
func testValidNegativeCoordinates() throws {
let string = "geo:-53.99803101552848,-8.25347900390625;u=10.0"
let uri = try XCTUnwrap(GeoURI(string: string))
XCTAssertEqual(uri.latitude, -53.99803101552848)
XCTAssertEqual(uri.longitude, -8.25347900390625)
XCTAssertEqual(uri.uncertainty, 10)
XCTAssertEqual(uri.string, string)
}
func testValidMixedCoordinates() throws {
let string = "geo:53.99803101552848,-8.25347900390625;u=10.0"
let uri = try XCTUnwrap(GeoURI(string: string))
XCTAssertEqual(uri.latitude, 53.99803101552848)
XCTAssertEqual(uri.longitude, -8.25347900390625)
XCTAssertEqual(uri.uncertainty, 10)
XCTAssertEqual(uri.string, string)
}
func testValidCoordinatesNoUncertainty() throws {
let string = "geo:53.99803101552848,-8.25347900390625"
let uri = try XCTUnwrap(GeoURI(string: string))
XCTAssertEqual(uri.latitude, 53.99803101552848)
XCTAssertEqual(uri.longitude, -8.25347900390625)
XCTAssertNil(uri.uncertainty)
XCTAssertEqual(uri.string, string)
}
func testValidIntegerCoordinates() throws {
let string = "geo:53,-8;u=35"
let uri = try XCTUnwrap(GeoURI(string: string))
XCTAssertEqual(uri.latitude, 53)
XCTAssertEqual(uri.longitude, -8)
XCTAssertEqual(uri.uncertainty, 35)
XCTAssertEqual(uri.string, "geo:53.0,-8.0;u=35.0")
}
func testInvalidURI1() {
let string = "geo:53.99803101552848,-8.25347900390625;" // final ; without a u=number
XCTAssertNil(GeoURI(string: string))
}
func testInvalidURI2() {
let string = "geo:53.99803101552848, -8.25347900390625;" // spaces in the middle
XCTAssertNil(GeoURI(string: string))
}
func testInvalidURI3() {
let string = "geo:+53.99803101552848,-8.25347900390625" // '+' before a number
XCTAssertNil(GeoURI(string: string))
}
func testInvalidURI4() {
let string = "geo:53.99803101552848,-8.25347900390625;u=-20" // u is negative
XCTAssertNil(GeoURI(string: string))
}
}
@@ -34,14 +34,14 @@ class InvitesScreenViewModelTests: XCTestCase {
func testEmptyState() async throws {
setupViewModel()
_ = await context.$viewState.values.first(where: { $0.invites != nil })
_ = await context.$viewState.values.first()
let invites = try XCTUnwrap(context.viewState.invites)
XCTAssertTrue(invites.isEmpty)
}
func testListState() async throws {
setupViewModel(roomSummaries: .mockInvites)
_ = await context.$viewState.values.first(where: { $0.invites != nil })
_ = await context.$viewState.values.first(where: { !$0.invites.isEmpty })
let invites = try XCTUnwrap(context.viewState.invites)
XCTAssertEqual(invites.count, 2)
}