diff --git a/firefox-ios/Client.xcodeproj/project.pbxproj b/firefox-ios/Client.xcodeproj/project.pbxproj index 80ec50f46cb2..e2f942a0558f 100644 --- a/firefox-ios/Client.xcodeproj/project.pbxproj +++ b/firefox-ios/Client.xcodeproj/project.pbxproj @@ -850,6 +850,7 @@ 8AA020EF2B9A37E500771DE0 /* NimbusSplashScreenFeatureLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AA020EE2B9A37E500771DE0 /* NimbusSplashScreenFeatureLayer.swift */; }; 8AA6ADB52742B567004EEE23 /* TelemetryWrapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AA6ADB42742B567004EEE23 /* TelemetryWrapperTests.swift */; }; 8AA7347B28AEDB3100443D24 /* PocketViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AA7347A28AEDB3100443D24 /* PocketViewModelTests.swift */; }; + 8AA8389D2CA2FEFC003FA256 /* StoreTestUtility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AA8389C2CA2FEFC003FA256 /* StoreTestUtility.swift */; }; 8AAAB0592C1B7240008830B3 /* MockRustFirefoxSuggest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AAAB0582C1B723F008830B3 /* MockRustFirefoxSuggest.swift */; }; 8AAAB05B2C1B7268008830B3 /* ClientTabsSearchWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AAAB05A2C1B7268008830B3 /* ClientTabsSearchWrapper.swift */; }; 8AAAB05F2C1B72C9008830B3 /* SearchHighlightItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AAAB05E2C1B72C9008830B3 /* SearchHighlightItem.swift */; }; @@ -6949,6 +6950,7 @@ 8AA020EE2B9A37E500771DE0 /* NimbusSplashScreenFeatureLayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NimbusSplashScreenFeatureLayer.swift; sourceTree = ""; }; 8AA6ADB42742B567004EEE23 /* TelemetryWrapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TelemetryWrapperTests.swift; sourceTree = ""; }; 8AA7347A28AEDB3100443D24 /* PocketViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PocketViewModelTests.swift; sourceTree = ""; }; + 8AA8389C2CA2FEFC003FA256 /* StoreTestUtility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreTestUtility.swift; sourceTree = ""; }; 8AAAB0582C1B723F008830B3 /* MockRustFirefoxSuggest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockRustFirefoxSuggest.swift; sourceTree = ""; }; 8AAAB05A2C1B7268008830B3 /* ClientTabsSearchWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientTabsSearchWrapper.swift; sourceTree = ""; }; 8AAAB05E2C1B72C9008830B3 /* SearchHighlightItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchHighlightItem.swift; sourceTree = ""; }; @@ -10536,6 +10538,7 @@ C8E78BDC27F4A1E700C48BAA /* HistoryDeletionUtilityTests.swift */, 8A1E3BE128CBACD7003388C4 /* SponsoredContentFilterUtilityTests.swift */, 8ACA8F7529198D6400D3075D /* ThrottlerTests.swift */, + 8AA8389C2CA2FEFC003FA256 /* StoreTestUtility.swift */, ); path = Utils; sourceTree = ""; @@ -16082,6 +16085,7 @@ 21534904288201E300FADB4D /* GleanPlumbMessageManagerTests.swift in Sources */, AB03032F2AB8561700DCD8EF /* FakespotOptInViewModelTests.swift in Sources */, 21BFEEF82A05A0370033048D /* TabMigrationUtilityTests.swift in Sources */, + 8AA8389D2CA2FEFC003FA256 /* StoreTestUtility.swift in Sources */, DFD1046D2B23539600938418 /* ProductAdsCacheTests.swift in Sources */, E1390FB628B040E900C9EF3E /* WallpaperSelectorViewModelTests.swift in Sources */, 39AF317429DAE37E00F8E6F7 /* NimbusMessagingMessageTests.swift in Sources */, diff --git a/firefox-ios/firefox-ios-tests/Tests/ClientTests/Microsurvey/MicrosurveyMiddlewareTests.swift b/firefox-ios/firefox-ios-tests/Tests/ClientTests/Microsurvey/MicrosurveyMiddlewareTests.swift index 7c1497c3cdb6..0632df1a442d 100644 --- a/firefox-ios/firefox-ios-tests/Tests/ClientTests/Microsurvey/MicrosurveyMiddlewareTests.swift +++ b/firefox-ios/firefox-ios-tests/Tests/ClientTests/Microsurvey/MicrosurveyMiddlewareTests.swift @@ -8,11 +8,13 @@ import XCTest @testable import Client -final class MicrosurveyMiddlewareTests: XCTestCase { +final class MicrosurveyMiddlewareIntegrationTests: XCTestCase, StoreTestUtility { + let storeUtilityHelper = StoreTestUtilityHelper() override func setUp() { super.setUp() Glean.shared.resetGlean(clearStores: true) DependencyHelperMock().bootstrapDependencies() + setupTestingStore() } override func tearDown() { @@ -22,8 +24,6 @@ final class MicrosurveyMiddlewareTests: XCTestCase { } func testDismissSurveyAction() throws { - setupTestingStore() - let action = getAction(for: .closeSurvey) store.dispatch(action) @@ -41,8 +41,6 @@ final class MicrosurveyMiddlewareTests: XCTestCase { } func testPrivacyNoticeTappedAction() throws { - setupTestingStore() - let action = getAction(for: .tapPrivacyNotice) store.dispatch(action) @@ -60,8 +58,6 @@ final class MicrosurveyMiddlewareTests: XCTestCase { } func testSubmitSurveyAction() throws { - setupTestingStore() - let action = MicrosurveyAction( surveyId: "microsurvey-id", userSelection: "Neutral", @@ -85,8 +81,6 @@ final class MicrosurveyMiddlewareTests: XCTestCase { } func testConfirmationViewedAction() throws { - setupTestingStore() - let action = getAction(for: .confirmationViewed) store.dispatch(action) @@ -103,7 +97,8 @@ final class MicrosurveyMiddlewareTests: XCTestCase { ) } - private func setupAppState() -> AppState { + // MARK: StoreTestUtility + func setupAppState() -> AppState { return AppState( activeScreens: ActiveScreensState( screens: [ @@ -122,21 +117,16 @@ final class MicrosurveyMiddlewareTests: XCTestCase { ) } - private func setupTestingStore() { - store = Store( - state: setupAppState(), - reducer: AppState.reducer, + func setupTestingStore() { + storeUtilityHelper.setupTestingStore( + with: setupAppState(), middlewares: [MicrosurveyMiddleware().microsurveyProvider] ) } // In order to avoid flaky tests, we should reset the store // similar to production - private func resetTestingStore() { - store = Store( - state: AppState(), - reducer: AppState.reducer, - middlewares: middlewares - ) + func resetTestingStore() { + storeUtilityHelper.resetTestingStore() } } diff --git a/firefox-ios/firefox-ios-tests/Tests/ClientTests/Utils/StoreTestUtility.swift b/firefox-ios/firefox-ios-tests/Tests/ClientTests/Utils/StoreTestUtility.swift new file mode 100644 index 000000000000..9101129ade29 --- /dev/null +++ b/firefox-ios/firefox-ios-tests/Tests/ClientTests/Utils/StoreTestUtility.swift @@ -0,0 +1,34 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/ + +import Foundation +import Redux +@testable import Client + +protocol StoreTestUtility { + func setupAppState() -> AppState + func setupTestingStore() + func resetTestingStore() +} + +/// Utility class used when replacing the global store for testing purposes +class StoreTestUtilityHelper { + func setupTestingStore(with appState: AppState, middlewares: [Middleware]) { + store = Store( + state: appState, + reducer: AppState.reducer, + middlewares: middlewares + ) + } + + /// In order to avoid flaky tests, we should reset the store + /// similar to production + func resetTestingStore() { + store = Store( + state: AppState(), + reducer: AppState.reducer, + middlewares: middlewares + ) + } +}