Skip to content

Commit

Permalink
Add FXIOS-10895 [Bookmarks evolution] Add save button + fix issue wit…
Browse files Browse the repository at this point in the history
…h saving an update to bookmark (#23942)

Add save button + fix issue with saving an update to bookmark

+ adjust tests
  • Loading branch information
lmarceau authored Dec 23, 2024
1 parent a7e76c3 commit 04eb2ec
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ class EditFolderViewController: UIViewController,
view.tableHeaderView = headerSpacerView
}

private lazy var saveBarButton: UIBarButtonItem = {
let button = UIBarButtonItem(
title: String.Bookmarks.Menu.EditBookmarkSave,
style: .done,
target: self,
action: #selector(saveButtonAction)
)
return button
}()

init(viewModel: EditFolderViewModel,
windowUUID: WindowUUID,
themeManager: any ThemeManager = AppContainer.shared.resolve(),
Expand All @@ -64,6 +74,7 @@ class EditFolderViewController: UIViewController,
override func viewDidLoad() {
super.viewDidLoad()
title = viewModel.controllerTitle
navigationItem.rightBarButtonItem = saveBarButton
viewModel.onFolderStatusUpdate = { [weak self] in
self?.tableView.reloadSections(IndexSet(integer: Section.parentFolder.rawValue), with: .automatic)
}
Expand Down Expand Up @@ -109,6 +120,14 @@ class EditFolderViewController: UIViewController,
])
}

// MARK: - Actions

@objc
func saveButtonAction() {
// Save will happen in viewWillDisappear
navigationController?.popViewController(animated: true)
}

// MARK: - Themeable

func applyTheme() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class EditFolderViewModel {
switch result {
case .success(let guid):
// A nil guid indicates a bookmark update, not creation
guard let guid else { return }
guard let guid else { break }
profile.prefs.setString(guid, forKey: PrefsKeys.RecentBookmarkFolder)

// When the folder edit view is a child of the edit bookmark view, the newly created folder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,17 @@ class EditFolderViewModelTests: XCTestCase {
XCTAssertEqual(bookmarksSaver.saveCalled, 0)
}

func testSave_whenNilGuidReturned() async throws {
func testSave_whenNilGuidReturned_thenCallsSaveBookmarkButNoRecentBookmark() async throws {
let subject = createSubject(folder: folder, parentFolder: parentFolder)
let expectation = expectation(description: "onBookmarkSaved should be called")
subject.onBookmarkSaved = {
expectation.fulfill()
}

let task = subject.save()
await task?.value

await fulfillment(of: [expectation])
let prefs = try XCTUnwrap(profile.prefs as? MockProfilePrefs)
XCTAssertNil(prefs.things[PrefsKeys.RecentBookmarkFolder])
XCTAssertEqual(bookmarksSaver.saveCalled, 1)
Expand Down

0 comments on commit 04eb2ec

Please sign in to comment.