feat: add flattenEntries/flattenGroups tree-flattening helpers
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WYqycDFsynHH9VnnK7LNSf
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import XCTest
|
||||
@testable import MyPassCore
|
||||
|
||||
final class GroupTreeTests: XCTestCase {
|
||||
private func makeSampleTree() -> (root: Group, work: Group, email: Group) {
|
||||
let supportEntry = Entry(title: "Support Login", username: "alice")
|
||||
let email = Group(name: "Email", entries: [supportEntry])
|
||||
let bankEntry = Entry(title: "Bank", username: "bob")
|
||||
let work = Group(name: "Work", subgroups: [email], entries: [bankEntry])
|
||||
let rootEntry = Entry(title: "Root Entry", username: "root-user")
|
||||
let root = Group(name: "Root", subgroups: [work], entries: [rootEntry])
|
||||
return (root, work, email)
|
||||
}
|
||||
|
||||
func test_flattenEntries_rootEntry_hasEmptyBreadcrumb() {
|
||||
let (root, _, _) = makeSampleTree()
|
||||
let flat = flattenEntries(in: root)
|
||||
let rootEntry = flat.first { $0.entry.title == "Root Entry" }
|
||||
XCTAssertEqual(rootEntry?.breadcrumb, [])
|
||||
XCTAssertEqual(rootEntry?.parentGroupId, root.id)
|
||||
}
|
||||
|
||||
func test_flattenEntries_directChildEntry_hasSingleGroupBreadcrumb() {
|
||||
let (root, work, _) = makeSampleTree()
|
||||
let flat = flattenEntries(in: root)
|
||||
let bankEntry = flat.first { $0.entry.title == "Bank" }
|
||||
XCTAssertEqual(bankEntry?.breadcrumb.map(\.name), ["Work"])
|
||||
XCTAssertEqual(bankEntry?.parentGroupId, work.id)
|
||||
}
|
||||
|
||||
func test_flattenEntries_nestedEntry_hasFullBreadcrumb() {
|
||||
let (root, _, email) = makeSampleTree()
|
||||
let flat = flattenEntries(in: root)
|
||||
let supportEntry = flat.first { $0.entry.title == "Support Login" }
|
||||
XCTAssertEqual(supportEntry?.breadcrumb.map(\.name), ["Work", "Email"])
|
||||
XCTAssertEqual(supportEntry?.parentGroupId, email.id)
|
||||
}
|
||||
|
||||
func test_flattenGroups_includesRootFirstWithEmptyBreadcrumb() {
|
||||
let (root, _, _) = makeSampleTree()
|
||||
let flat = flattenGroups(in: root)
|
||||
XCTAssertEqual(flat.first?.group.id, root.id)
|
||||
XCTAssertEqual(flat.first?.breadcrumb, [])
|
||||
}
|
||||
|
||||
func test_flattenGroups_nestedGroup_hasBreadcrumb() {
|
||||
let (root, _, _) = makeSampleTree()
|
||||
let flat = flattenGroups(in: root)
|
||||
let email = flat.first { $0.group.name == "Email" }
|
||||
XCTAssertEqual(email?.breadcrumb.map(\.name), ["Work"])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user