Skip to content

Commit

Permalink
Bugfix FXIOS-5123 [v107.1] Fix jump back in crash (#12369)
Browse files Browse the repository at this point in the history
* Fix jump back in crash

* Fix tests
# Conflicts:
#	Tests/ClientTests/Frontend/Home/JumpBackIn/JumpBackInViewModelTests.swift
  • Loading branch information
OrlaM committed Nov 17, 2022
1 parent a0b702c commit cad563c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
14 changes: 4 additions & 10 deletions Client/Frontend/Home/JumpBackIn/JumpBackInViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class JumpBackInViewModel: FeatureFlaggable {
// MARK: - Private: Prepare UI data
private extension JumpBackInViewModel {

func refreshData(maxItemsToDisplay: JumpBackInDisplayGroupCount) {
private func refreshData(maxItemsToDisplay: JumpBackInDisplayGroupCount) {
jumpBackInList = createJumpBackInList(
from: recentTabs,
withMaxTabsCount: maxItemsToDisplay.tabsCount,
Expand Down Expand Up @@ -394,24 +394,16 @@ extension JumpBackInViewModel: HomepageViewModelProtocol {
func refreshData(for traitCollection: UITraitCollection,
isPortrait: Bool = UIWindow.isPortrait,
device: UIUserInterfaceIdiom = UIDevice.current.userInterfaceIdiom) {
getLatestData()
updateSectionLayout(for: traitCollection,
isPortrait: isPortrait,
device: device)

let maxItemsToDisplay = sectionLayout.maxItemsToDisplay(
hasAccount: jumpBackInDataAdaptor.hasSyncedTabFeatureEnabled,
device: device
)
refreshData(maxItemsToDisplay: maxItemsToDisplay)
}

private func getLatestData() {
recentTabs = jumpBackInDataAdaptor.getRecentTabData()
recentGroups = jumpBackInDataAdaptor.getGroupsData()
recentSyncedTab = jumpBackInDataAdaptor.getSyncedTabData()
}

func updatePrivacyConcernedSection(isPrivate: Bool) {
self.isPrivate = isPrivate
}
Expand Down Expand Up @@ -484,7 +476,9 @@ extension JumpBackInViewModel: HomepageSectionHandler {
extension JumpBackInViewModel: JumpBackInDelegate {
func didLoadNewData() {
ensureMainThread {
self.getLatestData()
self.recentTabs = self.jumpBackInDataAdaptor.getRecentTabData()
self.recentGroups = self.jumpBackInDataAdaptor.getGroupsData()
self.recentSyncedTab = self.jumpBackInDataAdaptor.getSyncedTabData()
guard self.isEnabled else { return }
self.delegate?.reloadView()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class JumpBackInViewModelTests: XCTestCase {
trait.overridenHorizontalSizeClass = .compact
trait.overridenVerticalSizeClass = .regular

subject.didLoadNewData()
subject.refreshData(for: trait, isPortrait: true, device: .phone)
let maxItems = subject.sectionLayout.maxItemsToDisplay(hasAccount: false,
device: .phone)
Expand All @@ -186,6 +187,7 @@ class JumpBackInViewModelTests: XCTestCase {
let trait = MockTraitCollection()
trait.overridenHorizontalSizeClass = .compact
trait.overridenVerticalSizeClass = .regular
subject.didLoadNewData()
subject.refreshData(for: trait, isPortrait: true, device: .phone)
let maxItems = subject.sectionLayout.maxItemsToDisplay(hasAccount: true,
device: .phone)
Expand All @@ -206,7 +208,7 @@ class JumpBackInViewModelTests: XCTestCase {
let trait = MockTraitCollection()
trait.overridenHorizontalSizeClass = .compact
trait.overridenVerticalSizeClass = .regular

subject.didLoadNewData()
subject.refreshData(for: trait, isPortrait: true, device: .phone)
let maxItems = subject.sectionLayout.maxItemsToDisplay(hasAccount: true,
device: .phone)
Expand All @@ -226,7 +228,8 @@ class JumpBackInViewModelTests: XCTestCase {
let trait = MockTraitCollection()
trait.overridenHorizontalSizeClass = .regular
trait.overridenVerticalSizeClass = .compact
subject.refreshData(for: trait, isPortrait: false, device: .phone)
subject.didLoadNewData()
subject.refreshData(for: trait, isPortrait: true, device: .phone)
let maxItems = subject.sectionLayout.maxItemsToDisplay(hasAccount: true,
device: .phone)

Expand All @@ -245,6 +248,7 @@ class JumpBackInViewModelTests: XCTestCase {
let trait = MockTraitCollection()
trait.overridenHorizontalSizeClass = .regular
trait.overridenVerticalSizeClass = .compact
subject.didLoadNewData()
subject.refreshData(for: trait, isPortrait: false, device: .phone)
let maxItems = subject.sectionLayout.maxItemsToDisplay(hasAccount: true,
device: .phone)
Expand Down Expand Up @@ -284,6 +288,7 @@ class JumpBackInViewModelTests: XCTestCase {
trait.overridenHorizontalSizeClass = .regular
trait.overridenVerticalSizeClass = .regular

subject.didLoadNewData()
subject.refreshData(for: trait, isPortrait: false, device: .pad)
let maxItems = subject.sectionLayout.maxItemsToDisplay(hasAccount: true,
device: .pad)
Expand Down Expand Up @@ -320,6 +325,7 @@ class JumpBackInViewModelTests: XCTestCase {
let trait = MockTraitCollection()
trait.overridenHorizontalSizeClass = .regular
trait.overridenVerticalSizeClass = .regular
subject.didLoadNewData()
subject.refreshData(for: trait, isPortrait: false, device: .pad)
let maxItems = subject.sectionLayout.maxItemsToDisplay(hasAccount: true,
device: .pad)
Expand All @@ -335,6 +341,7 @@ class JumpBackInViewModelTests: XCTestCase {
let tab2 = createTab(profile: mockProfile, urlString: "www.firefox1.com")
let tab3 = createTab(profile: mockProfile, urlString: "www.firefox1.com")
adaptor.recentTabs = [tab1, tab2, tab3]
subject.didLoadNewData()

// Start in portrait
let portraitTrait = MockTraitCollection()
Expand Down Expand Up @@ -379,6 +386,7 @@ class JumpBackInViewModelTests: XCTestCase {

func testRefreshData_noData() {
let subject = createSubject()
subject.didLoadNewData()
subject.refreshData(for: MockTraitCollection())

XCTAssertEqual(subject.jumpBackInList.tabs.count, 0)
Expand All @@ -389,6 +397,7 @@ class JumpBackInViewModelTests: XCTestCase {
let subject = createSubject()
let tab1 = createTab(profile: mockProfile, urlString: "www.firefox1.com")
adaptor.recentTabs = [tab1]
subject.didLoadNewData()
subject.refreshData(for: MockTraitCollection())

XCTAssertEqual(subject.jumpBackInList.tabs.count, 1)
Expand All @@ -398,6 +407,7 @@ class JumpBackInViewModelTests: XCTestCase {
func testRefreshData_syncedTab() {
let subject = createSubject()
adaptor.syncedTab = JumpBackInSyncedTab(client: remoteClient, tab: remoteTab)
subject.didLoadNewData()
subject.refreshData(for: MockTraitCollection())

XCTAssertEqual(subject.jumpBackInList.tabs.count, 0)
Expand All @@ -417,6 +427,7 @@ class JumpBackInViewModelTests: XCTestCase {
let trait = MockTraitCollection()
trait.overridenHorizontalSizeClass = .compact
trait.overridenVerticalSizeClass = .regular
subject.didLoadNewData()
subject.refreshData(for: trait, isPortrait: true, device: .phone)

XCTAssertEqual(subject.sectionLayout, .compactJumpBackIn)
Expand All @@ -436,6 +447,7 @@ class JumpBackInViewModelTests: XCTestCase {
let trait = MockTraitCollection()
trait.overridenHorizontalSizeClass = .compact
trait.overridenVerticalSizeClass = .regular
subject.didLoadNewData()
subject.refreshData(for: trait, isPortrait: true, device: .phone)

XCTAssertEqual(subject.sectionLayout, .compactJumpBackIn)
Expand All @@ -456,6 +468,7 @@ class JumpBackInViewModelTests: XCTestCase {
let trait = MockTraitCollection()
trait.overridenHorizontalSizeClass = .compact
trait.overridenVerticalSizeClass = .regular
subject.didLoadNewData()
subject.refreshData(for: trait, isPortrait: true, device: .phone)

let jumpBackIn = subject.jumpBackInList
Expand All @@ -480,6 +493,7 @@ class JumpBackInViewModelTests: XCTestCase {
let trait = MockTraitCollection()
trait.overridenHorizontalSizeClass = .regular
trait.overridenVerticalSizeClass = .compact
subject.didLoadNewData()
subject.refreshData(for: trait, isPortrait: false, device: .phone)

let jumpBackIn = subject.jumpBackInList
Expand All @@ -505,6 +519,7 @@ class JumpBackInViewModelTests: XCTestCase {
let trait = MockTraitCollection()
trait.overridenHorizontalSizeClass = .regular
trait.overridenVerticalSizeClass = .compact
subject.didLoadNewData()
subject.refreshData(for: trait, isPortrait: false, device: .phone)

let jumpBackIn = subject.jumpBackInList
Expand Down

0 comments on commit cad563c

Please # to comment.