From 07f0c491223d8a96e046083df7c6ac11f2f51099 Mon Sep 17 00:00:00 2001 From: Cyndi Chin Date: Wed, 18 Sep 2024 16:39:34 -0400 Subject: [PATCH] Add FXIOS-9683 [Unit Tests] Tab Peek State tests (#22043) --- firefox-ios/Client.xcodeproj/project.pbxproj | 12 +++ .../TabTray/Redux/TabPeekStateTests.swift | 99 +++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 firefox-ios/firefox-ios-tests/Tests/ClientTests/TabTray/Redux/TabPeekStateTests.swift diff --git a/firefox-ios/Client.xcodeproj/project.pbxproj b/firefox-ios/Client.xcodeproj/project.pbxproj index d2baf18a2bc1..9759eae062ce 100644 --- a/firefox-ios/Client.xcodeproj/project.pbxproj +++ b/firefox-ios/Client.xcodeproj/project.pbxproj @@ -795,6 +795,7 @@ 8A7A93EE2810ADF2005E7E1B /* ContileProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A7A93ED2810ADF2005E7E1B /* ContileProviderTests.swift */; }; 8A7AE4442BAB510B0072DAEC /* LibraryPanelCoordinatorDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A7AE4432BAB510B0072DAEC /* LibraryPanelCoordinatorDelegate.swift */; }; 8A7AE4472BAC78230072DAEC /* MockLibraryNavigationHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A7AE4452BAC76B00072DAEC /* MockLibraryNavigationHandler.swift */; }; + 8A7AF0C72C9A119A009691B5 /* TabPeekStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A7AF0C52C9A1167009691B5 /* TabPeekStateTests.swift */; }; 8A7D1AC52BA3542600162F4B /* splashScreen.json in Resources */ = {isa = PBXBuildFile; fileRef = 8A7D1AC42BA3542600162F4B /* splashScreen.json */; }; 8A8158CB2C2C77B000281F72 /* MicrosurveyTelemetry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A8158CA2C2C77B000281F72 /* MicrosurveyTelemetry.swift */; }; 8A827E302C20C7F5008D5E3C /* MicrosurveyMiddlewareTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A827E2E2C20C55E008D5E3C /* MicrosurveyMiddlewareTests.swift */; }; @@ -6838,6 +6839,7 @@ 8A7A93ED2810ADF2005E7E1B /* ContileProviderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContileProviderTests.swift; sourceTree = ""; }; 8A7AE4432BAB510B0072DAEC /* LibraryPanelCoordinatorDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LibraryPanelCoordinatorDelegate.swift; sourceTree = ""; }; 8A7AE4452BAC76B00072DAEC /* MockLibraryNavigationHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockLibraryNavigationHandler.swift; sourceTree = ""; }; + 8A7AF0C52C9A1167009691B5 /* TabPeekStateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabPeekStateTests.swift; sourceTree = ""; }; 8A7D1AC42BA3542600162F4B /* splashScreen.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = splashScreen.json; sourceTree = ""; }; 8A8158CA2C2C77B000281F72 /* MicrosurveyTelemetry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MicrosurveyTelemetry.swift; sourceTree = ""; }; 8A827E2E2C20C55E008D5E3C /* MicrosurveyMiddlewareTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MicrosurveyMiddlewareTests.swift; sourceTree = ""; }; @@ -9408,6 +9410,7 @@ 21D8EA942ABE0511003FF16E /* TabTray */ = { isa = PBXGroup; children = ( + 8A7AF0C42C9A1135009691B5 /* Redux */, 21B548982B1E7FDF00DC1DF8 /* InactiveTabsManagerTests.swift */, 219935ED2B07B9B300E5966F /* Legacy */, 1D8487B52AD6038100F7527C /* RemoteTabPanelStateTests.swift */, @@ -10701,6 +10704,14 @@ path = Pocket; sourceTree = ""; }; + 8A7AF0C42C9A1135009691B5 /* Redux */ = { + isa = PBXGroup; + children = ( + 8A7AF0C52C9A1167009691B5 /* TabPeekStateTests.swift */, + ); + path = Redux; + sourceTree = ""; + }; 8A827E332C20C8C0008D5E3C /* Mock */ = { isa = PBXGroup; children = ( @@ -16199,6 +16210,7 @@ 21FA8FAE2AE856460013B815 /* TabsCoordinatorTests.swift in Sources */, E1D8BC7A21FF7A0000B100BD /* TPStatsBlocklistsTests.swift in Sources */, 5AF6254328A57A4600A90253 /* HistoryHighlightsDataAdaptorTests.swift in Sources */, + 8A7AF0C72C9A119A009691B5 /* TabPeekStateTests.swift in Sources */, 0AFF7F642C7784D600265214 /* MockDataCleaner.swift in Sources */, 8AE80BAD2891957C00BC12EA /* TopSitesDimensionTests.swift in Sources */, D82ED2641FEB3C420059570B /* DefaultSearchPrefsTests.swift in Sources */, diff --git a/firefox-ios/firefox-ios-tests/Tests/ClientTests/TabTray/Redux/TabPeekStateTests.swift b/firefox-ios/firefox-ios-tests/Tests/ClientTests/TabTray/Redux/TabPeekStateTests.swift new file mode 100644 index 000000000000..ecca2484c84a --- /dev/null +++ b/firefox-ios/firefox-ios-tests/Tests/ClientTests/TabTray/Redux/TabPeekStateTests.swift @@ -0,0 +1,99 @@ +// 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 Redux +import XCTest + +@testable import Client + +final class TabPeekStateTests: XCTestCase { + override func setUp() { + super.setUp() + DependencyHelperMock().bootstrapDependencies() + } + + override func tearDown() { + DependencyHelperMock().reset() + super.tearDown() + } + + func testLoadTabPeekAction_showAddBookmarks_andSendToDevice() { + let initialState = createSubject() + let reducer = tabPeekReducer() + + XCTAssertEqual(initialState.showAddToBookmarks, false) + XCTAssertEqual(initialState.showSendToDevice, false) + + let action = getAction(for: .loadTabPeek) + let newState = reducer(initialState, action) + + XCTAssertEqual(newState.showAddToBookmarks, true) + XCTAssertEqual(newState.showSendToDevice, true) + } + + func testLoadTabPeekAction_doesNotShowAddBookmarks_orSendToDevice() { + let initialState = createSubject() + let reducer = tabPeekReducer() + + XCTAssertEqual(initialState.showAddToBookmarks, false) + XCTAssertEqual(initialState.showSendToDevice, false) + + let model = TabPeekModel( + canTabBeSaved: false, + isSyncEnabled: true, + screenshot: UIImage(), + accessiblityLabel: "" + ) + let action = getAction(for: .loadTabPeek, with: model) + let newState = reducer(initialState, action) + + XCTAssertEqual(newState.showAddToBookmarks, false) + XCTAssertEqual(newState.showSendToDevice, false) + } + + func testLoadTabPeekAction_showBookmarks_andDoesNotShowDevice() { + let initialState = createSubject() + let reducer = tabPeekReducer() + + XCTAssertEqual(initialState.showAddToBookmarks, false) + XCTAssertEqual(initialState.showSendToDevice, false) + + let model = TabPeekModel( + canTabBeSaved: true, + isSyncEnabled: false, + screenshot: UIImage(), + accessiblityLabel: "" + ) + let action = getAction(for: .loadTabPeek, with: model) + let newState = reducer(initialState, action) + + XCTAssertEqual(newState.showAddToBookmarks, true) + XCTAssertEqual(newState.showSendToDevice, false) + } + + // MARK: - Private + private func createSubject() -> TabPeekState { + return TabPeekState(windowUUID: .XCTestDefaultUUID) + } + + private func tabPeekReducer() -> Reducer { + return TabPeekState.reducer + } + + private func getAction( + for actionType: TabPeekActionType, + with model: TabPeekModel = TabPeekModel( + canTabBeSaved: true, + isSyncEnabled: true, + screenshot: UIImage(), + accessiblityLabel: "tabpeek-a11y-label" + ) + ) -> TabPeekAction { + return TabPeekAction( + tabPeekModel: model, + windowUUID: .XCTestDefaultUUID, + actionType: actionType + ) + } +}