From 8ed7de214959ffb0274218a614f5263293a6802d Mon Sep 17 00:00:00 2001 From: Nicolas Buquet Date: Thu, 10 Oct 2024 15:23:59 +0200 Subject: [PATCH] Enhance xcodegen project files --- TchapX/SupportingFiles/UnitTests.xctestplan | 32 +++++++ TchapX/SupportingFiles/target-development.yml | 6 +- TchapX/SupportingFiles/target-production.yml | 6 +- TchapX/SupportingFiles/target-staging.yml | 6 +- TchapX/SupportingFiles/target-unitTests.yml | 49 ++++++++++ .../SupportingFiles/NSE/target.yml | 9 +- .../Other/Helpers/MatrixIdFromString.swift | 91 +++++++++++++++++++ .../Other/Helpers/UserDisplayName.swift | 9 ++ .../Sources/UserDisplayNameTests.swift | 19 ++++ .../production/SupportingFiles/NSE/target.yml | 9 +- TchapX/staging/SupportingFiles/NSE/target.yml | 9 +- TchapX/staging/UnitTests/Sources/String.swift | 36 ++++++++ project-tchap-x.yml | 2 + 13 files changed, 262 insertions(+), 21 deletions(-) create mode 100644 TchapX/SupportingFiles/UnitTests.xctestplan create mode 100644 TchapX/SupportingFiles/target-unitTests.yml create mode 100644 TchapX/main/Sources/Other/Helpers/MatrixIdFromString.swift create mode 100644 TchapX/main/Sources/Other/Helpers/UserDisplayName.swift create mode 100644 TchapX/main/UnitTests/Sources/UserDisplayNameTests.swift create mode 100644 TchapX/staging/UnitTests/Sources/String.swift diff --git a/TchapX/SupportingFiles/UnitTests.xctestplan b/TchapX/SupportingFiles/UnitTests.xctestplan new file mode 100644 index 0000000000..0dac0ed927 --- /dev/null +++ b/TchapX/SupportingFiles/UnitTests.xctestplan @@ -0,0 +1,32 @@ +{ + "configurations" : [ + { + "id" : "991CB720-B4D2-4F1F-BB8A-A2C1A717F529", + "name" : "TchapX", + "options" : { + + } + } + ], + "defaultOptions" : { + "defaultTestExecutionTimeAllowance" : 60, + "environmentVariableEntries" : [ + { + "key" : "IS_RUNNING_UNIT_TESTS", + "value" : "1" + } + ], + "testExecutionOrdering" : "random", + "testTimeoutsEnabled" : true + }, + "testTargets" : [ + { + "target" : { + "containerPath" : "container:TchapX.xcodeproj", + "identifier" : "E156D99C308BC583D03697F6", + "name" : "Tchap-Production" + } + } + ], + "version" : 1 +} diff --git a/TchapX/SupportingFiles/target-development.yml b/TchapX/SupportingFiles/target-development.yml index 4bbbea41a9..ad7f2f5b52 100644 --- a/TchapX/SupportingFiles/target-development.yml +++ b/TchapX/SupportingFiles/target-development.yml @@ -113,11 +113,11 @@ targets: settings: base: - PRODUCTION_APP_NAME: Tchap DEVELOPMENT + PRODUCTION_APP_NAME: TchapX DEVELOPMENT BASE_APP_GROUP_IDENTIFIER: fr.gouv.tchapx.dev BASE_BUNDLE_IDENTIFIER: fr.gouv.tchapx.dev - APP_NAME: TchapX-development - APP_DISPLAY_NAME: TchapX-DEVELOPMENT + APP_NAME: TchapX-Development + APP_DISPLAY_NAME: TchapX Development ASSETCATALOG_COMPILER_APPICON_NAME: TchapX-icon PRODUCT_NAME: $(APP_NAME) diff --git a/TchapX/SupportingFiles/target-production.yml b/TchapX/SupportingFiles/target-production.yml index 83d9c7cfa1..a197b1aacf 100644 --- a/TchapX/SupportingFiles/target-production.yml +++ b/TchapX/SupportingFiles/target-production.yml @@ -113,11 +113,11 @@ targets: settings: base: - PRODUCTION_APP_NAME: Tchap PRODUCTION + PRODUCTION_APP_NAME: TchapX PRODUCTION BASE_APP_GROUP_IDENTIFIER: fr.gouv.tchapx BASE_BUNDLE_IDENTIFIER: fr.gouv.tchapx - APP_NAME: TchapX-production - APP_DISPLAY_NAME: TchapX-PRODUCTION + APP_NAME: TchapX-Production + APP_DISPLAY_NAME: TchapX Production PRODUCT_NAME: $(APP_NAME) PRODUCT_BUNDLE_IDENTIFIER: $(BASE_BUNDLE_IDENTIFIER) diff --git a/TchapX/SupportingFiles/target-staging.yml b/TchapX/SupportingFiles/target-staging.yml index dda3b5ba3d..dcabddabcc 100644 --- a/TchapX/SupportingFiles/target-staging.yml +++ b/TchapX/SupportingFiles/target-staging.yml @@ -113,11 +113,11 @@ targets: settings: base: - PRODUCTION_APP_NAME: Tchap STAGING + PRODUCTION_APP_NAME: TchapX STAGING BASE_APP_GROUP_IDENTIFIER: fr.gouv.tchapx.staging BASE_BUNDLE_IDENTIFIER: fr.gouv.tchapx.staging - APP_NAME: TchapX-staging - APP_DISPLAY_NAME: TchapX-STAGING + APP_NAME: TchapX-Staging + APP_DISPLAY_NAME: TchapX Staging PRODUCT_NAME: $(APP_NAME) PRODUCT_BUNDLE_IDENTIFIER: $(BASE_BUNDLE_IDENTIFIER) diff --git a/TchapX/SupportingFiles/target-unitTests.yml b/TchapX/SupportingFiles/target-unitTests.yml new file mode 100644 index 0000000000..9acce375b9 --- /dev/null +++ b/TchapX/SupportingFiles/target-unitTests.yml @@ -0,0 +1,49 @@ +name: TchapX-UnitTests + +schemes: + UnitTests: + analyze: + config: Debug + archive: + config: Release + build: + targets: + TchapX-UnitTests: all + profile: + config: Release + run: + config: Debug + disableMainThreadChecker: false + test: + config: Debug + disableMainThreadChecker: false + gatherCoverageData: true + coverageTargets: + - TchapX-Development + testPlans: + - path: UnitTests.xctestplan + # Don't set it as defaultPlan to avoid conflict with ElementX defaultPlan. + defaultPlan: false + +targets: + TchapX-UnitTests: + type: bundle.unit-test + platform: iOS + + dependencies: + - target: TchapX-Development + + info: + path: ../development/SupportingFiles/Info.plist + + settings: + base: + PRODUCT_NAME: TchapX-UnitTests + PRODUCT_BUNDLE_IDENTIFIER: ${BASE_BUNDLE_IDENTIFIER}.unit.tests + debug: + release: + + sources: +# - path: ../../ElementX/Sources/Other/InfoPlistReader.swift +# - path: ../../Tools/Scripts/Templates/SimpleScreenExample/Tests/Unit + - path: ../main/UnitTests/Sources diff --git a/TchapX/development/SupportingFiles/NSE/target.yml b/TchapX/development/SupportingFiles/NSE/target.yml index 0f78cb4b88..0f542f37ec 100644 --- a/TchapX/development/SupportingFiles/NSE/target.yml +++ b/TchapX/development/SupportingFiles/NSE/target.yml @@ -58,11 +58,11 @@ targets: settings: base: - PRODUCTION_APP_NAME: TchapX-NSE DEVELOPMENT + PRODUCTION_APP_NAME: TchapX-NSE Development BASE_APP_GROUP_IDENTIFIER: fr.gouv.tchapx.dev BASE_BUNDLE_IDENTIFIER: fr.gouv.tchapx.dev - APP_NAME: TchapX-NSE-development - APP_DISPLAY_NAME: TchapX-NSE-DEVELOPMENT + APP_NAME: TchapX-NSE-Development + APP_DISPLAY_NAME: TchapX-NSE Development PRODUCT_NAME: TchapX-NSE-Development PRODUCT_DISPLAY_NAME: $(APP_DISPLAY_NAME) @@ -116,4 +116,5 @@ targets: - path: ../../../../ElementX/Sources/Application/AppSettings.swift - path: ../../../../ElementX/Sources/AppHooks/AppHooks.swift - path: ../../../../ElementX/Sources/AppHooks/Hooks/ClientBuilderHook.swift - - path: ../PrivacyInfo.xcprivacy \ No newline at end of file + - path: ../PrivacyInfo.xcprivacy +# - path: ../../../main/Sources/Other/Helpers/TchapX-String.swift \ No newline at end of file diff --git a/TchapX/main/Sources/Other/Helpers/MatrixIdFromString.swift b/TchapX/main/Sources/Other/Helpers/MatrixIdFromString.swift new file mode 100644 index 0000000000..74b2f15b52 --- /dev/null +++ b/TchapX/main/Sources/Other/Helpers/MatrixIdFromString.swift @@ -0,0 +1,91 @@ +/* + * MIT License + * + * Copyright (c) 2024. DINUM + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE + * OR OTHER DEALINGS IN THE SOFTWARE. + */ + +// +// MatrixIdFromString.swift +// Tchap X +// +// Created by Nicolas Buquet on 03/10/2024. +// Copyright © 2024 Tchap. All rights reserved. +// + +import Foundation + +struct MatrixIdFromString { + private var mxIdString: String + + init(_ mxIdString: String) { + self.mxIdString = mxIdString + } + + /// Get the homeserver name of a matrix identifier. + /// + /// - Returns: the homeserver name, if any, `nil` otherwise. + /// + /// The identifier type may be any matrix identifier type: user id, room id, ... + /// + /// For example in case of "@jean-philippe.martin-modernisation.fr:matrix.test.org", this will return "matrix.test.org". + /// + /// In case of "!AAAAAAA:matrix.test.org", this will return "matrix.test.org". + /// + var homeServerName: Substring { + guard let splitIndex = mxIdString.firstIndex(of: ":") else { + return "" + } + return mxIdString[mxIdString.index(after: splitIndex)...] + } + + /// Get the Tchap display name of the homeserver mentioned in a matrix identifier. + /// + /// - Returns: the Tchap display name of the homeserver. + /// + /// The identifier type may be any matrix identifier type: user id, room id, ... + /// + /// The returned name is capitalized. + /// + /// The Tchap HS display name is the component mentioned before the suffix "tchap.gouv.fr" + /// + /// For example in case of "@jean-philippe.martin-modernisation.fr:name1.tchap.gouv.fr", this will return "Name1". + /// in case of "@jean-philippe.martin-modernisation.fr:agent.name2.tchap.gouv.fr", this will return "Name2". + + var homeServerDisplayName: Substring { + var homeserverName = homeServerName + if homeserverName.hasSuffix("tchap.gouv.fr") { + let homeserverNameComponents = homeserverName.split(separator: ".") + if homeserverNameComponents.count >= 4 { + homeserverName = homeserverNameComponents[homeserverNameComponents.count - 4] + } + } + return homeserverName.prefix(1).localizedCapitalized + homeserverName.localizedLowercase.dropFirst() + } + + /// Tells whether a homeserver name corresponds to an external server or not. + /// + /// - Returns: true if external. + + var isExternalTchapServer: Bool { + mxIdString.isEmpty || mxIdString.hasPrefix("e.") || mxIdString.hasPrefix("agent.externe.") + } + +} diff --git a/TchapX/main/Sources/Other/Helpers/UserDisplayName.swift b/TchapX/main/Sources/Other/Helpers/UserDisplayName.swift new file mode 100644 index 0000000000..76abe336a2 --- /dev/null +++ b/TchapX/main/Sources/Other/Helpers/UserDisplayName.swift @@ -0,0 +1,9 @@ +// +// UserDisplayName.swift +// TchapX +// +// Created by Nicolas Buquet on 09/10/2024. +// Copyright © 2024 Tchap. All rights reserved. +// + +import Foundation diff --git a/TchapX/main/UnitTests/Sources/UserDisplayNameTests.swift b/TchapX/main/UnitTests/Sources/UserDisplayNameTests.swift new file mode 100644 index 0000000000..33f6f864a4 --- /dev/null +++ b/TchapX/main/UnitTests/Sources/UserDisplayNameTests.swift @@ -0,0 +1,19 @@ +// +// UserDisplayNaneTests.swift +// IntegrationTests +// +// Created by Nicolas Buquet on 09/10/2024. +// Copyright © 2024 Tchap. All rights reserved. +// + +import XCTest + +@testable import TchapX_Development + +final class UserDisplayNaneTests: XCTestCase { + func testUserName() { + XCTAssertEqual(MatrixIdFromString("@jean-philippe.martin-modernisation.fr:matrix.test.org").homeServerName, "matrix.test.org") + + } + +} diff --git a/TchapX/production/SupportingFiles/NSE/target.yml b/TchapX/production/SupportingFiles/NSE/target.yml index 0026dd49d1..0782e46aa4 100644 --- a/TchapX/production/SupportingFiles/NSE/target.yml +++ b/TchapX/production/SupportingFiles/NSE/target.yml @@ -58,11 +58,11 @@ targets: settings: base: - PRODUCTION_APP_NAME: TchapX-NSE PRODUCTION + PRODUCTION_APP_NAME: TchapX-NSE Production BASE_APP_GROUP_IDENTIFIER: fr.gouv.tchapx BASE_BUNDLE_IDENTIFIER: fr.gouv.tchapx - APP_NAME: TchapX-NSE-staging - APP_DISPLAY_NAME: TchapX-NSE-PRODUCTION + APP_NAME: TchapX-NSE-Production + APP_DISPLAY_NAME: TchapX-NSE Production PRODUCT_NAME: TchapX-NSE-Production PRODUCT_DISPLAY_NAME: $(APP_DISPLAY_NAME) @@ -116,4 +116,5 @@ targets: - path: ../../../../ElementX/Sources/Application/AppSettings.swift - path: ../../../../ElementX/Sources/AppHooks/AppHooks.swift - path: ../../../../ElementX/Sources/AppHooks/Hooks/ClientBuilderHook.swift - - path: ../PrivacyInfo.xcprivacy \ No newline at end of file + - path: ../PrivacyInfo.xcprivacy +# - path: ../../../main/Sources/Other/Helpers/TchapX-String.swift \ No newline at end of file diff --git a/TchapX/staging/SupportingFiles/NSE/target.yml b/TchapX/staging/SupportingFiles/NSE/target.yml index b76ac07d48..a37f608a39 100644 --- a/TchapX/staging/SupportingFiles/NSE/target.yml +++ b/TchapX/staging/SupportingFiles/NSE/target.yml @@ -58,11 +58,11 @@ targets: settings: base: - PRODUCTION_APP_NAME: TchapX-NSE STAGING + PRODUCTION_APP_NAME: TchapX-NSE Staging BASE_APP_GROUP_IDENTIFIER: fr.gouv.tchapx.staging BASE_BUNDLE_IDENTIFIER: fr.gouv.tchapx.staging - APP_NAME: TchapX-NSE-staging - APP_DISPLAY_NAME: TchapX-NSE-STAGING + APP_NAME: TchapX-NSE-Staging + APP_DISPLAY_NAME: TchapX-NSE Staging PRODUCT_NAME: TchapX-NSE-Staging PRODUCT_DISPLAY_NAME: $(APP_DISPLAY_NAME) @@ -116,4 +116,5 @@ targets: - path: ../../../../ElementX/Sources/Application/AppSettings.swift - path: ../../../../ElementX/Sources/AppHooks/AppHooks.swift - path: ../../../../ElementX/Sources/AppHooks/Hooks/ClientBuilderHook.swift - - path: ../PrivacyInfo.xcprivacy \ No newline at end of file + - path: ../PrivacyInfo.xcprivacy +# - path: ../../../main/Sources/Other/Helpers/TchapX-String.swift \ No newline at end of file diff --git a/TchapX/staging/UnitTests/Sources/String.swift b/TchapX/staging/UnitTests/Sources/String.swift new file mode 100644 index 0000000000..3cd390e927 --- /dev/null +++ b/TchapX/staging/UnitTests/Sources/String.swift @@ -0,0 +1,36 @@ +// +// String.swift +// UnitTests +// +// Created by Nicolas Buquet on 03/10/2024. +// Copyright © 2024 Tchap. All rights reserved. +// + +import XCTest + +final class String: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testExample() throws { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. + // Any test you write for XCTest can be annotated as throws and async. + // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error. + // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards. + } + + func testPerformanceExample() throws { + // This is an example of a performance test case. + self.measure { + // Put the code you want to measure the time of here. + } + } + +} diff --git a/project-tchap-x.yml b/project-tchap-x.yml index d5ae1e0c55..0ff3970534 100644 --- a/project-tchap-x.yml +++ b/project-tchap-x.yml @@ -18,6 +18,7 @@ options: - pattern: TchapX order: - Sources + - UnitTests - Resources - SupportingFiles @@ -34,3 +35,4 @@ include: - path: TchapX/staging/SupportingFiles/NSE/target.yml - path: TchapX/SupportingFiles/target-development.yml - path: TchapX/development/SupportingFiles/NSE/target.yml +- path: TchapX/SupportingFiles/target-unitTests.yml