@@ -36,6 +36,8 @@ final class ConnectivityToolViewModel {
3636 ///
3737 private let siteID : Int64
3838
39+ private var latestTestResult : [ ConnectivityTestResult ] = [ ]
40+
3941 init ( session: SessionManagerProtocol = ServiceLocator . stores. sessionManager) {
4042
4143 let network = AlamofireNetwork ( credentials: session. defaultCredentials, selectedSite: nil , appPasswordSupportState: nil )
@@ -50,14 +52,10 @@ final class ConnectivityToolViewModel {
5052 }
5153 }
5254
53- private var lastResults : [ TestCaseResult ] = [ ]
54-
5555 /// Sequentially runs all connectivity tests defined in `ConnectivityTest`.
5656 /// Provide a `sinceTest` parameter to omit test cases before it..
5757 ///
5858 private func startConnectivityTest( sinceTest: ConnectivityTest = . internetConnection) async {
59-
60- lastResults = [ ]
6159 let supportedTests : [ ConnectivityTest ] = {
6260 if ServiceLocator . stores. isAuthenticatedWithoutWPCom == false {
6361 [ . internetConnection, . wpComServers, . site, . siteOrders, . loadingProducts]
@@ -85,9 +83,9 @@ final class ConnectivityToolViewModel {
8583 // Track test result
8684 trackResponseEvent ( for: testCase, success: testResult. isSuccess, timeTaken: timeTaken)
8785
88- lastResults . append ( TestCaseResult ( test : testCase,
89- result: testResult,
90- timeTaken: timeTaken) )
86+ latestTestResult . append ( ConnectivityTestResult ( testCase : testCase,
87+ result: testResult,
88+ timeTaken: timeTaken) )
9189
9290 // Only continue with another test if the current test was successful.
9391 if !testResult. isSuccess {
@@ -101,11 +99,13 @@ final class ConnectivityToolViewModel {
10199
102100 /// This is not a user facing text but will be part of the Zendesk submission for troubleshooting.
103101 func troubleshootingDescription( ) -> String ? {
104- guard !lastResults . isEmpty else {
102+ guard !latestTestResult . isEmpty else {
105103 return nil
106104 }
107105
108- return lastResults. map { $0. description ( ) } . joined ( )
106+ return latestTestResult. enumerated ( ) . map { index, result in
107+ " ## \( index + 1 ) . " + result. description ( )
108+ } . joined ( )
109109 }
110110
111111 /// Perform the test for a provided test case.
@@ -244,7 +244,9 @@ final class ConnectivityToolViewModel {
244244 UIApplication . shared. open ( WooConstants . URLs. troubleshootErrorLoadingData. asURL ( ) )
245245 ServiceLocator . analytics. track ( event: . ConnectivityTool. readMoreTapped ( ) )
246246 }
247- var readMoreAction = ConnectivityToolCard . ConnectivityState. Action ( title: readMore, systemImage: SystemImages . readMore. rawValue, action: generalTroubleshootAction)
247+ var readMoreAction = ConnectivityToolCard . ConnectivityState. Action ( title: readMore,
248+ systemImage: SystemImages . readMore. rawValue,
249+ action: generalTroubleshootAction)
248250 let jetpackTroubleshootAction = {
249251 UIApplication . shared. open ( WooConstants . URLs. troubleshootJetpackConnection. asURL ( ) )
250252 ServiceLocator . analytics. track ( event: . ConnectivityTool. readMoreTapped ( ) )
@@ -379,15 +381,15 @@ final class ConnectivityToolViewModel {
379381 }
380382}
381383
382- fileprivate struct TestCaseResult {
383- let test : ConnectivityToolViewModel . ConnectivityTest
384+ fileprivate struct ConnectivityTestResult {
385+ let testCase : ConnectivityToolViewModel . ConnectivityTest
384386 let result : ConnectivityToolCard . ConnectivityState
385387 let timeTaken : TimeInterval
386388
387389 /// This is not a user facing text, but will be part of the attachment sent to Zendesk
388390 func description( ) -> String {
389391 let lines : [ String ] = [
390- " ## \( caseName) " ,
392+ caseName,
391393 " Took: \( formattedTimeTaken) " ,
392394 " Result: \( resultDescription) " ,
393395 " "
@@ -402,7 +404,7 @@ fileprivate struct TestCaseResult {
402404
403405 /// This is not a user facing text, but will be part of the attachment sent to Zendesk
404406 private var caseName : String {
405- switch test {
407+ switch testCase {
406408 case . internetConnection: " Internet Connection "
407409 case . wpComServers: " Connecting to WordPress.com Servers "
408410 case . site: " Connecting to your site "
0 commit comments