ASMR/src/test/kotlin/net/shadowfacts/cacao/view/ViewHoverTests.kt

65 lines
1.5 KiB
Kotlin

package net.shadowfacts.cacao.view
import net.shadowfacts.cacao.Window
import net.shadowfacts.cacao.geometry.Point
import net.shadowfacts.cacao.geometry.Rect
import net.shadowfacts.cacao.viewcontroller.ViewController
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.util.concurrent.CompletableFuture
/**
* @author shadowfacts
*/
class ViewHoverTests {
lateinit var viewController: ViewController
lateinit var window: Window
val view: View
get() = viewController.view
companion object {
@BeforeAll
@JvmStatic
fun setupAll() {
System.setProperty("cacao.drawing.disabled", "true")
}
}
@BeforeEach
fun setup() {
viewController = object: ViewController() {}
window = Window(viewController)
}
@Test
fun testHoverRootView() {
val point = CompletableFuture<Point>()
view.addSubview(object: View(Rect(50.0, 50.0, 100.0, 100.0)) {
override fun drawContent(mouse: Point, delta: Float) {
point.complete(mouse)
}
})
window.draw(Point(75.0, 75.0), 0f)
assertEquals(Point(25.0, 25.0), point.getNow(null))
}
@Test
fun testHoverNestedView() {
val point = CompletableFuture<Point>()
val root = view.addSubview(View(Rect(50.0, 50.0, 100.0, 100.0)))
root.addSubview(object: View(Rect(25.0, 25.0, 50.0, 50.0)) {
override fun drawContent(mouse: Point, delta: Float) {
point.complete(mouse)
}
})
window.draw(Point(100.0, 100.0), 0f)
assertEquals(Point(25.0, 25.0), point.getNow(null))
}
}