Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jotaemepereira committed Jul 19, 2024
1 parent 26e5d16 commit e118f10
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
32 changes: 16 additions & 16 deletions UnitTests/Bookmarks/Model/BookmarkOutlineViewDataSourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BookmarkOutlineViewDataSourceTests: XCTestCase {
let mockFolder = BookmarkFolder.mock
let treeController = createTreeController(with: [mockFolder])
let mockFolderNode = treeController.node(representing: mockFolder)!
let dataSource = BookmarkOutlineViewDataSource(contentMode: .foldersOnly, bookmarkManager: LocalBookmarkManager(), treeController: treeController)
let dataSource = BookmarkOutlineViewDataSource(contentMode: .foldersOnly, bookmarkManager: LocalBookmarkManager(), treeController: treeController, sortMode: .manual)

let notification = Notification(name: NSOutlineView.itemDidExpandNotification, object: nil, userInfo: ["NSObject": mockFolderNode])
dataSource.outlineViewItemDidExpand(notification)
Expand All @@ -38,7 +38,7 @@ class BookmarkOutlineViewDataSourceTests: XCTestCase {
let mockFolder = BookmarkFolder.mock
let treeController = createTreeController(with: [mockFolder])
let mockFolderNode = treeController.node(representing: mockFolder)!
let dataSource = BookmarkOutlineViewDataSource(contentMode: .foldersOnly, bookmarkManager: LocalBookmarkManager(), treeController: treeController)
let dataSource = BookmarkOutlineViewDataSource(contentMode: .foldersOnly, bookmarkManager: LocalBookmarkManager(), treeController: treeController, sortMode: .manual)

let expandNotification = Notification(name: NSOutlineView.itemDidExpandNotification, object: nil, userInfo: ["NSObject": mockFolderNode])
dataSource.outlineViewItemDidExpand(expandNotification)
Expand All @@ -56,7 +56,7 @@ class BookmarkOutlineViewDataSourceTests: XCTestCase {
let mockOutlineView = NSOutlineView(frame: .zero)
let treeController = createTreeController(with: [mockFolder])
let mockFolderNode = treeController.node(representing: mockFolder)!
let dataSource = BookmarkOutlineViewDataSource(contentMode: .foldersOnly, bookmarkManager: LocalBookmarkManager(), treeController: treeController)
let dataSource = BookmarkOutlineViewDataSource(contentMode: .foldersOnly, bookmarkManager: LocalBookmarkManager(), treeController: treeController, sortMode: .manual)

let writer = dataSource.outlineView(mockOutlineView, pasteboardWriterForItem: mockFolderNode) as? FolderPasteboardWriter
XCTAssertNotNil(writer)
Expand All @@ -69,7 +69,7 @@ class BookmarkOutlineViewDataSourceTests: XCTestCase {
let mockFolder = BookmarkFolder.mock
let mockOutlineView = NSOutlineView(frame: .zero)
let treeController = createTreeController(with: [mockFolder])
let dataSource = BookmarkOutlineViewDataSource(contentMode: .foldersOnly, bookmarkManager: LocalBookmarkManager(), treeController: treeController)
let dataSource = BookmarkOutlineViewDataSource(contentMode: .foldersOnly, bookmarkManager: LocalBookmarkManager(), treeController: treeController, sortMode: .manual)

let spacerNode = BookmarkNode(representedObject: SpacerNode.blank, parent: nil)
let writer = dataSource.outlineView(mockOutlineView, pasteboardWriterForItem: spacerNode) as? FolderPasteboardWriter
Expand All @@ -86,9 +86,9 @@ class BookmarkOutlineViewDataSourceTests: XCTestCase {
bookmarkManager.loadBookmarks()

let treeDataSource = BookmarkSidebarTreeController(bookmarkManager: bookmarkManager)
let treeController = BookmarkTreeController(dataSource: treeDataSource)
let treeController = BookmarkTreeController(dataSource: treeDataSource, sortMode: .manual)
let mockDestinationNode = treeController.node(representing: mockDestinationFolder)!
let dataSource = BookmarkOutlineViewDataSource(contentMode: .foldersOnly, bookmarkManager: bookmarkManager, treeController: treeController)
let dataSource = BookmarkOutlineViewDataSource(contentMode: .foldersOnly, bookmarkManager: LocalBookmarkManager(), treeController: treeController, sortMode: .manual)

let pasteboardBookmark = PasteboardBookmark(id: UUID().uuidString, url: "https://example.com", title: "Pasteboard Bookmark")
let result = dataSource.validateDrop(for: [pasteboardBookmark], destination: mockDestinationNode)
Expand All @@ -106,9 +106,9 @@ class BookmarkOutlineViewDataSourceTests: XCTestCase {
bookmarkManager.loadBookmarks()

let treeDataSource = BookmarkSidebarTreeController(bookmarkManager: bookmarkManager)
let treeController = BookmarkTreeController(dataSource: treeDataSource)
let treeController = BookmarkTreeController(dataSource: treeDataSource, sortMode: .manual)
let mockDestinationNode = treeController.node(representing: mockDestinationFolder)!
let dataSource = BookmarkOutlineViewDataSource(contentMode: .foldersOnly, bookmarkManager: bookmarkManager, treeController: treeController)
let dataSource = BookmarkOutlineViewDataSource(contentMode: .foldersOnly, bookmarkManager: LocalBookmarkManager(), treeController: treeController, sortMode: .manual)

let pasteboardFolder = PasteboardFolder(folder: .init(id: UUID().uuidString, title: "Pasteboard Folder"))
let result = dataSource.validateDrop(for: [pasteboardFolder], destination: mockDestinationNode)
Expand All @@ -126,8 +126,8 @@ class BookmarkOutlineViewDataSourceTests: XCTestCase {
bookmarkManager.loadBookmarks()

let treeDataSource = BookmarkSidebarTreeController(bookmarkManager: bookmarkManager)
let treeController = BookmarkTreeController(dataSource: treeDataSource)
let dataSource = BookmarkOutlineViewDataSource(contentMode: .foldersOnly, bookmarkManager: bookmarkManager, treeController: treeController)
let treeController = BookmarkTreeController(dataSource: treeDataSource, sortMode: .manual)
let dataSource = BookmarkOutlineViewDataSource(contentMode: .foldersOnly, bookmarkManager: LocalBookmarkManager(), treeController: treeController, sortMode: .manual)
let mockDestinationNode = treeController.node(representing: mockDestinationFolder)!

let pasteboardFolder = PasteboardFolder(folder: mockDestinationFolder)
Expand All @@ -148,8 +148,8 @@ class BookmarkOutlineViewDataSourceTests: XCTestCase {
bookmarkManager.loadBookmarks()

let treeDataSource = BookmarkSidebarTreeController(bookmarkManager: bookmarkManager)
let treeController = BookmarkTreeController(dataSource: treeDataSource)
let dataSource = BookmarkOutlineViewDataSource(contentMode: .foldersOnly, bookmarkManager: bookmarkManager, treeController: treeController)
let treeController = BookmarkTreeController(dataSource: treeDataSource, sortMode: .manual)
let dataSource = BookmarkOutlineViewDataSource(contentMode: .foldersOnly, bookmarkManager: LocalBookmarkManager(), treeController: treeController, sortMode: .manual)
let mockDestinationNode = treeController.node(representing: childFolder)!

// Simulate dragging the root folder onto the child folder:
Expand All @@ -167,7 +167,7 @@ class BookmarkOutlineViewDataSourceTests: XCTestCase {
let mockFolderNode = treeController.node(representing: mockFolder)!
var didFireClosure = false
var capturedCell: BookmarkOutlineCellView?
let dataSource = BookmarkOutlineViewDataSource(contentMode: .foldersOnly, bookmarkManager: LocalBookmarkManager(), treeController: treeController) { cell in
let dataSource = BookmarkOutlineViewDataSource(contentMode: .foldersOnly, bookmarkManager: LocalBookmarkManager(), treeController: treeController, sortMode: .manual) { cell in
didFireClosure = true
capturedCell = cell
}
Expand All @@ -187,7 +187,7 @@ class BookmarkOutlineViewDataSourceTests: XCTestCase {
let mockOutlineView = NSOutlineView(frame: .zero)
let treeController = createTreeController(with: [mockFolder])
let mockFolderNode = treeController.node(representing: mockFolder)!
let dataSource = BookmarkOutlineViewDataSource(contentMode: .bookmarksAndFolders, bookmarkManager: LocalBookmarkManager(), treeController: treeController, showMenuButtonOnHover: true)
let dataSource = BookmarkOutlineViewDataSource(contentMode: .bookmarksAndFolders, bookmarkManager: LocalBookmarkManager(), treeController: treeController, sortMode: .manual, showMenuButtonOnHover: true)

// WHEN
let cell = try XCTUnwrap(dataSource.outlineView(mockOutlineView, viewFor: nil, item: mockFolderNode) as? BookmarkOutlineCellView)
Expand All @@ -202,7 +202,7 @@ class BookmarkOutlineViewDataSourceTests: XCTestCase {
let mockOutlineView = NSOutlineView(frame: .zero)
let treeController = createTreeController(with: [mockFolder])
let mockFolderNode = treeController.node(representing: mockFolder)!
let dataSource = BookmarkOutlineViewDataSource(contentMode: .foldersOnly, bookmarkManager: LocalBookmarkManager(), treeController: treeController, showMenuButtonOnHover: false)
let dataSource = BookmarkOutlineViewDataSource(contentMode: .foldersOnly, bookmarkManager: LocalBookmarkManager(), treeController: treeController, sortMode: .manual, showMenuButtonOnHover: false)

// WHEN
let cell = try XCTUnwrap(dataSource.outlineView(mockOutlineView, viewFor: nil, item: mockFolderNode) as? BookmarkOutlineCellView)
Expand All @@ -222,7 +222,7 @@ class BookmarkOutlineViewDataSourceTests: XCTestCase {
bookmarkManager.loadBookmarks()

let treeDataSource = BookmarkSidebarTreeController(bookmarkManager: bookmarkManager)
return BookmarkTreeController(dataSource: treeDataSource)
return BookmarkTreeController(dataSource: treeDataSource, sortMode: .manual)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class BookmarkSidebarTreeControllerTests: XCTestCase {

func testWhenBookmarkStoreHasNoFolders_ThenOnlyDefaultNodesAreReturned() {
let dataSource = BookmarkSidebarTreeController(bookmarkManager: LocalBookmarkManager())
let treeController = BookmarkTreeController(dataSource: dataSource)
let treeController = BookmarkTreeController(dataSource: dataSource, sortMode: .manual)
let defaultNodes = treeController.rootNode.childNodes
let representedObjects = defaultNodes.representedObjects()

Expand All @@ -48,7 +48,7 @@ class BookmarkSidebarTreeControllerTests: XCTestCase {
bookmarkManager.loadBookmarks()

let dataSource = BookmarkSidebarTreeController(bookmarkManager: bookmarkManager)
let treeController = BookmarkTreeController(dataSource: dataSource)
let treeController = BookmarkTreeController(dataSource: dataSource, sortMode: .manual)
let defaultNodes = treeController.rootNode.childNodes
XCTAssertEqual(defaultNodes.count, 1)

Expand All @@ -69,7 +69,7 @@ class BookmarkSidebarTreeControllerTests: XCTestCase {
bookmarkManager.loadBookmarks()

let dataSource = BookmarkSidebarTreeController(bookmarkManager: bookmarkManager)
let treeController = BookmarkTreeController(dataSource: dataSource)
let treeController = BookmarkTreeController(dataSource: dataSource, sortMode: .manual)
let defaultNodes = treeController.rootNode.childNodes
XCTAssertEqual(defaultNodes.count, 1)

Expand All @@ -92,7 +92,7 @@ class BookmarkSidebarTreeControllerTests: XCTestCase {
bookmarkManager.loadBookmarks()

let dataSource = BookmarkSidebarTreeController(bookmarkManager: bookmarkManager)
let treeController = BookmarkTreeController(dataSource: dataSource)
let treeController = BookmarkTreeController(dataSource: dataSource, sortMode: .manual)
let defaultNodes = treeController.rootNode.childNodes
XCTAssertEqual(defaultNodes.count, 1)

Expand Down
12 changes: 6 additions & 6 deletions UnitTests/Bookmarks/Model/TreeControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ class TreeControllerTests: XCTestCase {
func testWhenInitializingTreeControllerWithRootNode_ThenRootNodeIsSet() {
let dataSource = MockTreeControllerDataSource()
let node = BookmarkNode(representedObject: TestObject(), parent: nil)
let treeController = BookmarkTreeController(dataSource: dataSource, rootNode: node)
let treeController = BookmarkTreeController(dataSource: dataSource, sortMode: .manual, rootNode: node)

XCTAssertEqual(treeController.rootNode, node)
}

func testWhenInitializingTreeControllerWithoutRootNode_ThenGenericRootNodeIsCreated() {
let dataSource = MockTreeControllerDataSource()
let treeController = BookmarkTreeController(dataSource: dataSource)
let treeController = BookmarkTreeController(dataSource: dataSource, sortMode: .manual)

XCTAssertTrue(treeController.rootNode.canHaveChildNodes)
}
Expand All @@ -64,7 +64,7 @@ class TreeControllerTests: XCTestCase {
rootNode.childNodes = [firstChildNode, secondChildNode]

let dataSource = MockTreeControllerDataSource()
let treeController = BookmarkTreeController(dataSource: dataSource, rootNode: rootNode)
let treeController = BookmarkTreeController(dataSource: dataSource, sortMode: .manual, rootNode: rootNode)

let foundNode = treeController.node(representing: desiredObject)
XCTAssertEqual(foundNode, secondChildNode)
Expand All @@ -79,7 +79,7 @@ class TreeControllerTests: XCTestCase {
rootNode.childNodes = [firstChildNode, secondChildNode]

let dataSource = MockTreeControllerDataSource()
let treeController = BookmarkTreeController(dataSource: dataSource, rootNode: rootNode)
let treeController = BookmarkTreeController(dataSource: dataSource, sortMode: .manual, rootNode: rootNode)

let foundNode = treeController.node(representing: TestObject())
XCTAssertNil(foundNode)
Expand All @@ -94,7 +94,7 @@ class TreeControllerTests: XCTestCase {
rootNode.childNodes = [firstChildNode, secondChildNode]

let dataSource = MockTreeControllerDataSource()
let treeController = BookmarkTreeController(dataSource: dataSource, rootNode: rootNode)
let treeController = BookmarkTreeController(dataSource: dataSource, sortMode: .manual, rootNode: rootNode)

var visitedNodes = Set<Int>()

Expand All @@ -112,7 +112,7 @@ class TreeControllerTests: XCTestCase {
let dataSource = MockTreeControllerDataSource()
let searchDataSource = MockTreeControllerSearchDataSource()
searchDataSource.returnNodes = [firstNode, secondNode, thirdNode]
let sut = BookmarkTreeController(dataSource: dataSource, searchDataSource: searchDataSource)
let sut = BookmarkTreeController(dataSource: dataSource, sortMode: .manual, searchDataSource: searchDataSource)

sut.rebuild(for: "some search query", sortMode: .manual)

Expand Down

0 comments on commit e118f10

Please sign in to comment.