Add Window layout unit tests
This commit is contained in:
parent
1dffc67339
commit
008354b74a
|
@ -0,0 +1,81 @@
|
|||
package net.shadowfacts.shadowui
|
||||
|
||||
import net.shadowfacts.kiwidsl.dsl
|
||||
import net.shadowfacts.shadowui.geometry.Size
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
class WindowTests {
|
||||
|
||||
lateinit var window: Window
|
||||
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
window = Window()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConstraintToConstant() {
|
||||
val view = window.addView(View())
|
||||
window.solver.dsl {
|
||||
view.leftAnchor equalTo 100
|
||||
view.rightAnchor equalTo 200
|
||||
|
||||
view.topAnchor equalTo 100
|
||||
view.heightAnchor equalTo 200
|
||||
}
|
||||
window.layout()
|
||||
|
||||
assertEquals(100.0, view.widthAnchor.value)
|
||||
assertEquals(300.0, view.bottomAnchor.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConstraintToView() {
|
||||
val one = window.addView(View())
|
||||
val two = window.addView(View())
|
||||
window.solver.dsl {
|
||||
one.leftAnchor equalTo 0
|
||||
one.widthAnchor equalTo 100
|
||||
|
||||
one.topAnchor equalTo 0
|
||||
one.heightAnchor equalTo 200
|
||||
|
||||
two.leftAnchor equalTo one.rightAnchor
|
||||
two.rightAnchor equalTo 400
|
||||
|
||||
two.topAnchor equalTo one.bottomAnchor
|
||||
two.heightAnchor equalTo one.heightAnchor
|
||||
}
|
||||
window.layout()
|
||||
|
||||
assertEquals(100.0, two.leftAnchor.value)
|
||||
assertEquals(300.0, two.widthAnchor.value)
|
||||
|
||||
assertEquals(200.0, two.topAnchor.value)
|
||||
assertEquals(400.0, two.bottomAnchor.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIntrinsicContentSize() {
|
||||
val view = window.addView(View()).apply {
|
||||
intrinsicContentSize = Size(100.0, 200.0)
|
||||
}
|
||||
window.solver.dsl {
|
||||
view.leftAnchor equalTo 0
|
||||
view.topAnchor equalTo 100
|
||||
}
|
||||
window.layout()
|
||||
|
||||
assertEquals(100.0, view.widthAnchor.value)
|
||||
assertEquals(100.0, view.rightAnchor.value)
|
||||
|
||||
assertEquals(200.0, view.heightAnchor.value)
|
||||
assertEquals(300.0, view.bottomAnchor.value)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue