forked from agentic-review-benchmarks/firefox-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditBookmarkDataSourceTests.swift
More file actions
79 lines (64 loc) · 2.8 KB
/
EditBookmarkDataSourceTests.swift
File metadata and controls
79 lines (64 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/
import XCTest
@testable import Client
@MainActor
final class EditBookmarkDataSourceTests: XCTestCase {
private let folders = [
Folder(title: "Parent", guid: "ParentFolder", indentation: 0),
Folder(title: "Child", guid: "ChildFolder", indentation: 1)
]
private var tableView: UITableView!
override func setUp() async throws {
try await super.setUp()
tableView = UITableView()
let window = UIWindow(frame: UIScreen.main.bounds)
window.rootViewController = UIViewController()
window.rootViewController?.view.addSubview(tableView)
window.makeKeyAndVisible()
}
override func tearDown() async throws {
tableView = nil
try await super.tearDown()
}
func testOnSnapshotUpdate() {
let expectation = XCTestExpectation(description: "onShapshotUpate should be called")
let subject = createSubject(tableView: tableView)
subject.onSnapshotUpdate = {
expectation.fulfill()
}
subject.updateSnapshot(isFolderCollapsed: true, folders: folders)
wait(for: [expectation], timeout: 10.0)
}
func testDataSourceSnapshot_whenFolderIsCollapsed() {
let subject = createSubject(tableView: tableView)
let sections: [EditBookmarkTableSection] = [.main, .selectFolder]
var tableCells: [EditBookmarkTableCell] = [.bookmark]
folders.forEach {
tableCells.append(EditBookmarkTableCell.folder($0, true))
}
subject.updateSnapshot(isFolderCollapsed: true, folders: folders)
XCTAssertEqual(subject.snapshot().sectionIdentifiers, sections)
XCTAssertEqual(subject.snapshot().itemIdentifiers, tableCells)
}
func testDataSourceSnapshot_whenFolderIsNotCollapsed() {
let subject = createSubject(tableView: tableView)
let sections: [EditBookmarkTableSection] = [.main, .selectFolder]
var tableCells: [EditBookmarkTableCell] = [.bookmark]
folders.forEach {
tableCells.append(EditBookmarkTableCell.folder($0, false))
}
tableCells.append(.newFolder)
subject.updateSnapshot(isFolderCollapsed: false, folders: folders)
XCTAssertEqual(subject.snapshot().sectionIdentifiers, sections)
XCTAssertEqual(subject.snapshot().itemIdentifiers, tableCells)
}
private func createSubject(tableView: UITableView) -> EditBookmarkDiffableDataSource {
let dataSource = EditBookmarkDiffableDataSource(tableView: tableView) { _, _, _ in
return UITableViewCell()
}
trackForMemoryLeaks(dataSource)
return dataSource
}
}