Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cyndichin committed Dec 20, 2024
1 parent 6fa47a4 commit fe685f6
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 37 deletions.
12 changes: 6 additions & 6 deletions firefox-ios/Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1046,15 +1046,14 @@
8AE1E1D927B1BD380024C45E /* UIStackViewExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE1E1D827B1BD380024C45E /* UIStackViewExtensionsTests.swift */; };
8AE1E1DB27B1C1320024C45E /* SearchBarSettingsViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE1E1DA27B1C1320024C45E /* SearchBarSettingsViewModelTests.swift */; };
8AE459922CEFB1DC002D6679 /* InactiveTabsTelemetry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE459912CEFB1DC002D6679 /* InactiveTabsTelemetry.swift */; };
8AE80BAD2891957C00BC12EA /* TopSitesDimensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE80BAC2891957C00BC12EA /* TopSitesDimensionTests.swift */; };
8AE80BAD2891957C00BC12EA /* LegacyTopSitesDimensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE80BAC2891957C00BC12EA /* LegacyTopSitesDimensionTests.swift */; };
8AE80BAF2891960300BC12EA /* MockTraitCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE80BAE2891960300BC12EA /* MockTraitCollection.swift */; };
8AE80BB62891AEA100BC12EA /* MockDispatchGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE80BB42891AE6700BC12EA /* MockDispatchGroup.swift */; };
8AE80BB82891BE0700BC12EA /* JumpBackInDataAdaptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE80BB72891BE0700BC12EA /* JumpBackInDataAdaptor.swift */; };
8AE80BBA2891C0C300BC12EA /* JumpBackInSectionLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE80BB92891C0C300BC12EA /* JumpBackInSectionLayout.swift */; };
8AE80BBC2891C20D00BC12EA /* JumpBackInList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE80BBB2891C20D00BC12EA /* JumpBackInList.swift */; };
8AE80BBE2891C21A00BC12EA /* JumpBackInSyncedTab.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE80BBD2891C21A00BC12EA /* JumpBackInSyncedTab.swift */; };
8AE938192CD91D5A0020E6CF /* TopSiteState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE938182CD91D5A0020E6CF /* TopSiteState.swift */; };
8AE9381B2CD91FDB0020E6CF /* TopSitesSectionStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE9381A2CD91FDB0020E6CF /* TopSitesSectionStateTests.swift */; };
8AE9381D2CD920310020E6CF /* TopSiteCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE9381C2CD920310020E6CF /* TopSiteCell.swift */; };
8AE9FD262CF66301001053EE /* UnifiedAdsProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE9FD252CF662FF001053EE /* UnifiedAdsProvider.swift */; };
8AEAD9F32C3D7B3E001A2C5A /* FeatureFlagsSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AEAD9F22C3D7B3E001A2C5A /* FeatureFlagsSettings.swift */; };
Expand All @@ -1067,6 +1066,7 @@
8AEE62C92756BA34003207D1 /* LoginsHelper.js in Resources */ = {isa = PBXBuildFile; fileRef = 8AEE62C62756BA34003207D1 /* LoginsHelper.js */; };
8AEE62CA2756BA34003207D1 /* TrackingProtectionStats.js in Resources */ = {isa = PBXBuildFile; fileRef = 8AEE62C72756BA34003207D1 /* TrackingProtectionStats.js */; };
8AEE62CB2756BA34003207D1 /* DownloadHelper.js in Resources */ = {isa = PBXBuildFile; fileRef = 8AEE62C82756BA34003207D1 /* DownloadHelper.js */; };
8AEF41602D15D6290013925D /* TopSitesSectionStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE9381A2CD91FDB0020E6CF /* TopSitesSectionStateTests.swift */; };
8AF10D8A29D713F50086351D /* LaunchScreenViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AF10D8929D713F50086351D /* LaunchScreenViewModelTests.swift */; };
8AF10D8F29D774090086351D /* SceneSetupHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AF10D8E29D774090086351D /* SceneSetupHelper.swift */; };
8AF10D9129D7761A0086351D /* MockLaunchScreenManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AF10D9029D776190086351D /* MockLaunchScreenManager.swift */; };
Expand Down Expand Up @@ -7635,7 +7635,7 @@
8AE1E1D827B1BD380024C45E /* UIStackViewExtensionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIStackViewExtensionsTests.swift; sourceTree = "<group>"; };
8AE1E1DA27B1C1320024C45E /* SearchBarSettingsViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchBarSettingsViewModelTests.swift; sourceTree = "<group>"; };
8AE459912CEFB1DC002D6679 /* InactiveTabsTelemetry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InactiveTabsTelemetry.swift; sourceTree = "<group>"; };
8AE80BAC2891957C00BC12EA /* TopSitesDimensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopSitesDimensionTests.swift; sourceTree = "<group>"; };
8AE80BAC2891957C00BC12EA /* LegacyTopSitesDimensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegacyTopSitesDimensionTests.swift; sourceTree = "<group>"; };
8AE80BAE2891960300BC12EA /* MockTraitCollection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockTraitCollection.swift; sourceTree = "<group>"; };
8AE80BB42891AE6700BC12EA /* MockDispatchGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockDispatchGroup.swift; sourceTree = "<group>"; };
8AE80BB72891BE0700BC12EA /* JumpBackInDataAdaptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JumpBackInDataAdaptor.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -11987,7 +11987,7 @@
8A7A93ED2810ADF2005E7E1B /* ContileProviderTests.swift */,
961577932A39008100391E8D /* SponsoredTileDataUtilityTests.swift */,
8A33221E27DFE318008F809E /* TopSitesDataAdaptorTests.swift */,
8AE80BAC2891957C00BC12EA /* TopSitesDimensionTests.swift */,
8AE80BAC2891957C00BC12EA /* LegacyTopSitesDimensionTests.swift */,
3B6F40171DC7849C00656CC6 /* TopSitesViewModelTests.swift */,
);
path = TopSites;
Expand Down Expand Up @@ -15715,7 +15715,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8AE9381B2CD91FDB0020E6CF /* TopSitesSectionStateTests.swift in Sources */,
4590912E2A2E4F7700061F0C /* AutopushTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -17038,6 +17037,7 @@
E18259E329B2A51B00E6BE76 /* MockNotificationManager.swift in Sources */,
96A5F736298D8EDF00234E5F /* MockSearchEngineProvider.swift in Sources */,
8A5D1CA02A30C9D7005AD35C /* MockAppSettingsDelegate.swift in Sources */,
8AEF41602D15D6290013925D /* TopSitesSectionStateTests.swift in Sources */,
1D7B789F2AE088930011E9F2 /* EventQueueTests.swift in Sources */,
21A1C3C72996AFF800181B7C /* OverlayModeManagerTests.swift in Sources */,
ED07C0F52CCB020B006C0627 /* SearchEngineSelectionMiddlewareTests.swift in Sources */,
Expand Down Expand Up @@ -17296,7 +17296,7 @@
8AFC4E472CAF53E100C54B43 /* RemoteDataTypeTests.swift in Sources */,
8A7AF0C72C9A119A009691B5 /* TabPeekStateTests.swift in Sources */,
0AFF7F642C7784D600265214 /* MockDataCleaner.swift in Sources */,
8AE80BAD2891957C00BC12EA /* TopSitesDimensionTests.swift in Sources */,
8AE80BAD2891957C00BC12EA /* LegacyTopSitesDimensionTests.swift in Sources */,
D82ED2641FEB3C420059570B /* DefaultSearchPrefsTests.swift in Sources */,
1D74FF502B2797EA00FF01D0 /* WindowManagerTests.swift in Sources */,
CA24B53B24ABFE5D0093848C /* PasswordManagerDataSourceHelperTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ final class HomepageDiffableDataSource:
}

/// Gets the proper amount of top sites based on layout configuration
/// which is determ
/// which is determined by the number of rows and number of tiles per row
/// - Parameters:
/// - topSiteState: state object for top site section
/// - textColor: text color from wallpaper configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ final class HomepageSectionLayoutProvider {

private var logger: Logger
private var windowUUID: WindowUUID

// MARK: Top Sites variables
// Used to calculate the layout configuration for top sites, which also determines the amount of top sites data to filter on
private var dimensionImplementation: TopSitesDimensionImplementation

init(windowUUID: WindowUUID, logger: Logger = DefaultLogger.shared) {
Expand Down Expand Up @@ -185,7 +182,7 @@ final class HomepageSectionLayoutProvider {
cellWidth: UX.TopSitesConstants.cellEstimatedSize.width
)

let numberOfTilesPerRow = dimensionImplementation.currentCount ?? UX.TopSitesConstants.minCards
let numberOfTilesPerRow = dimensionImplementation.numberOfTilesPerRow ?? UX.TopSitesConstants.minCards

let itemSize = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0 / CGFloat(numberOfTilesPerRow)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import Common

class TopSitesDimensionImplementation {
var currentCount: Int? {
/// The update count of number of tiles per row based on device layout
/// After updating the value, the top sites state should be updated respectively
var numberOfTilesPerRow: Int? {
willSet {
guard newValue != currentCount else { return }
DispatchQueue.main.async {
guard newValue != numberOfTilesPerRow else { return }
queue.async {
store.dispatch(
TopSitesAction(
numberOfTilesPerRow: newValue,
Expand All @@ -19,9 +21,12 @@ class TopSitesDimensionImplementation {
}
}
}

private let windowUUID: WindowUUID
init(windowUUID: WindowUUID) {
private let queue: DispatchQueueInterface
init(windowUUID: WindowUUID, queue: DispatchQueueInterface = DispatchQueue.main) {
self.windowUUID = windowUUID
self.queue = queue
}

/// Updates the number of tiles (top sites) per row the user will see. This depends on the UI interface the user has.
Expand All @@ -39,6 +44,6 @@ class TopSitesDimensionImplementation {
let minCardsConstant = HomepageSectionLayoutProvider.UX.TopSitesConstants.minCards
let numberOfTilesPerRow = numberOfTiles < minCardsConstant ? minCardsConstant : numberOfTiles

self.currentCount = numberOfTilesPerRow
self.numberOfTilesPerRow = numberOfTilesPerRow
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import Redux
import Shared

/// State for the top sites section that is used in the homepage
/// The state does not only contain the data, but needs to know about the number of rows and tiles per row in order to only show a specific amount of the top sites data.
/// The state does not only contain the top sites list, but needs to also know about the number of rows
/// and tiles per row in order to only show a specific amount of the top sites data.
struct TopSitesSectionState: StateType, Equatable {
var windowUUID: WindowUUID
var topSitesData: [TopSiteState]
Expand Down Expand Up @@ -80,7 +81,7 @@ struct TopSitesSectionState: StateType, Equatable {
else {
return defaultState(from: state)
}
print("CYN action \(numberOfTilesPerRow)")

return TopSitesSectionState(
windowUUID: state.windowUUID,
topSitesData: state.topSitesData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/

import XCTest
import Storage

@testable import Client

Expand All @@ -20,11 +21,13 @@ final class HomepageDiffableDataSourceTests: XCTestCase {
) { (collectionView, indexPath, item) -> UICollectionViewCell? in
return UICollectionViewCell()
}
DependencyHelperMock().bootstrapDependencies()
}

override func tearDown() {
diffableDataSource = nil
collectionView = nil
DependencyHelperMock().reset()
super.tearDown()
}

Expand Down Expand Up @@ -67,4 +70,50 @@ final class HomepageDiffableDataSourceTests: XCTestCase {
let snapshot = dataSource.snapshot()
XCTAssertEqual(snapshot.numberOfItems(inSection: .pocket(.systemCyan)), 1)
}

func test_updateSnapshot_withValidState_returnTopSites() throws {
let dataSource = try XCTUnwrap(diffableDataSource)

let state = HomepageState.reducer(
HomepageState(windowUUID: .XCTestDefaultUUID),
TopSitesAction(
topSites: createSites(),
windowUUID: .XCTestDefaultUUID,
actionType: TopSitesMiddlewareActionType.retrievedUpdatedSites
)
)

let updatedState = HomepageState.reducer(
state,
TopSitesAction(
numberOfRows: 4,
windowUUID: .XCTestDefaultUUID,
actionType: TopSitesActionType.updatedNumberOfRows
)
)

let finalState = HomepageState.reducer(
state,
TopSitesAction(
numberOfTilesPerRow: 4,
windowUUID: .XCTestDefaultUUID,
actionType: TopSitesActionType.updatedNumberOfTilesPerRow
)
)

dataSource.updateSnapshot(state: updatedState)

let snapshot = dataSource.snapshot()
XCTAssertEqual(snapshot.numberOfItems(inSection: .topSites), 16)
}

private func createSites(count: Int = 30) -> [TopSiteState] {
var sites = [TopSiteState]()
(0..<count).forEach {
let site = Site(url: "www.url\($0).com",
title: "Title \($0)")
sites.append(TopSiteState(site: site))
}
return sites
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ import XCTest
@testable import Client

final class HomepageStateTests: XCTestCase {
override func setUp() {
super.setUp()
DependencyHelperMock().bootstrapDependencies()
}

override func tearDown() {
DependencyHelperMock().reset()
super.tearDown()
}

func tests_initialState_returnsExpectedState() {
let initialState = createSubject()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import XCTest
@testable import Client

final class TopsSitesSectionStateTests: XCTestCase {
override func setUp() {
super.setUp()
DependencyHelperMock().bootstrapDependencies()
}

override func tearDown() {
DependencyHelperMock().reset()
super.tearDown()
}

func tests_initialState_returnsExpectedState() {
let initialState = createSubject()

Expand Down Expand Up @@ -56,6 +66,40 @@ final class TopsSitesSectionStateTests: XCTestCase {
XCTAssertEqual(newState.topSitesData.compactMap { $0.title }, [])
}

func test_updatedNumberOfRows_returnsExpectedState() throws {
let initialState = createSubject()
let reducer = topSiteReducer()

let newState = reducer(
initialState,
TopSitesAction(
numberOfRows: 4,
windowUUID: .XCTestDefaultUUID,
actionType: TopSitesActionType.updatedNumberOfRows
)
)

XCTAssertEqual(newState.windowUUID, .XCTestDefaultUUID)
XCTAssertEqual(newState.numberOfRows, 4)
}

func test_updatedNumberOfTilesPerRow_returnsExpectedState() throws {
let initialState = createSubject()
let reducer = topSiteReducer()

let newState = reducer(
initialState,
TopSitesAction(
numberOfTilesPerRow: 8,
windowUUID: .XCTestDefaultUUID,
actionType: TopSitesActionType.updatedNumberOfTilesPerRow
)
)

XCTAssertEqual(newState.windowUUID, .XCTestDefaultUUID)
XCTAssertEqual(newState.numberOfTilesPerRow, 8)
}

// MARK: - Private
private func createSubject() -> TopSitesSectionState {
return TopSitesSectionState(windowUUID: .XCTestDefaultUUID)
Expand Down
Loading

0 comments on commit fe685f6

Please sign in to comment.