From 12bd687494bd42e1503b0506afbde27d4180dfbc Mon Sep 17 00:00:00 2001 From: Doug <6060466+pixlwave@users.noreply.github.com> Date: Thu, 26 Jun 2025 12:36:13 +0100 Subject: [PATCH] Use mock log files for the BugReportScreenViewModelTests. (#4257) The array could be empty if a previous test deleted the logs. --- .../BugReportScreen/BugReportScreenViewModel.swift | 4 +++- .../Sources/BugReportScreenViewModelTests.swift | 14 +++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ElementX/Sources/Screens/BugReportScreen/BugReportScreenViewModel.swift b/ElementX/Sources/Screens/BugReportScreen/BugReportScreenViewModel.swift index 621040038..a6d102d1d 100644 --- a/ElementX/Sources/Screens/BugReportScreen/BugReportScreenViewModel.swift +++ b/ElementX/Sources/Screens/BugReportScreen/BugReportScreenViewModel.swift @@ -14,7 +14,7 @@ class BugReportScreenViewModel: BugReportScreenViewModelType, BugReportScreenVie private let bugReportService: BugReportServiceProtocol private let clientProxy: ClientProxyProtocol? - private let logFiles = Tracing.logFiles + private let logFiles: [URL] private let actionsSubject: PassthroughSubject = .init() // periphery:ignore - when set to nil this is automatically cancelled @@ -26,10 +26,12 @@ class BugReportScreenViewModel: BugReportScreenViewModelType, BugReportScreenVie init(bugReportService: BugReportServiceProtocol, clientProxy: ClientProxyProtocol?, + logFiles: [URL] = Tracing.logFiles, screenshot: UIImage?, isModallyPresented: Bool) { self.bugReportService = bugReportService self.clientProxy = clientProxy + self.logFiles = logFiles let canSendLogFiles = Self.validate(logFiles) let bindings = BugReportScreenViewStateBindings(reportText: "", sendingLogsEnabled: canSendLogFiles, canContact: false) diff --git a/UnitTests/Sources/BugReportScreenViewModelTests.swift b/UnitTests/Sources/BugReportScreenViewModelTests.swift index fd84ca394..b72a2ec9b 100644 --- a/UnitTests/Sources/BugReportScreenViewModelTests.swift +++ b/UnitTests/Sources/BugReportScreenViewModelTests.swift @@ -11,6 +11,8 @@ import XCTest @MainActor class BugReportScreenViewModelTests: XCTestCase { + let logFiles: [URL] = [URL(filePath: "/path/to/file1.log"), URL(filePath: "/path/to/file2.log")] + enum TestError: Error { case testError } @@ -19,6 +21,7 @@ class BugReportScreenViewModelTests: XCTestCase { let clientProxy = ClientProxyMock(.init(userID: "@mock.client.com")) let viewModel = BugReportScreenViewModel(bugReportService: BugReportServiceMock(), clientProxy: clientProxy, + logFiles: logFiles, screenshot: nil, isModallyPresented: false) let context = viewModel.context @@ -32,6 +35,7 @@ class BugReportScreenViewModelTests: XCTestCase { let clientProxy = ClientProxyMock(.init(userID: "@mock.client.com")) let viewModel = BugReportScreenViewModel(bugReportService: BugReportServiceMock(), clientProxy: clientProxy, + logFiles: logFiles, screenshot: UIImage.actions, isModallyPresented: false) let context = viewModel.context @@ -44,7 +48,9 @@ class BugReportScreenViewModelTests: XCTestCase { let clientProxy = ClientProxyMock(.init(userID: "@mock.client.com")) let viewModel = BugReportScreenViewModel(bugReportService: BugReportServiceMock(), clientProxy: clientProxy, - screenshot: nil, isModallyPresented: false) + logFiles: logFiles, + screenshot: nil, + isModallyPresented: false) let context = viewModel.context XCTAssertNil(context.viewState.screenshot) context.send(viewAction: .attachScreenshot(UIImage.actions)) @@ -64,7 +70,9 @@ class BugReportScreenViewModelTests: XCTestCase { let viewModel = BugReportScreenViewModel(bugReportService: mockService, clientProxy: clientProxy, - screenshot: nil, isModallyPresented: false) + logFiles: logFiles, + screenshot: nil, + isModallyPresented: false) let context = viewModel.context context.reportText = "This will succeed" @@ -86,7 +94,7 @@ class BugReportScreenViewModelTests: XCTestCase { XCTAssertEqual(mockService.submitBugReportProgressListenerReceivedArguments?.bugReport.curve25519, "THECURVEKEYKEY") XCTAssertEqual(mockService.submitBugReportProgressListenerReceivedArguments?.bugReport.ed25519, "THEEDKEYKEY") XCTAssertEqual(mockService.submitBugReportProgressListenerReceivedArguments?.bugReport.text, "This will succeed") - XCTAssertEqual(mockService.submitBugReportProgressListenerReceivedArguments?.bugReport.logFiles?.isEmpty, false) + XCTAssertEqual(mockService.submitBugReportProgressListenerReceivedArguments?.bugReport.logFiles, logFiles) XCTAssertEqual(mockService.submitBugReportProgressListenerReceivedArguments?.bugReport.canContact, false) XCTAssertEqual(mockService.submitBugReportProgressListenerReceivedArguments?.bugReport.githubLabels, []) XCTAssertEqual(mockService.submitBugReportProgressListenerReceivedArguments?.bugReport.files, [])