mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Fixes vector-im/element-x-ios/issues/117 - Event permalink timeline action
* moved NSRegularExpression outside of the AttributedString builder into the MatrixEntityRegex * fixed eventId v3 regex * added permalink builders for users, room identifiers and aliases, and events * added timeline item permalink contextual menu actions and error alerts * added an app wide ServiceLocator and moved the top level userIndicatorPresenter to it. * added URL constructor that takes a StaticString and returns an non-optional * Include Unit and UI tests in the swiftlint search paths
This commit is contained in:
@@ -181,7 +181,7 @@ class AttributedStringBuilderTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testEventIdLink() async {
|
||||
let eventId = "$eventidentifier:matrix.org"
|
||||
let eventId = "$eventidentifier"
|
||||
let string = "The event is \(eventId)."
|
||||
checkMatrixEntityLinkIn(attributedString: await attributedStringBuilder.fromHTML(string), expected: eventId)
|
||||
checkMatrixEntityLinkIn(attributedString: await attributedStringBuilder.fromPlain(string), expected: eventId)
|
||||
@@ -254,10 +254,8 @@ class AttributedStringBuilderTests: XCTestCase {
|
||||
|
||||
XCTAssertEqual(attributedStringBuilder.blockquoteCoalescedComponentsFrom(attributedString)?.count, 1)
|
||||
|
||||
for run in attributedString.runs {
|
||||
if run.elementX.blockquote != nil {
|
||||
return
|
||||
}
|
||||
for run in attributedString.runs where run.elementX.blockquote ?? false {
|
||||
return
|
||||
}
|
||||
|
||||
XCTFail("Couldn't find blockquote")
|
||||
@@ -280,10 +278,8 @@ class AttributedStringBuilderTests: XCTestCase {
|
||||
|
||||
XCTAssertEqual(attributedStringBuilder.blockquoteCoalescedComponentsFrom(attributedString)?.count, 3)
|
||||
|
||||
for run in attributedString.runs {
|
||||
if run.elementX.blockquote != nil {
|
||||
return
|
||||
}
|
||||
for run in attributedString.runs where run.elementX.blockquote ?? false {
|
||||
return
|
||||
}
|
||||
|
||||
XCTFail("Couldn't find blockquote")
|
||||
@@ -310,10 +306,8 @@ class AttributedStringBuilderTests: XCTestCase {
|
||||
XCTAssertEqual(coalescedComponents.first?.attributedString.runs.count, 3, "Link not present in the component")
|
||||
|
||||
var foundBlockquoteAndLink = false
|
||||
for run in attributedString.runs {
|
||||
if run.elementX.blockquote != nil, run.link != nil {
|
||||
foundBlockquoteAndLink = true
|
||||
}
|
||||
for run in attributedString.runs where run.elementX.blockquote ?? false && run.link != nil {
|
||||
foundBlockquoteAndLink = true
|
||||
}
|
||||
|
||||
XCTAssertNotNil(foundBlockquoteAndLink, "Couldn't find blockquote or link")
|
||||
@@ -336,10 +330,8 @@ class AttributedStringBuilderTests: XCTestCase {
|
||||
XCTAssertEqual(attributedStringBuilder.blockquoteCoalescedComponentsFrom(attributedString)?.count, 1)
|
||||
|
||||
var numberOfBlockquotes = 0
|
||||
for run in attributedString.runs {
|
||||
if run.elementX.blockquote != nil, run.link != nil {
|
||||
numberOfBlockquotes += 1
|
||||
}
|
||||
for run in attributedString.runs where run.elementX.blockquote ?? false && run.link != nil {
|
||||
numberOfBlockquotes += 1
|
||||
}
|
||||
|
||||
XCTAssertEqual(numberOfBlockquotes, 3, "Couldn't find all the blockquotes")
|
||||
@@ -365,10 +357,8 @@ class AttributedStringBuilderTests: XCTestCase {
|
||||
XCTAssertEqual(attributedStringBuilder.blockquoteCoalescedComponentsFrom(attributedString)?.count, 6)
|
||||
|
||||
var numberOfBlockquotes = 0
|
||||
for run in attributedString.runs {
|
||||
if run.elementX.blockquote != nil, run.link != nil {
|
||||
numberOfBlockquotes += 1
|
||||
}
|
||||
for run in attributedString.runs where run.elementX.blockquote ?? false && run.link != nil {
|
||||
numberOfBlockquotes += 1
|
||||
}
|
||||
|
||||
XCTAssertEqual(numberOfBlockquotes, 3, "Couldn't find all the blockquotes")
|
||||
@@ -384,11 +374,9 @@ class AttributedStringBuilderTests: XCTestCase {
|
||||
|
||||
XCTAssertEqual(attributedString.runs.count, 3)
|
||||
|
||||
for run in attributedString.runs {
|
||||
if run.link != nil {
|
||||
XCTAssertEqual(run.link?.path, expected)
|
||||
return
|
||||
}
|
||||
for run in attributedString.runs where run.link != nil {
|
||||
XCTAssertEqual(run.link?.path, expected)
|
||||
return
|
||||
}
|
||||
|
||||
XCTFail("Couldn't find expected value.")
|
||||
|
||||
@@ -33,21 +33,21 @@ class BugReportServiceTests: XCTestCase {
|
||||
files: [])
|
||||
XCTAssertFalse(result.reportUrl.isEmpty)
|
||||
}
|
||||
|
||||
|
||||
func testInitialStateWithRealService() throws {
|
||||
let service = try BugReportService(withBaseUrlString: "https://www.example.com",
|
||||
sentryEndpoint: "mock_sentry_dsn",
|
||||
applicationId: "mock_app_id",
|
||||
session: .mock)
|
||||
let service = BugReportService(withBaseURL: URL(staticString: "https://www.example.com"),
|
||||
sentryURL: URL(staticString: "https://1234@sentry.com/1234"),
|
||||
applicationId: "mock_app_id",
|
||||
session: .mock)
|
||||
XCTAssertFalse(service.crashedLastRun)
|
||||
}
|
||||
|
||||
|
||||
@MainActor func testSubmitBugReportWithRealService() async throws {
|
||||
let service = try BugReportService(withBaseUrlString: "https://www.example.com",
|
||||
sentryEndpoint: "mock_sentry_dsn",
|
||||
applicationId: "mock_app_id",
|
||||
session: .mock)
|
||||
|
||||
let service = BugReportService(withBaseURL: URL(staticString: "https://www.example.com"),
|
||||
sentryURL: URL(staticString: "https://1234@sentry.com/1234"),
|
||||
applicationId: "mock_app_id",
|
||||
session: .mock)
|
||||
|
||||
let result = try await service.submitBugReport(text: "i cannot send message",
|
||||
includeLogs: true,
|
||||
includeCrashLog: true,
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
//
|
||||
// Copyright 2022 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
|
||||
|
||||
class PermalinkBuilderTests: XCTestCase {
|
||||
func testUserIdentifierPermalink() {
|
||||
let userId = "@abcdefghijklmnopqrstuvwxyz1234567890._-=/:matrix.org"
|
||||
|
||||
do {
|
||||
let permalink = try PermalinkBuilder.permalinkTo(userIdentifier: userId)
|
||||
XCTAssertEqual(permalink, URL(string: "\(BuildSettings.permalinkBaseURL)/#/\(userId)"))
|
||||
} catch {
|
||||
XCTFail("User identifier must be valid: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
func testInvalidUserIdentifier() {
|
||||
do {
|
||||
_ = try PermalinkBuilder.permalinkTo(userIdentifier: "This1sN0tV4lid!@#$%^&*()")
|
||||
XCTFail("A permalink should not be created.")
|
||||
} catch {
|
||||
XCTAssertEqual(error as? PermalinkBuilderError, PermalinkBuilderError.invalidUserIdentifier)
|
||||
}
|
||||
}
|
||||
|
||||
func testRoomIdentifierPermalink() throws {
|
||||
let roomId = "!abcdefghijklmnopqrstuvwxyz1234567890:matrix.org"
|
||||
|
||||
do {
|
||||
let permalink = try PermalinkBuilder.permalinkTo(roomIdentifier: roomId)
|
||||
XCTAssertEqual(permalink, URL(string: "\(BuildSettings.permalinkBaseURL)/#/!abcdefghijklmnopqrstuvwxyz1234567890%3Amatrix.org"))
|
||||
} catch {
|
||||
XCTFail("Room identifier must be valid: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
func testInvalidRoomIdentifier() {
|
||||
do {
|
||||
_ = try PermalinkBuilder.permalinkTo(roomIdentifier: "This1sN0tV4lid!@#$%^&*()")
|
||||
XCTFail("A permalink should not be created.")
|
||||
} catch {
|
||||
XCTAssertEqual(error as? PermalinkBuilderError, PermalinkBuilderError.invalidRoomIdentifier)
|
||||
}
|
||||
}
|
||||
|
||||
func testRoomAliasPermalink() throws {
|
||||
let roomAlias = "#abcdefghijklmnopqrstuvwxyz-_.1234567890:matrix.org"
|
||||
|
||||
do {
|
||||
let permalink = try PermalinkBuilder.permalinkTo(roomAlias: roomAlias)
|
||||
XCTAssertEqual(permalink, URL(string: "\(BuildSettings.permalinkBaseURL)/#/%23abcdefghijklmnopqrstuvwxyz-_.1234567890%3Amatrix.org"))
|
||||
} catch {
|
||||
XCTFail("Room alias must be valid: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
func testInvalidRoomAlias() {
|
||||
do {
|
||||
_ = try PermalinkBuilder.permalinkTo(roomAlias: "This1sN0tV4lid!@#$%^&*()")
|
||||
XCTFail("A permalink should not be created.")
|
||||
} catch {
|
||||
XCTAssertEqual(error as? PermalinkBuilderError, PermalinkBuilderError.invalidRoomAlias)
|
||||
}
|
||||
}
|
||||
|
||||
func testEventPermalink() throws {
|
||||
let eventId = "$abcdefghijklmnopqrstuvwxyz1234567890"
|
||||
let roomId = "!abcdefghijklmnopqrstuvwxyz1234567890:matrix.org"
|
||||
|
||||
do {
|
||||
let permalink = try PermalinkBuilder.permalinkTo(eventIdentifier: eventId, roomIdentifier: roomId)
|
||||
XCTAssertEqual(permalink, URL(string: "\(BuildSettings.permalinkBaseURL)/#/!abcdefghijklmnopqrstuvwxyz1234567890%3Amatrix.org/%24abcdefghijklmnopqrstuvwxyz1234567890"))
|
||||
} catch {
|
||||
XCTFail("Room and event identifiers must be valid: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
func testInvalidEventIdentifier() {
|
||||
do {
|
||||
_ = try PermalinkBuilder.permalinkTo(eventIdentifier: "This1sN0tV4lid!@#$%^&*()", roomIdentifier: "")
|
||||
XCTFail("A permalink should not be created.")
|
||||
} catch {
|
||||
XCTAssertEqual(error as? PermalinkBuilderError, PermalinkBuilderError.invalidEventIdentifier)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user