diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index af80a22c3..72a891454 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -93,7 +93,6 @@ 2352C541AF857241489756FF /* MockRoomSummaryProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F7D42E66E939B709C1EC390 /* MockRoomSummaryProvider.swift */; }; 23701DE32ACD6FD40AA992C3 /* MediaUploadingPreprocessorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE203026B9AD3DB412439866 /* MediaUploadingPreprocessorTests.swift */; }; 237FC70AA257B935F53316BA /* SessionVerificationControllerProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = C55D7E514F9DE4E3D72FDCAD /* SessionVerificationControllerProxy.swift */; }; - 23B2CD5A06B16055BDDD0994 /* ApplicationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44D8C8431416EB8DFEC7E235 /* ApplicationTests.swift */; }; 24906A1E82D0046655958536 /* MessageComposer.swift in Sources */ = {isa = PBXBuildFile; fileRef = E18CF12478983A5EB390FB26 /* MessageComposer.swift */; }; 24A75F72EEB7561B82D726FD /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2141693488CE5446BB391964 /* Date.swift */; }; 24BDDD09A90B8BFE3793F3AA /* ClientProxyProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6033779EB37259F27F938937 /* ClientProxyProtocol.swift */; }; @@ -317,6 +316,7 @@ 764AFCC225B044CF5F9B41E5 /* PaginationIndicatorRoomTimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42EEA67A6796BDC2761619C5 /* PaginationIndicatorRoomTimelineView.swift */; }; 76BA28216FBAF83B2D86A027 /* InvitesScreenCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA2A71915C1F075E403F559C /* InvitesScreenCell.swift */; }; 7756C4E90CABE6F14F7920A0 /* BugReportUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6FEA87EA3752203065ECE27 /* BugReportUITests.swift */; }; + 77920AFA8091AC6B9F190C90 /* Signposter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 752A0EB49BF5BCEA37EDF7A3 /* Signposter.swift */; }; 77D7DAA41AAB36800C1F2E2D /* RoomTimelineProviderProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 095AED4CF56DFF3EB7BB84C8 /* RoomTimelineProviderProtocol.swift */; }; 77FACC29F98FE2E65BBB6A5F /* ServerSelectionUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 054F469E433864CC6FE6EE8E /* ServerSelectionUITests.swift */; }; 784592335560C2E91D32D177 /* DeveloperOptionsScreenModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06B098A612DCB5A7358EECD5 /* DeveloperOptionsScreenModels.swift */; }; @@ -368,6 +368,7 @@ 878070573C7BF19E735707B4 /* RoomTimelineItemProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DE8D25D6A91030175D52A20 /* RoomTimelineItemProperties.swift */; }; 87CEDB8A0696F0D5AE2ABB28 /* test_audio.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = D5E26C54362206BBDD096D83 /* test_audio.mp3 */; }; 8810A2A30A68252EBB54EE05 /* HomeScreenModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71BC7CA1BC1041E93077BBA1 /* HomeScreenModels.swift */; }; + 88356DE7F2AD243AB10C7B7A /* Signposter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 752A0EB49BF5BCEA37EDF7A3 /* Signposter.swift */; }; 8868ACFA45E5B5E19514B575 /* LegalInformationScreenUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACCC1874C122E2BBE648B8F5 /* LegalInformationScreenUITests.swift */; }; 88F348E2CB14FF71CBBB665D /* AudioRoomTimelineItemContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7475C5AE20BA896930907EA8 /* AudioRoomTimelineItemContent.swift */; }; 890F0D453FE388756479AC97 /* AnalyticsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C687844F60BFF532D49A994C /* AnalyticsTests.swift */; }; @@ -976,7 +977,6 @@ 42C64A14EE89928207E3B42B /* AnalyticsSettingsScreenModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsSettingsScreenModels.swift; sourceTree = ""; }; 42EEA67A6796BDC2761619C5 /* PaginationIndicatorRoomTimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaginationIndicatorRoomTimelineView.swift; sourceTree = ""; }; 4481799F455B3DA243BDA2AC /* ShareToMapsAppActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareToMapsAppActivity.swift; sourceTree = ""; }; - 44D8C8431416EB8DFEC7E235 /* ApplicationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationTests.swift; sourceTree = ""; }; 450E04B2A976CC4C8CC1807C /* EmoteRoomTimelineItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmoteRoomTimelineItem.swift; sourceTree = ""; }; 4549FCB53F43DB0B278374BC /* TemplateScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemplateScreen.swift; sourceTree = ""; }; 4552D3466B1453F287223ADA /* SwipeRightAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwipeRightAction.swift; sourceTree = ""; }; @@ -1116,6 +1116,7 @@ 7475C5AE20BA896930907EA8 /* AudioRoomTimelineItemContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioRoomTimelineItemContent.swift; sourceTree = ""; }; 748AE77AC3B0A01223033B87 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; 74DD0855F2F76D47E5555082 /* MediaUploadPreviewScreenCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaUploadPreviewScreenCoordinator.swift; sourceTree = ""; }; + 752A0EB49BF5BCEA37EDF7A3 /* Signposter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Signposter.swift; sourceTree = ""; }; 75697AB5E64A12F1F069F511 /* EncryptedHistoryRoomTimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncryptedHistoryRoomTimelineView.swift; sourceTree = ""; }; 75910F5A36EA8FF9BAD08D18 /* MigrationScreenUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MigrationScreenUITests.swift; sourceTree = ""; }; 772334731A8BF8E6D90B194D /* LocationRoomTimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationRoomTimelineView.swift; sourceTree = ""; }; @@ -2119,6 +2120,7 @@ 5445FCE0CE15E634FDC1A2E2 /* AnalyticsService.swift */, A6B891A6DA826E2461DBB40F /* PHGPostHogConfiguration.swift */, 1715E3D7F53C0748AA50C91C /* PostHogAnalyticsClient.swift */, + 752A0EB49BF5BCEA37EDF7A3 /* Signposter.swift */, 3A304097A59704AC9B869EC6 /* Helpers */, ); path = Analytics; @@ -2136,7 +2138,6 @@ isa = PBXGroup; children = ( D33116993D54FADC0C721C1F /* Application.swift */, - 44D8C8431416EB8DFEC7E235 /* ApplicationTests.swift */, 2D256FEE2F1AF1E51D39B622 /* LoginTests.swift */, 9C4048041C1A6B20CB97FD18 /* TestMeasurementParser.swift */, ); @@ -4525,6 +4526,7 @@ 1C8BC70A18060677E295A846 /* ShareToMapsAppActivity.swift in Sources */, 8922219C5C934C4155E8CA50 /* SharedUserDefaultsKeys.swift in Sources */, 274CE3C986841D15FD530BF5 /* ShimmerModifier.swift in Sources */, + 77920AFA8091AC6B9F190C90 /* Signposter.swift in Sources */, 8BC8EF6705A78946C1F22891 /* SoftLogoutScreen.swift in Sources */, A3A7A05E8F9B7EB0E1A09A2A /* SoftLogoutScreenCoordinator.swift in Sources */, F86102DC2C68BBBB0521BAAE /* SoftLogoutScreenModels.swift in Sources */, @@ -4691,9 +4693,9 @@ files = ( DC08ADC41E792086A340A8B3 /* AccessibilityIdentifiers.swift in Sources */, 1702981A8085BE4FB0EC001B /* Application.swift in Sources */, - 23B2CD5A06B16055BDDD0994 /* ApplicationTests.swift in Sources */, 07240B7159A3990C4C2E8FFC /* LoginTests.swift in Sources */, A439B456D0761D6541745CC3 /* NSRegularExpresion.swift in Sources */, + 88356DE7F2AD243AB10C7B7A /* Signposter.swift in Sources */, 290FDB0FFDC2F1DDF660343E /* TestMeasurementParser.swift in Sources */, B444F9C184A377C1B481F07F /* XCUIElement.swift in Sources */, ); diff --git a/ElementX/Sources/Application/AppCoordinator.swift b/ElementX/Sources/Application/AppCoordinator.swift index c283063f7..9d454bee4 100644 --- a/ElementX/Sources/Application/AppCoordinator.swift +++ b/ElementX/Sources/Application/AppCoordinator.swift @@ -353,7 +353,8 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate, navigationSplitCoordinator: navigationSplitCoordinator, bugReportService: ServiceLocator.shared.bugReportService, roomTimelineControllerFactory: RoomTimelineControllerFactory(), - appSettings: ServiceLocator.shared.settings) + appSettings: ServiceLocator.shared.settings, + analytics: ServiceLocator.shared.analytics) userSessionFlowCoordinator.callback = { [weak self] action in switch action { @@ -550,6 +551,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate, } private func startSync() { + ServiceLocator.shared.analytics.signpost.beginSync() guard let userSession else { fatalError("User session not setup") } @@ -574,6 +576,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate, case .startedUpdating: showLoadingIndicator() case .receivedSyncUpdate: + ServiceLocator.shared.analytics.signpost.endSync() ServiceLocator.shared.userIndicatorController.retractIndicatorWithId(identifier) default: break diff --git a/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift index 242fd2be1..ec12aa5a9 100644 --- a/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift @@ -28,6 +28,7 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol { private let bugReportService: BugReportServiceProtocol private let roomTimelineControllerFactory: RoomTimelineControllerFactoryProtocol private let appSettings: AppSettings + private let analytics: AnalyticsService private let stateMachine: UserSessionFlowCoordinatorStateMachine private let roomFlowCoordinator: RoomFlowCoordinator @@ -46,13 +47,15 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol { navigationSplitCoordinator: NavigationSplitCoordinator, bugReportService: BugReportServiceProtocol, roomTimelineControllerFactory: RoomTimelineControllerFactoryProtocol, - appSettings: AppSettings) { + appSettings: AppSettings, + analytics: AnalyticsService) { stateMachine = UserSessionFlowCoordinatorStateMachine() self.userSession = userSession self.navigationSplitCoordinator = navigationSplitCoordinator self.bugReportService = bugReportService self.roomTimelineControllerFactory = roomTimelineControllerFactory self.appSettings = appSettings + self.analytics = analytics sidebarNavigationStackCoordinator = NavigationStackCoordinator(navigationSplitCoordinator: navigationSplitCoordinator) detailNavigationStackCoordinator = NavigationStackCoordinator(navigationSplitCoordinator: navigationSplitCoordinator) @@ -64,8 +67,8 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol { navigationStackCoordinator: detailNavigationStackCoordinator, navigationSplitCoordinator: navigationSplitCoordinator, emojiProvider: EmojiProvider(), - appSettings: ServiceLocator.shared.settings, - analytics: ServiceLocator.shared.analytics, + appSettings: appSettings, + analytics: analytics, userIndicatorController: ServiceLocator.shared.userIndicatorController) setupStateMachine() @@ -73,9 +76,11 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol { roomFlowCoordinator.actions.sink { action in switch action { case .presentedRoom(let roomID): + self.analytics.signpost.beginRoomFlow(roomID) self.stateMachine.processEvent(.selectRoom(roomId: roomID)) case .dismissedRoom: self.stateMachine.processEvent(.deselectRoom) + self.analytics.signpost.endRoomFlow() } } .store(in: &cancellables) diff --git a/ElementX/Sources/Other/AccessibilityIdentifiers.swift b/ElementX/Sources/Other/AccessibilityIdentifiers.swift index 077ee4488..1c9a3bea3 100644 --- a/ElementX/Sources/Other/AccessibilityIdentifiers.swift +++ b/ElementX/Sources/Other/AccessibilityIdentifiers.swift @@ -33,7 +33,9 @@ struct A11yIdentifiers { static let roomMemberDetailsScreen = RoomMemberDetailsScreen() static let createRoomScreen = CreateRoomScreen() static let invitesScreen = InvitesScreen() - + static let welcomeScreen = WelcomeScreen() + static let migrationScreen = MigrationScreen() + struct AnalyticsPromptScreen { let title = "analytics_prompt-title" let enable = "analytics_prompt-enable" @@ -59,8 +61,10 @@ struct A11yIdentifiers { let settings = "home_screen-settings" let signOut = "home_screen-sign_out" let verificationBannerContinue = "home_screen-verification_continue" + + let roomNamePrefix = "home_screen-room_name" func roomName(_ name: String) -> String { - "home_screen-room_name:\(name)" + "\(roomNamePrefix):\(name)" } } @@ -142,4 +146,12 @@ struct A11yIdentifiers { let roomName = "create_room-room_name" let roomTopic = "create_room-room_topic" } + + struct WelcomeScreen { + let letsGo = "welcome_screen-lets_go" + } + + struct MigrationScreen { + let message = "migration_screen-message" + } } diff --git a/ElementX/Sources/Other/SwiftUI/Animation/ShimmerModifier.swift b/ElementX/Sources/Other/SwiftUI/Animation/ShimmerModifier.swift index 57ad49200..4e2c3076b 100644 --- a/ElementX/Sources/Other/SwiftUI/Animation/ShimmerModifier.swift +++ b/ElementX/Sources/Other/SwiftUI/Animation/ShimmerModifier.swift @@ -76,6 +76,7 @@ struct ShimmerOverlay_Previews: PreviewProvider { attributedStringBuilder: AttributedStringBuilder(permalinkBaseURL: ServiceLocator.shared.settings.permalinkBaseURL), selectedRoomPublisher: CurrentValueSubject(nil).asCurrentValuePublisher(), appSettings: ServiceLocator.shared.settings, + analytics: ServiceLocator.shared.analytics, userIndicatorController: ServiceLocator.shared.userIndicatorController) static var previews: some View { diff --git a/ElementX/Sources/Screens/Authentication/AuthenticationCoordinator.swift b/ElementX/Sources/Screens/Authentication/AuthenticationCoordinator.swift index de9bd2a0f..f22827217 100644 --- a/ElementX/Sources/Screens/Authentication/AuthenticationCoordinator.swift +++ b/ElementX/Sources/Screens/Authentication/AuthenticationCoordinator.swift @@ -165,6 +165,7 @@ class AuthenticationCoordinator: CoordinatorProtocol { private func showLoginScreen() { let parameters = LoginScreenCoordinatorParameters(authenticationService: authenticationService, + analytics: analytics, userIndicatorController: userIndicatorController) let coordinator = LoginScreenCoordinator(parameters: parameters) diff --git a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenCoordinator.swift b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenCoordinator.swift index 4e83c67bd..8acad732f 100644 --- a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenCoordinator.swift +++ b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenCoordinator.swift @@ -21,6 +21,7 @@ struct LoginScreenCoordinatorParameters { /// The service used to authenticate the user. let authenticationService: AuthenticationServiceProxyProtocol + let analytics: AnalyticsService let userIndicatorController: UserIndicatorControllerProtocol } @@ -119,15 +120,18 @@ final class LoginScreenCoordinator: CoordinatorProtocol { startLoading(isInteractionBlocking: true) Task { + parameters.analytics.signpost.beginLogin() switch await authenticationService.login(username: username, password: password, initialDeviceName: UIDevice.current.initialDeviceName, deviceID: nil) { case .success(let userSession): callback?(.signedIn(userSession)) + parameters.analytics.signpost.endLogin() stopLoading() case .failure(let error): stopLoading() + parameters.analytics.signpost.endLogin() switch error { case .isOnWaitlist: callback?(.isOnWaitlist(.init(username: username, diff --git a/ElementX/Sources/Screens/HomeScreen/HomeScreenCoordinator.swift b/ElementX/Sources/Screens/HomeScreen/HomeScreenCoordinator.swift index ab23aa9d3..454a3ac73 100644 --- a/ElementX/Sources/Screens/HomeScreen/HomeScreenCoordinator.swift +++ b/ElementX/Sources/Screens/HomeScreen/HomeScreenCoordinator.swift @@ -52,6 +52,7 @@ final class HomeScreenCoordinator: CoordinatorProtocol { attributedStringBuilder: parameters.attributedStringBuilder, selectedRoomPublisher: parameters.selectedRoomPublisher, appSettings: ServiceLocator.shared.settings, + analytics: ServiceLocator.shared.analytics, userIndicatorController: ServiceLocator.shared.userIndicatorController) viewModel.callback = { [weak self] action in diff --git a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift index 934400433..5b96bb47a 100644 --- a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift +++ b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift @@ -23,6 +23,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol private let userSession: UserSessionProtocol private let attributedStringBuilder: AttributedStringBuilderProtocol private let appSettings: AppSettings + private let analytics: AnalyticsService private let userIndicatorController: UserIndicatorControllerProtocol private let roomSummaryProvider: RoomSummaryProviderProtocol? @@ -38,10 +39,12 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol attributedStringBuilder: AttributedStringBuilderProtocol, selectedRoomPublisher: CurrentValuePublisher, appSettings: AppSettings, + analytics: AnalyticsService, userIndicatorController: UserIndicatorControllerProtocol) { self.userSession = userSession self.attributedStringBuilder = attributedStringBuilder self.appSettings = appSettings + self.analytics = analytics self.userIndicatorController = userIndicatorController roomSummaryProvider = userSession.clientProxy.roomSummaryProvider @@ -98,6 +101,11 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol return } + // End the initial sync performance timing once the room list is about to be displayed. + if roomListMode == .rooms, self.state.roomListMode == .skeletons { + analytics.signpost.endSync() + } + self.state.roomListMode = roomListMode MXLog.info("Received room summary provider update, setting view room list mode to \"\(self.state.roomListMode)\"") diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift index 263b09341..a18859b9f 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift @@ -228,6 +228,7 @@ struct HomeScreen_Previews: PreviewProvider { attributedStringBuilder: AttributedStringBuilder(permalinkBaseURL: ServiceLocator.shared.settings.permalinkBaseURL), selectedRoomPublisher: CurrentValueSubject(nil).asCurrentValuePublisher(), appSettings: ServiceLocator.shared.settings, + analytics: ServiceLocator.shared.analytics, userIndicatorController: ServiceLocator.shared.userIndicatorController) return NavigationStack { diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRoomCell.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRoomCell.swift index 7d1fb1b4a..864be144a 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRoomCell.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRoomCell.swift @@ -177,6 +177,7 @@ struct HomeScreenRoomCell_Previews: PreviewProvider { attributedStringBuilder: AttributedStringBuilder(permalinkBaseURL: ServiceLocator.shared.settings.permalinkBaseURL), selectedRoomPublisher: CurrentValueSubject(nil).asCurrentValuePublisher(), appSettings: ServiceLocator.shared.settings, + analytics: ServiceLocator.shared.analytics, userIndicatorController: ServiceLocator.shared.userIndicatorController) let rooms: [HomeScreenRoom] = summaryProvider.roomListPublisher.value.compactMap { summary -> HomeScreenRoom? in diff --git a/ElementX/Sources/Screens/MigrationScreen/View/MigrationScreen.swift b/ElementX/Sources/Screens/MigrationScreen/View/MigrationScreen.swift index f32e3cbc5..7c0eff3ae 100644 --- a/ElementX/Sources/Screens/MigrationScreen/View/MigrationScreen.swift +++ b/ElementX/Sources/Screens/MigrationScreen/View/MigrationScreen.swift @@ -43,6 +43,7 @@ struct MigrationScreen: View { .font(.compound.bodyLG) .multilineTextAlignment(.center) .foregroundColor(.compound.textPrimary) + .accessibilityIdentifier(A11yIdentifiers.migrationScreen.message) } } } diff --git a/ElementX/Sources/Screens/WelcomeScreenScreen/View/WelcomeScreen.swift b/ElementX/Sources/Screens/WelcomeScreenScreen/View/WelcomeScreen.swift index 665992d79..1bfb88ab8 100644 --- a/ElementX/Sources/Screens/WelcomeScreenScreen/View/WelcomeScreen.swift +++ b/ElementX/Sources/Screens/WelcomeScreenScreen/View/WelcomeScreen.swift @@ -94,6 +94,7 @@ struct WelcomeScreen: View { Text(context.viewState.buttonTitle) } .buttonStyle(.elementAction(.xLarge)) + .accessibilityIdentifier(A11yIdentifiers.welcomeScreen.letsGo) } } diff --git a/ElementX/Sources/Services/Analytics/AnalyticsService.swift b/ElementX/Sources/Services/Analytics/AnalyticsService.swift index 68470b365..d93c7da5b 100644 --- a/ElementX/Sources/Services/Analytics/AnalyticsService.swift +++ b/ElementX/Sources/Services/Analytics/AnalyticsService.swift @@ -35,6 +35,10 @@ class AnalyticsService { private let client: AnalyticsClientProtocol private let appSettings: AppSettings private let bugReportService: BugReportServiceProtocol + + /// A signpost client for performance testing the app. This client doesn't respect the + /// `isRunning` state or behave any differently when `start`/`reset` are called. + let signpost = Signposter() init(client: AnalyticsClientProtocol, appSettings: AppSettings, bugReportService: BugReportServiceProtocol) { self.client = client diff --git a/ElementX/Sources/Services/Analytics/Signposter.swift b/ElementX/Sources/Services/Analytics/Signposter.swift new file mode 100644 index 000000000..63d6ef1ba --- /dev/null +++ b/ElementX/Sources/Services/Analytics/Signposter.swift @@ -0,0 +1,84 @@ +// +// 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. +// + +import OSLog + +/// A simple wrapper around OSSignposter for easy performance testing. +class Signposter { + /// The underlying signposter. + private let signposter = OSSignposter(subsystem: subsystem, category: category) + /// A logger instance to capture any errors. + private let logger = Logger(subsystem: subsystem, category: category) + + /// Signpost name constants. + enum Name { + static let login: StaticString = "Login" + static let sync: StaticString = "Sync" + static let roomFlow: StaticString = "RoomFlow" + } + + static let subsystem = "ElementX" + static let category = "PerformanceTests" + + // MARK: - Login + + private var loginState: OSSignpostIntervalState? + + func beginLogin() { + loginState = signposter.beginInterval(Name.login) + } + + func endLogin() { + guard let loginState else { + logger.error("Missing login state.") + return + } + + signposter.endInterval(Name.login, loginState) + self.loginState = nil + } + + // MARK: - Sync + + private var syncState: OSSignpostIntervalState? + + func beginSync() { + syncState = signposter.beginInterval(Name.sync) + } + + func endSync() { + guard let syncState else { return } + + signposter.endInterval(Name.sync, syncState) + self.syncState = nil + } + + // MARK: - Room Flow + + private var roomFlowState: OSSignpostIntervalState? + + func beginRoomFlow(_ name: String) { + roomFlowState = signposter.beginInterval(Name.roomFlow) + signposter.emitEvent("RoomName", "\(name, privacy: .auto(mask: .hash))") + } + + func endRoomFlow() { + guard let roomFlowState else { return } + + signposter.endInterval(Name.roomFlow, roomFlowState) + self.roomFlowState = nil + } +} diff --git a/ElementX/Sources/UITests/UITestsAppCoordinator.swift b/ElementX/Sources/UITests/UITestsAppCoordinator.swift index b41c11b70..753b5dfb6 100644 --- a/ElementX/Sources/UITests/UITestsAppCoordinator.swift +++ b/ElementX/Sources/UITests/UITestsAppCoordinator.swift @@ -78,6 +78,7 @@ class MockScreen: Identifiable { case .login: let navigationStackCoordinator = NavigationStackCoordinator() let coordinator = LoginScreenCoordinator(parameters: .init(authenticationService: MockAuthenticationServiceProxy(), + analytics: ServiceLocator.shared.analytics, userIndicatorController: ServiceLocator.shared.userIndicatorController)) navigationStackCoordinator.setRootCoordinator(coordinator) return navigationStackCoordinator @@ -336,7 +337,8 @@ class MockScreen: Identifiable { navigationSplitCoordinator: navigationSplitCoordinator, bugReportService: BugReportServiceMock(), roomTimelineControllerFactory: MockRoomTimelineControllerFactory(), - appSettings: ServiceLocator.shared.settings) + appSettings: ServiceLocator.shared.settings, + analytics: ServiceLocator.shared.analytics) coordinator.start() diff --git a/IntegrationTests/Sources/ApplicationTests.swift b/IntegrationTests/Sources/ApplicationTests.swift deleted file mode 100644 index e41d3cfaf..000000000 --- a/IntegrationTests/Sources/ApplicationTests.swift +++ /dev/null @@ -1,34 +0,0 @@ -// -// 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. -// - -import XCTest - -class ApplicationTests: XCTestCase { - func testLaunchPerformance() throws { - let parser = TestMeasurementParser() - - parser.capture(testCase: self) { - self.measure(metrics: [XCTApplicationLaunchMetric()]) { - Application.launch() - } - } - - guard let actualDuration = parser.valueForMetric(.appLaunch) else { - XCTFail("Couldn't retrieve app launch duration") - return - } - } -} diff --git a/IntegrationTests/Sources/LoginTests.swift b/IntegrationTests/Sources/LoginTests.swift index 207513cef..a0ea19a45 100644 --- a/IntegrationTests/Sources/LoginTests.swift +++ b/IntegrationTests/Sources/LoginTests.swift @@ -20,7 +20,15 @@ class LoginTests: XCTestCase { func testLoginFlow() throws { let parser = TestMeasurementParser() parser.capture(testCase: self) { - self.measure(metrics: [XCTClockMetric()]) { + let metrics: [XCTMetric] = [ + XCTApplicationLaunchMetric(), + XCTClockMetric(), + XCTOSSignpostMetric(subsystem: Signposter.subsystem, category: Signposter.category, name: "\(Signposter.Name.login)"), + XCTOSSignpostMetric(subsystem: Signposter.subsystem, category: Signposter.category, name: "\(Signposter.Name.sync)"), + XCTOSSignpostMetric(subsystem: Signposter.subsystem, category: Signposter.category, name: "\(Signposter.Name.roomFlow)") + ] + + self.measure(metrics: metrics) { self.runLoginLogoutFlow() } } @@ -47,7 +55,7 @@ class LoginTests: XCTestCase { XCTAssertTrue(homeserverTextField.waitForExistence(timeout: 10.0)) homeserverTextField.clearAndTypeText(app.homeserver) - + let confirmButton = app.buttons[A11yIdentifiers.changeServerScreen.continue] XCTAssertTrue(confirmButton.waitForExistence(timeout: 10.0)) confirmButton.tap() @@ -71,26 +79,27 @@ class LoginTests: XCTestCase { XCTAssertTrue(nextButton.isEnabled) nextButton.tap() - - // Wait for login to finish - let doesNotExistPredicate = NSPredicate(format: "exists == 0") - expectation(for: doesNotExistPredicate, evaluatedWith: nextButton) - // timeout is huge because we're waiting for server actions as well. - waitForExpectations(timeout: 300.0) + sleep(10) - // Handle save password sheet - let savePasswordButton = app.buttons["Save Password"] - if savePasswordButton.waitForExistence(timeout: 10.0) { - savePasswordButton.tap() - } - // Handle analytics prompt screen if app.staticTexts[A11yIdentifiers.analyticsPromptScreen.title].waitForExistence(timeout: 1.0) { + // Wait for login and then handle save password sheet + let savePasswordButton = app.buttons["Save Password"] + if savePasswordButton.waitForExistence(timeout: 10.0) { + savePasswordButton.tap() + } + let enableButton = app.buttons[A11yIdentifiers.analyticsPromptScreen.enable] XCTAssertTrue(enableButton.waitForExistence(timeout: 10.0)) enableButton.tap() } + + // This might come in a different order, wait for both. + let savePasswordButton = app.buttons["Save Password"] + if savePasswordButton.waitForExistence(timeout: 10.0) { + savePasswordButton.tap() + } // Handle the notifications permission alert https://stackoverflow.com/a/58171074/730924 let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard") @@ -99,9 +108,36 @@ class LoginTests: XCTestCase { alertAllowButton.tap() } - let profileButton = app.buttons[A11yIdentifiers.homeScreen.userAvatar] - XCTAssertTrue(profileButton.waitForExistence(timeout: 10.0)) + // Migration screen may be shown as an overlay. + // if that pops up soon enough, we just let that happen and wait + let message = app.staticTexts[A11yIdentifiers.migrationScreen.message] + if message.waitForExistence(timeout: 10.0) { + let doesNotExistPredicate = NSPredicate(format: "exists == 0") + expectation(for: doesNotExistPredicate, evaluatedWith: message) + waitForExpectations(timeout: 300.0) + } + + // Welcome screen may be shown as an overlay. + if app.buttons[A11yIdentifiers.welcomeScreen.letsGo].waitForExistence(timeout: 1.0) { + let goButton = app.buttons[A11yIdentifiers.welcomeScreen.letsGo] + XCTAssertTrue(goButton.waitForExistence(timeout: 1.0)) + goButton.tap() + } + + // Wait for the home screen to become visible. + let profileButton = app.buttons[A11yIdentifiers.homeScreen.userAvatar] + // Timeouts are huge because we're waiting for the server. + XCTAssertTrue(profileButton.waitForExistence(timeout: 300.0)) + + // Open the first room in the list. + let rooms = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH %@", A11yIdentifiers.homeScreen.roomNamePrefix)) + rooms.firstMatch.tap() + // Temporary sleep to get it working. + sleep(20) + // Go back to the home screen. + app.navigationBars.firstMatch.buttons["All Chats"].tap() + // `Failed to scroll to visible (by AX action) Button` https://stackoverflow.com/a/33534187/730924 profileButton.forceTap() diff --git a/IntegrationTests/SupportingFiles/IntegrationTests.xctestplan b/IntegrationTests/SupportingFiles/IntegrationTests.xctestplan index 5619366d9..3bbfab9b1 100644 --- a/IntegrationTests/SupportingFiles/IntegrationTests.xctestplan +++ b/IntegrationTests/SupportingFiles/IntegrationTests.xctestplan @@ -27,8 +27,7 @@ "containerPath" : "container:ElementX.xcodeproj", "identifier" : "D3DB351B7FBE0F49649171FC", "name" : "IntegrationTests" - }, - "testTimeoutsEnabled" : true + } }, "testTargets" : [ { diff --git a/IntegrationTests/SupportingFiles/target.yml b/IntegrationTests/SupportingFiles/target.yml index 7c81c12ff..8714b1303 100644 --- a/IntegrationTests/SupportingFiles/target.yml +++ b/IntegrationTests/SupportingFiles/target.yml @@ -57,3 +57,4 @@ targets: - path: ../../ElementX/Sources/Other/AccessibilityIdentifiers.swift - path: ../../ElementX/Sources/Other/Extensions/XCUIElement.swift - path: ../../ElementX/Sources/Other/Extensions/NSRegularExpresion.swift + - path: ../../ElementX/Sources/Services/Analytics/Signposter.swift diff --git a/Tools/Scripts/parsePerformanceMetrics.sh b/Tools/Scripts/parsePerformanceMetrics.sh index 49a2259ce..46e7e3832 100755 --- a/Tools/Scripts/parsePerformanceMetrics.sh +++ b/Tools/Scripts/parsePerformanceMetrics.sh @@ -12,8 +12,11 @@ NOW=`date -u -Iminutes` # Find all the measurement lines in the file, then strip out the gumph into a CSV-like format. grep ".*measured.*values" $1 | sed -e "s/.*Test Case .*-\[//" -e "s/\]' measured \[/,/" -e "s/\].*values: \[/,/" -e "s/\], performance.*//" -e "s/^/$2,/" \ - -e "s/IntegrationTests.ApplicationTests testLaunchPerformance,Duration (AppLaunch), s/launchPerformance/" \ - -e "s/IntegrationTests.LoginTests testLoginFlow,Clock Monotonic Time, s/loginPerformance/" \ + -e "s/IntegrationTests.LoginTests testLoginFlow,Duration .AppLaunch., s/launchPerformance/" \ + -e "s/IntegrationTests.LoginTests testLoginFlow,Duration .Login., s/loginPerformance/" \ + -e "s/IntegrationTests.LoginTests testLoginFlow,Duration .RoomFlow., s/roomflowPerformance/" \ + -e "s/IntegrationTests.LoginTests testLoginFlow,Duration .Sync., s/syncPerformance/" \ + -e "s/IntegrationTests.LoginTests testLoginFlow,Clock Monotonic Time, s/totalTime/" \ -e "s/^/$NOW,/" # The output should contain fields for the identifier, name, type, unit, then a list of recorded values (normally 5) diff --git a/UnitTests/Sources/HomeScreenViewModelTests.swift b/UnitTests/Sources/HomeScreenViewModelTests.swift index ebbaba431..77ef30f43 100644 --- a/UnitTests/Sources/HomeScreenViewModelTests.swift +++ b/UnitTests/Sources/HomeScreenViewModelTests.swift @@ -35,6 +35,7 @@ class HomeScreenViewModelTests: XCTestCase { attributedStringBuilder: AttributedStringBuilder(permalinkBaseURL: ServiceLocator.shared.settings.permalinkBaseURL), selectedRoomPublisher: CurrentValueSubject(nil).asCurrentValuePublisher(), appSettings: ServiceLocator.shared.settings, + analytics: ServiceLocator.shared.analytics, userIndicatorController: ServiceLocator.shared.userIndicatorController) } diff --git a/fastlane/Fastfile b/fastlane/Fastfile index c688aa941..95a561fcc 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -143,15 +143,16 @@ end lane :integration_tests do create_simulator_if_necessary( - name: "iPhone 13 Pro", - type: "com.apple.CoreSimulator.SimDeviceType.iPhone-13-Pro" + name: "iPhone 14 Pro", + type: "com.apple.CoreSimulator.SimDeviceType.iPhone-14-Pro" ) run_tests( scheme: "IntegrationTests", - devices: ["iPhone 13 Pro"], + devices: ["iPhone 14 Pro"], ensure_devices_found: true, result_bundle: true, + reset_simulator: true, include_simulator_logs: true ) @@ -391,7 +392,7 @@ private_lane :create_simulator_if_necessary do |options| UI.user_error!("Invalid simulator type") unless !simulator_type.to_s.empty? - # Use use a `(` here to avoid matching `iPhone 13 Pro` on `iPhone 13 Pro Max` for example + # Use use a `(` here to avoid matching `iPhone 14 Pro` on `iPhone 14 Pro Max` for example begin sh("xcrun simctl list devices | grep '#{simulator_name} ('") UI.success "Simulator already exists" rescue