43 lines
1.6 KiB
Swift
43 lines
1.6 KiB
Swift
import XCTest
|
|||
|
|
@testable import MyPassCore
|
||
|
|
|
||
|
|
final class GroupSelectionTests: XCTestCase {
|
||
|
|
private func makeSampleTree() -> (root: Group, work: Group, email: Group, personal: Group) {
|
||
|
|
let email = Group(name: "Email")
|
||
|
|
let work = Group(name: "Work", subgroups: [email])
|
||
|
|
let personal = Group(name: "Personal")
|
||
|
|
let root = Group(name: "Root", subgroups: [work, personal])
|
||
|
|
return (root, work, email, personal)
|
||
|
|
}
|
||
|
|
|
||
|
|
func test_subtreeIds_includesGroupAndAllDescendants() {
|
||
|
|
let (root, work, email, _) = makeSampleTree()
|
||
|
|
let ids = GroupSelection.subtreeIds(of: work.id, in: root)
|
||
|
|
XCTAssertEqual(ids, [work.id, email.id])
|
||
|
|
}
|
||
|
|
|
||
|
|
func test_subtreeIds_leafGroup_returnsOnlyItself() {
|
||
|
|
let (root, _, email, _) = makeSampleTree()
|
||
|
|
let ids = GroupSelection.subtreeIds(of: email.id, in: root)
|
||
|
|
XCTAssertEqual(ids, [email.id])
|
||
|
|
}
|
||
|
|
|
||
|
|
func test_toggling_selectsGroupAndSubtree() {
|
||
|
|
let (root, work, email, _) = makeSampleTree()
|
||
|
|
let result = GroupSelection.toggling(work.id, in: root, current: [])
|
||
|
|
XCTAssertEqual(result, [work.id, email.id])
|
||
|
|
}
|
||
|
|
|
||
|
|
func test_toggling_deselectsGroupAndSubtree() {
|
||
|
|
let (root, work, email, _) = makeSampleTree()
|
||
|
|
let result = GroupSelection.toggling(work.id, in: root, current: [work.id, email.id])
|
||
|
|
XCTAssertEqual(result, [])
|
||
|
|
}
|
||
|
|
|
||
|
|
func test_toggling_doesNotAffectUnrelatedSelection() {
|
||
|
|
let (root, work, email, personal) = makeSampleTree()
|
||
|
|
let result = GroupSelection.toggling(work.id, in: root, current: [personal.id])
|
||
|
|
XCTAssertEqual(result, [personal.id, work.id, email.id])
|
||
|
|
}
|
||
|
|
}
|