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:
Stefan Ceriu
2022-12-16 10:02:22 +02:00
committed by GitHub
parent 5b90f37f2e
commit 6f974a4422
39 changed files with 259 additions and 272 deletions
+10 -4
View File
@@ -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