mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Add UnitTestsAppCoordinator.
This commit is contained in:
@@ -20,15 +20,12 @@ import XCTest
|
||||
|
||||
@MainActor
|
||||
class AnalyticsSettingsScreenViewModelTests: XCTestCase {
|
||||
private var applicationSettings: AppSettings!
|
||||
private var appSettings: AppSettings { ServiceLocator.shared.settings }
|
||||
private var viewModel: AnalyticsSettingsScreenViewModelProtocol!
|
||||
private var context: AnalyticsSettingsScreenViewModelType.Context!
|
||||
|
||||
@MainActor override func setUpWithError() throws {
|
||||
AppSettings.configureWithSuiteName("io.element.elementx.unitests")
|
||||
AppSettings.reset()
|
||||
applicationSettings = AppSettings()
|
||||
ServiceLocator.shared.register(appSettings: applicationSettings)
|
||||
let analyticsClient = AnalyticsClientMock()
|
||||
analyticsClient.isRunning = false
|
||||
ServiceLocator.shared.register(analytics: Analytics(client: analyticsClient))
|
||||
@@ -42,13 +39,13 @@ class AnalyticsSettingsScreenViewModelTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testOptIn() {
|
||||
applicationSettings.analyticsConsentState = .optedOut
|
||||
appSettings.analyticsConsentState = .optedOut
|
||||
context.send(viewAction: .toggleAnalytics)
|
||||
XCTAssertTrue(context.enableAnalytics)
|
||||
}
|
||||
|
||||
func testOptOut() {
|
||||
applicationSettings.analyticsConsentState = .optedIn
|
||||
appSettings.analyticsConsentState = .optedIn
|
||||
context.send(viewAction: .toggleAnalytics)
|
||||
XCTAssertFalse(context.enableAnalytics)
|
||||
}
|
||||
|
||||
@@ -19,15 +19,13 @@ import AnalyticsEvents
|
||||
import XCTest
|
||||
|
||||
class AnalyticsTests: XCTestCase {
|
||||
private var applicationSettings: AppSettings!
|
||||
private var appSettings: AppSettings { ServiceLocator.shared.settings }
|
||||
private var analyticsClient: AnalyticsClientMock!
|
||||
private var bugReportService: BugReportServiceMock!
|
||||
|
||||
override func setUp() {
|
||||
AppSettings.configureWithSuiteName("io.element.elementx.unitests")
|
||||
AppSettings.reset()
|
||||
applicationSettings = AppSettings()
|
||||
ServiceLocator.shared.register(appSettings: applicationSettings)
|
||||
|
||||
bugReportService = BugReportServiceMock()
|
||||
bugReportService.isRunning = false
|
||||
ServiceLocator.shared.register(bugReportService: bugReportService)
|
||||
@@ -47,7 +45,7 @@ class AnalyticsTests: XCTestCase {
|
||||
|
||||
func testAnalyticsPromptUserDeclinedPostHog() {
|
||||
// Given an existing install of the app where the user previously declined PostHog
|
||||
applicationSettings.analyticsConsentState = .optedOut
|
||||
appSettings.analyticsConsentState = .optedOut
|
||||
|
||||
// When the user is prompted for analytics
|
||||
let showPrompt = ServiceLocator.shared.analytics.shouldShowAnalyticsPrompt
|
||||
@@ -58,7 +56,7 @@ class AnalyticsTests: XCTestCase {
|
||||
|
||||
func testAnalyticsPromptUserAcceptedPostHog() {
|
||||
// Given an existing install of the app where the user previously accepted PostHog
|
||||
applicationSettings.analyticsConsentState = .optedIn
|
||||
appSettings.analyticsConsentState = .optedIn
|
||||
|
||||
// When the user is prompted for analytics
|
||||
let showPrompt = ServiceLocator.shared.analytics.shouldShowAnalyticsPrompt
|
||||
@@ -81,7 +79,7 @@ class AnalyticsTests: XCTestCase {
|
||||
// When analytics is opt-out
|
||||
ServiceLocator.shared.analytics.optOut()
|
||||
// Then analytics should be disabled
|
||||
XCTAssertEqual(applicationSettings.analyticsConsentState, .optedOut)
|
||||
XCTAssertEqual(appSettings.analyticsConsentState, .optedOut)
|
||||
XCTAssertFalse(ServiceLocator.shared.analytics.isEnabled)
|
||||
XCTAssertFalse(ServiceLocator.shared.analytics.isRunning)
|
||||
XCTAssertFalse(analyticsClient.isRunning)
|
||||
@@ -96,7 +94,7 @@ class AnalyticsTests: XCTestCase {
|
||||
// When analytics is opt-in
|
||||
ServiceLocator.shared.analytics.optIn()
|
||||
// The analytics should be enabled
|
||||
XCTAssertEqual(applicationSettings.analyticsConsentState, .optedIn)
|
||||
XCTAssertEqual(appSettings.analyticsConsentState, .optedIn)
|
||||
XCTAssertTrue(ServiceLocator.shared.analytics.isEnabled)
|
||||
// Analytics client and the bug report service should have been started
|
||||
XCTAssertTrue(analyticsClient.startCalled)
|
||||
@@ -105,7 +103,7 @@ class AnalyticsTests: XCTestCase {
|
||||
|
||||
func testAnalyticsStartIfNotEnabled() {
|
||||
// Given an existing install of the app where the user previously declined the tracking
|
||||
applicationSettings.analyticsConsentState = .optedOut
|
||||
appSettings.analyticsConsentState = .optedOut
|
||||
// Analytics should not start
|
||||
XCTAssertFalse(ServiceLocator.shared.analytics.isEnabled)
|
||||
ServiceLocator.shared.analytics.startIfEnabled()
|
||||
@@ -115,7 +113,7 @@ class AnalyticsTests: XCTestCase {
|
||||
|
||||
func testAnalyticsStartIfEnabled() {
|
||||
// Given an existing install of the app where the user previously accpeted the tracking
|
||||
applicationSettings.analyticsConsentState = .optedIn
|
||||
appSettings.analyticsConsentState = .optedIn
|
||||
// Analytics should start
|
||||
XCTAssertTrue(ServiceLocator.shared.analytics.isEnabled)
|
||||
ServiceLocator.shared.analytics.startIfEnabled()
|
||||
@@ -188,14 +186,14 @@ class AnalyticsTests: XCTestCase {
|
||||
|
||||
func testResetConsentState() {
|
||||
// Given an existing install of the app where the user previously accpeted the tracking
|
||||
applicationSettings.analyticsConsentState = .optedIn
|
||||
appSettings.analyticsConsentState = .optedIn
|
||||
XCTAssertFalse(ServiceLocator.shared.analytics.shouldShowAnalyticsPrompt)
|
||||
|
||||
// When forgetting analytics consents
|
||||
ServiceLocator.shared.analytics.resetConsentState()
|
||||
|
||||
// Then the analytics prompt should be presented again
|
||||
XCTAssertEqual(applicationSettings.analyticsConsentState, .unknown)
|
||||
XCTAssertEqual(appSettings.analyticsConsentState, .unknown)
|
||||
XCTAssertTrue(ServiceLocator.shared.analytics.shouldShowAnalyticsPrompt)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,10 @@ class BugReportViewModelTests: XCTestCase {
|
||||
|
||||
func testSendReportWithSuccess() async throws {
|
||||
let mockService = BugReportServiceMock()
|
||||
mockService.submitBugReportProgressListenerReturnValue = SubmitBugReportResponse(reportUrl: "https://test.test")
|
||||
mockService.submitBugReportProgressListenerClosure = { _, _ in
|
||||
await Task.yield()
|
||||
return SubmitBugReportResponse(reportUrl: "https://test.test")
|
||||
}
|
||||
let viewModel = BugReportScreenViewModel(bugReportService: mockService,
|
||||
userID: "@mock.client.com",
|
||||
deviceID: nil,
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
//
|
||||
// Copyright 2023 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
|
||||
@testable import ElementX
|
||||
|
||||
extension XCTestCase {
|
||||
func setupAppSettings() {
|
||||
AppSettings.configureWithSuiteName("io.element.elementx.unitests")
|
||||
AppSettings.reset()
|
||||
ServiceLocator.shared.register(appSettings: AppSettings())
|
||||
}
|
||||
}
|
||||
@@ -27,13 +27,11 @@ final class NotificationManagerTests: XCTestCase {
|
||||
private var shouldDisplayInAppNotificationReturnValue = false
|
||||
private var handleInlineReplyDelegateCalled = false
|
||||
private var notificationTappedDelegateCalled = false
|
||||
private var settings: AppSettings!
|
||||
|
||||
private var appSettings: AppSettings { ServiceLocator.shared.settings }
|
||||
|
||||
override func setUp() {
|
||||
AppSettings.configureWithSuiteName("io.element.elementx.unitests")
|
||||
AppSettings.reset()
|
||||
settings = AppSettings()
|
||||
ServiceLocator.shared.register(appSettings: settings)
|
||||
|
||||
notificationManager = NotificationManager(notificationCenter: notificationCenter)
|
||||
notificationManager.start()
|
||||
@@ -64,7 +62,7 @@ final class NotificationManagerTests: XCTestCase {
|
||||
let pushkeyData = Data("1234".utf8)
|
||||
_ = await notificationManager.register(with: pushkeyData)
|
||||
XCTAssertEqual(clientProxy.setPusherArgument?.identifiers.pushkey, pushkeyData.base64EncodedString())
|
||||
XCTAssertEqual(clientProxy.setPusherArgument?.identifiers.appId, settings?.pusherAppId)
|
||||
XCTAssertEqual(clientProxy.setPusherArgument?.identifiers.appId, appSettings.pusherAppId)
|
||||
XCTAssertEqual(clientProxy.setPusherArgument?.appDisplayName, "\(InfoPlistReader.main.bundleDisplayName) (iOS)")
|
||||
XCTAssertEqual(clientProxy.setPusherArgument?.deviceDisplayName, UIDevice.current.name)
|
||||
XCTAssertNotNil(clientProxy.setPusherArgument?.profileTag)
|
||||
@@ -73,7 +71,7 @@ final class NotificationManagerTests: XCTestCase {
|
||||
XCTFail("Http kind expected")
|
||||
return
|
||||
}
|
||||
XCTAssertEqual(data.url, settings?.pushGatewayBaseURL.absoluteString)
|
||||
XCTAssertEqual(data.url, appSettings.pushGatewayBaseURL.absoluteString)
|
||||
XCTAssertEqual(data.format, .eventIdOnly)
|
||||
let defaultPayload = APNSPayload(aps: APSInfo(mutableContent: 1,
|
||||
alert: APSAlert(locKey: "Notification",
|
||||
@@ -83,15 +81,15 @@ final class NotificationManagerTests: XCTestCase {
|
||||
}
|
||||
|
||||
func test_whenRegisteredAndPusherTagNotSetInSettings_tagGeneratedAndSavedInSettings() async throws {
|
||||
settings?.pusherProfileTag = nil
|
||||
appSettings.pusherProfileTag = nil
|
||||
_ = await notificationManager.register(with: Data())
|
||||
XCTAssertNotNil(settings?.pusherProfileTag)
|
||||
XCTAssertNotNil(appSettings.pusherProfileTag)
|
||||
}
|
||||
|
||||
func test_whenRegisteredAndPusherTagIsSetInSettings_tagNotGenerated() async throws {
|
||||
settings?.pusherProfileTag = "12345"
|
||||
appSettings.pusherProfileTag = "12345"
|
||||
_ = await notificationManager.register(with: Data())
|
||||
XCTAssertEqual(settings?.pusherProfileTag, "12345")
|
||||
XCTAssertEqual(appSettings.pusherProfileTag, "12345")
|
||||
}
|
||||
|
||||
func test_whenShowLocalNotification_notificationRequestGetsAdded() async throws {
|
||||
|
||||
@@ -36,7 +36,7 @@ class StartChatScreenViewModelTests: XCTestCase {
|
||||
let userSession = MockUserSession(clientProxy: clientProxy, mediaProvider: MockMediaProvider())
|
||||
viewModel = StartChatScreenViewModel(userSession: userSession, userIndicatorController: nil, userDiscoveryService: userDiscoveryService)
|
||||
|
||||
setupAppSettings()
|
||||
AppSettings.reset()
|
||||
ServiceLocator.shared.settings.startChatUserSuggestionsEnabled = true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user