Fix EnumButtonTests failing

Clicking an EnumButton causes it to change it's labels text, which was
changed in f29e690208 to cause a layout pass, which invalidated the manually
set frame.
This commit is contained in:
Shadowfacts 2019-06-27 19:38:22 -04:00
parent d750339c07
commit 2044daec40
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 13 additions and 22 deletions

View File

@ -5,6 +5,7 @@ import net.shadowfacts.cacao.Window
import net.shadowfacts.cacao.geometry.Point
import net.shadowfacts.cacao.geometry.Rect
import net.shadowfacts.cacao.util.MouseButton
import net.shadowfacts.kiwidsl.dsl
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeAll
@ -31,23 +32,28 @@ class EnumButtonTests {
lateinit var screen: CacaoScreen
lateinit var window: Window
lateinit var button: EnumButton<MyEnum>
@BeforeEach
fun setup() {
screen = CacaoScreen()
window = screen.addWindow(Window())
button = window.addView(EnumButton(MyEnum.ONE, MyEnum::name))
window.solver.dsl {
button.leftAnchor equalTo 0
button.topAnchor equalTo 0
button.widthAnchor equalTo 25
button.heightAnchor equalTo 25
}
window.layout()
}
@Test
fun testHandlerCalled() {
val called = CompletableFuture<Boolean>()
val button = window.addView(EnumButton(MyEnum.ONE, MyEnum::name).apply {
frame = Rect(0.0, 0.0, 25.0, 25.0)
content.frame = bounds
handler = {
called.complete(true)
}
})
button.handler = {
called.complete(true)
}
assertTrue(window.mouseClicked(Point(5.0, 5.0), MouseButton.LEFT))
assertTrue(called.getNow(false))
@ -56,11 +62,6 @@ class EnumButtonTests {
@Test
fun testCyclesValues() {
val button = window.addView(EnumButton(MyEnum.ONE, MyEnum::name).apply {
frame = Rect(0.0, 0.0, 25.0, 25.0)
content.frame = bounds
})
assertTrue(window.mouseClicked(Point(5.0, 5.0), MouseButton.LEFT))
assertEquals(MyEnum.TWO, button.value)
assertTrue(window.mouseClicked(Point(5.0, 5.0), MouseButton.LEFT))
@ -71,11 +72,6 @@ class EnumButtonTests {
@Test
fun testCyclesValuesBackwards() {
val button = window.addView(EnumButton(MyEnum.ONE, MyEnum::name).apply {
frame = Rect(0.0, 0.0, 25.0, 25.0)
content.frame = Rect(0.0, 0.0, 25.0, 25.0)
})
assertTrue(window.mouseClicked(Point(5.0, 5.0), MouseButton.LEFT))
assertEquals(MyEnum.TWO, button.value)
assertTrue(window.mouseClicked(Point(5.0, 5.0), MouseButton.RIGHT))
@ -84,11 +80,6 @@ class EnumButtonTests {
@Test
fun testMiddleClickDoesNotChangeValue() {
val button = window.addView(EnumButton(MyEnum.ONE, MyEnum::name).apply {
frame = Rect(0.0, 0.0, 25.0, 25.0)
content.frame = Rect(0.0, 0.0, 25.0, 25.0)
})
assertTrue(window.mouseClicked(Point(5.0, 5.0), MouseButton.MIDDLE))
assertEquals(MyEnum.ONE, button.value)
}