mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Resetting the app after deletion and cleanup settings (#372)
* Fixes #361 - Reset everything if the app has been deleted since the last run * Cleaned up and renamed the ElementSettings to ApplicationSettings. Removed its singleton and moved it to the service locator. * Moved the ApplicationSettings to the Application folder * Merged together the BuildSettings and ApplicationSettings * Reset the UserDefaults too when resetting the application state * Rename ServiceLocator.applicationSettings to just settings * Fix indentation * Rename ApplicationSettings to AppSettings * Various tweaks following code review * Fix unit tests
This commit is contained in:
@@ -19,10 +19,16 @@ import AnalyticsEvents
|
||||
import XCTest
|
||||
|
||||
class AnalyticsTests: XCTestCase {
|
||||
private var applicationSettings: AppSettings!
|
||||
|
||||
override func setUp() {
|
||||
AppSettings.configureWithSuiteName("io.element.elementx.unitests")
|
||||
AppSettings.reset()
|
||||
applicationSettings = AppSettings()
|
||||
}
|
||||
|
||||
func testAnalyticsPromptNewUser() {
|
||||
// Given a fresh install of the app (without PostHog analytics having been set).
|
||||
ElementSettings.store.removeObject(forKey: ElementSettings.UserDefaultsKeys.enableAnalytics.rawValue)
|
||||
|
||||
// When the user is prompted for analytics.
|
||||
let showPrompt = Analytics.shared.shouldShowAnalyticsPrompt
|
||||
|
||||
@@ -32,7 +38,7 @@ class AnalyticsTests: XCTestCase {
|
||||
|
||||
func testAnalyticsPromptUserDeclinedPostHog() {
|
||||
// Given an existing install of the app where the user previously declined PostHog
|
||||
ElementSettings.shared.enableAnalytics = false
|
||||
applicationSettings.enableAnalytics = false
|
||||
|
||||
// When the user is prompted for analytics
|
||||
let showPrompt = Analytics.shared.shouldShowAnalyticsPrompt
|
||||
@@ -43,7 +49,7 @@ class AnalyticsTests: XCTestCase {
|
||||
|
||||
func testAnalyticsPromptUserAcceptedPostHog() {
|
||||
// Given an existing install of the app where the user previously accepted PostHog
|
||||
ElementSettings.shared.enableAnalytics = true
|
||||
applicationSettings.enableAnalytics = true
|
||||
|
||||
// When the user is prompted for analytics
|
||||
let showPrompt = Analytics.shared.shouldShowAnalyticsPrompt
|
||||
|
||||
@@ -18,12 +18,20 @@
|
||||
import XCTest
|
||||
|
||||
class PermalinkBuilderTests: XCTestCase {
|
||||
private var appSettings: AppSettings!
|
||||
|
||||
override func setUp() {
|
||||
AppSettings.configureWithSuiteName("io.element.elementx.unitests")
|
||||
AppSettings.reset()
|
||||
appSettings = AppSettings()
|
||||
}
|
||||
|
||||
func testUserIdentifierPermalink() {
|
||||
let userId = "@abcdefghijklmnopqrstuvwxyz1234567890._-=/:matrix.org"
|
||||
|
||||
do {
|
||||
let permalink = try PermalinkBuilder.permalinkTo(userIdentifier: userId)
|
||||
XCTAssertEqual(permalink, URL(string: "\(BuildSettings.permalinkBaseURL)/#/\(userId)"))
|
||||
XCTAssertEqual(permalink, URL(string: "\(appSettings.permalinkBaseURL)/#/\(userId)"))
|
||||
} catch {
|
||||
XCTFail("User identifier must be valid: \(error)")
|
||||
}
|
||||
@@ -43,7 +51,7 @@ class PermalinkBuilderTests: XCTestCase {
|
||||
|
||||
do {
|
||||
let permalink = try PermalinkBuilder.permalinkTo(roomIdentifier: roomId)
|
||||
XCTAssertEqual(permalink, URL(string: "\(BuildSettings.permalinkBaseURL)/#/!abcdefghijklmnopqrstuvwxyz1234567890%3Amatrix.org"))
|
||||
XCTAssertEqual(permalink, URL(string: "\(appSettings.permalinkBaseURL)/#/!abcdefghijklmnopqrstuvwxyz1234567890%3Amatrix.org"))
|
||||
} catch {
|
||||
XCTFail("Room identifier must be valid: \(error)")
|
||||
}
|
||||
@@ -63,7 +71,7 @@ class PermalinkBuilderTests: XCTestCase {
|
||||
|
||||
do {
|
||||
let permalink = try PermalinkBuilder.permalinkTo(roomAlias: roomAlias)
|
||||
XCTAssertEqual(permalink, URL(string: "\(BuildSettings.permalinkBaseURL)/#/%23abcdefghijklmnopqrstuvwxyz-_.1234567890%3Amatrix.org"))
|
||||
XCTAssertEqual(permalink, URL(string: "\(appSettings.permalinkBaseURL)/#/%23abcdefghijklmnopqrstuvwxyz-_.1234567890%3Amatrix.org"))
|
||||
} catch {
|
||||
XCTFail("Room alias must be valid: \(error)")
|
||||
}
|
||||
@@ -84,7 +92,7 @@ class PermalinkBuilderTests: XCTestCase {
|
||||
|
||||
do {
|
||||
let permalink = try PermalinkBuilder.permalinkTo(eventIdentifier: eventId, roomIdentifier: roomId)
|
||||
XCTAssertEqual(permalink, URL(string: "\(BuildSettings.permalinkBaseURL)/#/!abcdefghijklmnopqrstuvwxyz1234567890%3Amatrix.org/%24abcdefghijklmnopqrstuvwxyz1234567890"))
|
||||
XCTAssertEqual(permalink, URL(string: "\(appSettings.permalinkBaseURL)/#/!abcdefghijklmnopqrstuvwxyz1234567890%3Amatrix.org/%24abcdefghijklmnopqrstuvwxyz1234567890"))
|
||||
} catch {
|
||||
XCTFail("Room and event identifiers must be valid: \(error)")
|
||||
}
|
||||
|
||||
@@ -56,15 +56,4 @@ class SettingsViewModelTests: XCTestCase {
|
||||
await Task.yield()
|
||||
XCTAssert(correctResult)
|
||||
}
|
||||
|
||||
func testCrash() async throws {
|
||||
var correctResult = false
|
||||
viewModel.callback = { result in
|
||||
correctResult = result == .crash
|
||||
}
|
||||
|
||||
context.send(viewAction: .crash)
|
||||
await Task.yield()
|
||||
XCTAssert(correctResult)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user