new tests

This commit is contained in:
Mark Gregory
2026-10-19 09:47:26 +01:00
parent f63d40ff48
commit ff3658352a
8 changed files with 447 additions and 1056 deletions
+251 -1050
View File
File diff suppressed because it is too large Load Diff
+25
View File
@@ -0,0 +1,25 @@
import Foundation
import CoreGraphics
/// Pure schema-diagram operations shared by the UI and XCTest suite.
enum DiagramLogic {
static func selectedObjects(_ requested: Set<String>, available: [String]) -> Set<String> {
requested.intersection(Set(available))
}
static func arrangedPositions(_ names: [String]) -> [String: CGPoint] {
let countPerRow = max(1, Int(ceil(sqrt(Double(max(1, names.count))))))
var positions: [String: CGPoint] = [:]
for (index, name) in names.enumerated() {
positions[name] = CGPoint(x: CGFloat(index % countPerRow) * 290 + 30,
y: CGFloat(index / countPerRow) * 300 + 30)
}
return positions
}
static func translatedPosition(_ origin: CGPoint, translation: CGSize, zoom: CGFloat) -> CGPoint {
let scale = max(zoom, 0.1)
return CGPoint(x: origin.x + translation.width / scale,
y: origin.y + translation.height / scale)
}
}
+2 -6
View File
@@ -355,7 +355,7 @@ struct DBSynSchemaDiagramView: View {
// previous implementation only saved the checkboxes, leaving the diagram
// scrolled to stale positions after None / All / individual selections.
private func updateIncludedObjects(_ updated: Set<String>) {
let valid = updated.intersection(Set(allObjects))
let valid = DiagramLogic.selectedObjects(updated, available: allObjects)
guard valid != includedObjects else { return }
includedObjects = valid
if let selectedObject, !valid.contains(selectedObject) {
@@ -371,11 +371,7 @@ struct DBSynSchemaDiagramView: View {
private func arrange() {
let names = allObjects.filter { includedObjects.contains($0) }
let countPerRow = max(1, Int(ceil(sqrt(Double(max(1, names.count))))))
for (index, name) in names.enumerated() {
positions[name] = CGPoint(x: CGFloat(index % countPerRow) * 290 + 30,
y: CGFloat(index / countPerRow) * 300 + 30)
}
positions.merge(DiagramLogic.arrangedPositions(names)) { _, latest in latest }
}
private func loadCatalog() {
let stored = UserDefaults.standard.stringArray(forKey: catalogKey) ?? ["Main"]