72 lines
1.6 KiB
Kotlin
72 lines
1.6 KiB
Kotlin
package net.shadowfacts.cacao.view.button
|
|
|
|
import net.shadowfacts.cacao.Window
|
|
import net.shadowfacts.cacao.geometry.Point
|
|
import net.shadowfacts.cacao.geometry.Rect
|
|
import net.shadowfacts.cacao.util.MouseButton
|
|
import org.junit.jupiter.api.Assertions.*
|
|
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 ToggleButtonTests {
|
|
|
|
companion object {
|
|
@BeforeAll
|
|
@JvmStatic
|
|
fun setupAll() {
|
|
System.setProperty("cacao.drawing.disabled", "true")
|
|
}
|
|
}
|
|
|
|
lateinit var window: Window
|
|
|
|
@BeforeEach
|
|
fun setup() {
|
|
window = Window()
|
|
}
|
|
|
|
@Test
|
|
fun testHandlerCalled() {
|
|
val called = CompletableFuture<Boolean>()
|
|
val button = window.addView(ToggleButton(false).apply {
|
|
frame = Rect(0.0, 0.0, 25.0, 25.0)
|
|
content.frame = bounds
|
|
handler = {
|
|
called.complete(true)
|
|
}
|
|
})
|
|
|
|
window.mouseClicked(Point(5.0, 5.0), MouseButton.LEFT)
|
|
assertTrue(called.getNow(false))
|
|
}
|
|
|
|
@Test
|
|
fun testTogglesValues() {
|
|
val button = window.addView(ToggleButton(false).apply {
|
|
frame = Rect(0.0, 0.0, 25.0, 25.0)
|
|
content.frame = bounds
|
|
})
|
|
|
|
window.mouseClicked(Point(5.0, 5.0), MouseButton.LEFT)
|
|
assertTrue(button.state)
|
|
window.mouseClicked(Point(5.0, 5.0), MouseButton.LEFT)
|
|
assertFalse(button.state)
|
|
}
|
|
|
|
@Test
|
|
fun testMiddleClickDoesNotChangeValue() {
|
|
val button = window.addView(ToggleButton(false).apply {
|
|
frame = Rect(0.0, 0.0, 25.0, 25.0)
|
|
content.frame = bounds
|
|
})
|
|
|
|
window.mouseClicked(Point(5.0, 5.0), MouseButton.MIDDLE)
|
|
assertFalse(button.state)
|
|
}
|
|
|
|
} |