|
| 1 | +// |
| 2 | +// KeyHandlingTableViewOverlayTests.swift |
| 3 | +// TableProTests |
| 4 | +// |
| 5 | + |
| 6 | +import AppKit |
| 7 | +import Foundation |
| 8 | +import SwiftUI |
| 9 | +import TableProPluginKit |
| 10 | +import Testing |
| 11 | + |
| 12 | +@testable import TablePro |
| 13 | + |
| 14 | +@MainActor |
| 15 | +private final class StubColumnLayoutPersister: ColumnLayoutPersisting { |
| 16 | + func load(for tableName: String, connectionId: UUID) -> ColumnLayoutState? { nil } |
| 17 | + func save(_ layout: ColumnLayoutState, for tableName: String, connectionId: UUID) {} |
| 18 | + func clear(for tableName: String, connectionId: UUID) {} |
| 19 | +} |
| 20 | + |
| 21 | +@Suite("KeyHandlingTableView overlay raise") |
| 22 | +@MainActor |
| 23 | +struct KeyHandlingTableViewOverlayTests { |
| 24 | + private func makeCoordinator() -> TableViewCoordinator { |
| 25 | + TableViewCoordinator( |
| 26 | + changeManager: AnyChangeManager(DataChangeManager()), |
| 27 | + isEditable: true, |
| 28 | + selectedRowIndices: .constant([]), |
| 29 | + delegate: nil, |
| 30 | + layoutPersister: StubColumnLayoutPersister() |
| 31 | + ) |
| 32 | + } |
| 33 | + |
| 34 | + @Test("adding a subview while an overlay is active raises it to front without trapping") |
| 35 | + func addingSubviewRaisesActiveOverlay() { |
| 36 | + let tableView = KeyHandlingTableView() |
| 37 | + let coordinator = makeCoordinator() |
| 38 | + tableView.coordinator = coordinator |
| 39 | + |
| 40 | + let editor = CellOverlayEditor() |
| 41 | + coordinator.overlayEditor = editor |
| 42 | + let container = CellOverlayContainerView(frame: NSRect(x: 0, y: 0, width: 80, height: 24)) |
| 43 | + editor.install(in: tableView, row: 0, column: 0, columnIndex: 0, container: container) |
| 44 | + |
| 45 | + tableView.addSubview(NSView(frame: NSRect(x: 0, y: 0, width: 10, height: 10))) |
| 46 | + |
| 47 | + #expect(tableView.subviews.last === container) |
| 48 | + |
| 49 | + editor.removeOverlay() |
| 50 | + } |
| 51 | +} |
0 commit comments