diff --git a/firefox-ios/Client/Frontend/Library/Bookmarks/Edit Folder/EditFolderViewController.swift b/firefox-ios/Client/Frontend/Library/Bookmarks/Edit Folder/EditFolderViewController.swift index f2da5e1ccfc3..0a8c899c86d9 100644 --- a/firefox-ios/Client/Frontend/Library/Bookmarks/Edit Folder/EditFolderViewController.swift +++ b/firefox-ios/Client/Frontend/Library/Bookmarks/Edit Folder/EditFolderViewController.swift @@ -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(), @@ -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) } @@ -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() { diff --git a/firefox-ios/Client/Frontend/Library/Bookmarks/Edit Folder/EditFolderViewModel.swift b/firefox-ios/Client/Frontend/Library/Bookmarks/Edit Folder/EditFolderViewModel.swift index acc1bb7d68c6..df32b0e7ea51 100644 --- a/firefox-ios/Client/Frontend/Library/Bookmarks/Edit Folder/EditFolderViewModel.swift +++ b/firefox-ios/Client/Frontend/Library/Bookmarks/Edit Folder/EditFolderViewModel.swift @@ -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 diff --git a/firefox-ios/firefox-ios-tests/Tests/ClientTests/Library/Bookmarks/EditFolderViewModelTests.swift b/firefox-ios/firefox-ios-tests/Tests/ClientTests/Library/Bookmarks/EditFolderViewModelTests.swift index 561132b31ae3..8e0613b0c01c 100644 --- a/firefox-ios/firefox-ios-tests/Tests/ClientTests/Library/Bookmarks/EditFolderViewModelTests.swift +++ b/firefox-ios/firefox-ios-tests/Tests/ClientTests/Library/Bookmarks/EditFolderViewModelTests.swift @@ -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)