-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FXIOS-9683 [Unit Tests] Tab Peek State tests (#22043)
- Loading branch information
Showing
2 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
firefox-ios/firefox-ios-tests/Tests/ClientTests/TabTray/Redux/TabPeekStateTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TabPeekState> { | ||
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 | ||
) | ||
} | ||
} |