-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Wrap words for better readability * Set minimum OS to iOS 13 * Fix emoji parsing in HTML * Add a smart insights section * Getting closer to smart insights * Created a structure for providing smart insights * Fix tests * Add smart insights tests * Added tests for custom insights adding * Update readme * Add extra documentation * Fix SwiftLint warnings * Add test for unique insights * Revert unneeded UserDefaultsReporter change * Fix linting feedback * Remove todo * Fix CI * Small change to trigger a new CI run * Update README.md Co-authored-by: Kevin Renskers <[email protected]> * Update README.md Co-authored-by: Kevin Renskers <[email protected]> * Remove old reports before running * Remove optional array Co-authored-by: Kevin Renskers <[email protected]>
- Loading branch information
1 parent
0aa85f4
commit 5c6c587
Showing
37 changed files
with
551 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ playground.xcworkspace | |
# Package.pins | ||
# Package.resolved | ||
.build/ | ||
.spm-build/ | ||
|
||
# CocoaPods | ||
# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
DiagnosticsTests/Reporters/SmartInsights/DeviceStorageInsightTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// DeviceStorageInsightTests.swift | ||
// Diagnostics | ||
// | ||
// Created by Antoine van der Lee on 10/02/2022. | ||
// Copyright © 2019 WeTransfer. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import Diagnostics | ||
|
||
final class DeviceStorageInsightTests: XCTestCase { | ||
|
||
func testLowOnStorage() { | ||
let insight = DeviceStorageInsight(freeDiskSpace: 800 * 1000 * 1000, totalDiskSpace: "100GB") | ||
XCTAssertEqual(insight.result, .warn(message: "The user is low on storage (800 MB of 100GB left)")) | ||
} | ||
|
||
func testEnoughStorage() { | ||
let insight = DeviceStorageInsight(freeDiskSpace: 8000 * 1000 * 1000, totalDiskSpace: "100GB") | ||
XCTAssertEqual(insight.result, .success(message: "The user has enough storage (8 GB of 100GB left)")) | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
DiagnosticsTests/Reporters/SmartInsights/SmartInsightsReporterTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// SmartInsightsReporterTests.swift | ||
// Diagnostics | ||
// | ||
// Created by Antoine van der Lee on 10/02/2022. | ||
// Copyright © 2019 WeTransfer. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import Diagnostics | ||
|
||
final class SmartInsightsReporterTests: XCTestCase { | ||
|
||
func testSmartInsightsChapter() throws { | ||
let reporter = SmartInsightsReporter() | ||
let chapter = reporter.report() | ||
XCTAssertEqual(chapter.title, "Smart Insights") | ||
let insightsDictionary = try XCTUnwrap(chapter.diagnostics as? [String: String]) | ||
XCTAssertFalse(insightsDictionary.isEmpty) | ||
} | ||
|
||
func testRemovingDuplicateInsights() throws { | ||
var reporter = SmartInsightsReporter() | ||
let insight = SmartInsight(name: UUID().uuidString, result: .success(message: UUID().uuidString)) | ||
|
||
/// Remove default insights to make this test independent. | ||
reporter.insights.removeAll() | ||
|
||
reporter.insights.append(contentsOf: [insight, insight, insight]) | ||
|
||
let chapter = reporter.report() | ||
XCTAssertEqual(chapter.title, "Smart Insights") | ||
let insightsDictionary = try XCTUnwrap(chapter.diagnostics as? [String: String]) | ||
XCTAssertEqual(insightsDictionary.count, 1, "It should only have one of the custom insights") | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
DiagnosticsTests/Reporters/SmartInsights/UpdateAvailableInsightTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// UpdateAvailableInsightTests.swift | ||
// Diagnostics | ||
// | ||
// Created by Antoine van der Lee on 10/02/2022. | ||
// Copyright © 2019 WeTransfer. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import Diagnostics | ||
import Combine | ||
|
||
final class UpdateAvailableInsightTests: XCTestCase { | ||
|
||
let exampleError = NSError(domain: UUID().uuidString, code: -1, userInfo: nil) | ||
let sampleBundleIdentifier = "com.wetransfer.example.app" | ||
|
||
func testReturningNilIfNoBundleIdentifier() { | ||
XCTAssertNil(UpdateAvailableInsight(bundleIdentifier: nil)) | ||
} | ||
|
||
func testReturningNilIfNoAppMetadataAvailable() { | ||
let publisher: AnyPublisher<AppMetadataResults, Error> = Fail(error: exampleError).eraseToAnyPublisher() | ||
let insight = UpdateAvailableInsight(bundleIdentifier: sampleBundleIdentifier, appMetadataPublisher: publisher) | ||
XCTAssertNil(insight) | ||
} | ||
|
||
func testUserIsOnTheSameVersion() { | ||
let appMetadata = AppMetadataResults(results: [.init(version: "1.0.0")]) | ||
let publisher: AnyPublisher<AppMetadataResults, Error> = Just(appMetadata) | ||
.setFailureType(to: Error.self) | ||
.eraseToAnyPublisher() | ||
|
||
let insight = UpdateAvailableInsight(bundleIdentifier: sampleBundleIdentifier, currentVersion: "1.0.0", appMetadataPublisher: publisher) | ||
XCTAssertEqual(insight?.result, .success(message: "The user is using the latest app version 1.0.0")) | ||
} | ||
|
||
func testUserIsOnANewerVersion() { | ||
let appMetadata = AppMetadataResults(results: [.init(version: "1.0.0")]) | ||
let publisher: AnyPublisher<AppMetadataResults, Error> = Just(appMetadata) | ||
.setFailureType(to: Error.self) | ||
.eraseToAnyPublisher() | ||
|
||
let insight = UpdateAvailableInsight(bundleIdentifier: sampleBundleIdentifier, currentVersion: "2.0.0", appMetadataPublisher: publisher) | ||
XCTAssertEqual(insight?.result, .success(message: "The user is using a newer version 2.0.0")) | ||
} | ||
|
||
func testUserIsOnAnOlderVersion() { | ||
let appMetadata = AppMetadataResults(results: [.init(version: "2.0.0")]) | ||
let publisher: AnyPublisher<AppMetadataResults, Error> = Just(appMetadata) | ||
.setFailureType(to: Error.self) | ||
.eraseToAnyPublisher() | ||
|
||
let insight = UpdateAvailableInsight(bundleIdentifier: sampleBundleIdentifier, currentVersion: "1.0.0", appMetadataPublisher: publisher) | ||
XCTAssertEqual(insight?.result, .warn(message: "The user could update to 2.0.0")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// CustomSmartInsights.swift | ||
// Diagnostics | ||
// | ||
// Created by Antoine van der Lee on 10/02/2022. | ||
// Copyright © 2019 WeTransfer. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Diagnostics | ||
|
||
struct SmartInsightsProvider: SmartInsightsProviding { | ||
func smartInsights(for chapter: DiagnosticsChapter) -> [SmartInsightProviding]? { | ||
guard let html = chapter.diagnostics as? HTML else { return nil } | ||
if html.errorLogs.contains(where: { $0.contains("AppDelegate.ExampleLocalizedError") }) { | ||
return [ | ||
SmartInsight( | ||
name: "Localized data", | ||
result: .warn(message: "An error was found regarding missing localisation.") | ||
) | ||
] | ||
} | ||
return nil | ||
} | ||
} |
Oops, something went wrong.