diff options
Diffstat (limited to 'Tests/barTests/BlockInteractionTests.swift')
| -rw-r--r-- | Tests/barTests/BlockInteractionTests.swift | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/Tests/barTests/BlockInteractionTests.swift b/Tests/barTests/BlockInteractionTests.swift new file mode 100644 index 0000000..7ffc9d4 --- /dev/null +++ b/Tests/barTests/BlockInteractionTests.swift @@ -0,0 +1,48 @@ +import AppKit +import Testing +@testable import bar + +@Test @MainActor func monitorLifetime() { + let block = Block(name: "test", placement: .left, command: "") + var interaction: BlockInteraction? = BlockInteraction() + weak let owner = interaction + interaction?.start(block: block) + let first = interaction?.eventsMonitor as AnyObject? + #expect(first != nil) + interaction?.start(block: block) + #expect(first === (interaction?.eventsMonitor as AnyObject?)) + interaction?.hoveredIndex = 0 + interaction?.stop() + #expect(interaction?.eventsMonitor == nil) + #expect(interaction?.hoveredIndex == nil) + interaction?.stop() + interaction?.start(block: block) + #expect(interaction?.eventsMonitor != nil) + interaction = nil + #expect(owner == nil) +} + +@Test @MainActor func monitorDoesNotOwnBlock() { + let interaction = BlockInteraction() + var block: Block? = Block(name: "test", placement: .left, command: "") + weak let observedBlock = block + interaction.start(block: block!) + block = nil + #expect(observedBlock == nil) + interaction.stop() +} + +@Test @MainActor func hoverResolvesCurrentContent() { + let block = Block(name: "test", placement: .left, command: "") + let interaction = BlockInteraction() + block.cells = [Cell(rawValue: "old"), Cell(rawValue: "second")] + interaction.hoveredIndex = 0 + #expect(interaction.hoveredCell(in: block)?.rawValue == "old") + block.cells = [Cell(rawValue: "new"), Cell(rawValue: "new")] + #expect(interaction.hoveredCell(in: block)?.rawValue == "new") + interaction.hoveredIndex = 1 + block.cells = [Cell(rawValue: "remaining")] + #expect(interaction.hoveredCell(in: block) == nil) + interaction.stop() + #expect(interaction.hoveredCell(in: block) == nil) +} |
