112 lines
3.0 KiB
Kotlin
112 lines
3.0 KiB
Kotlin
package com.example.aiapp
|
|
|
|
import androidx.compose.ui.geometry.Offset
|
|
import kotlin.test.Test
|
|
import kotlin.test.assertEquals
|
|
|
|
class SessionImageTest {
|
|
@Test
|
|
fun `a full-height image hides both bars`() {
|
|
assertEquals(
|
|
ViewerBars(status = true, navigation = true),
|
|
viewerBars(
|
|
imageWidth = 1000,
|
|
imageHeight = 2000,
|
|
viewportWidth = 1000,
|
|
viewportHeight = 2000,
|
|
scale = 1f,
|
|
offset = Offset.Zero,
|
|
insets = ViewerBarInsets(status = 100, navigation = 100),
|
|
),
|
|
)
|
|
}
|
|
|
|
@Test
|
|
fun `a letterboxed image leaves both bars visible`() {
|
|
assertEquals(
|
|
ViewerBars(),
|
|
viewerBars(
|
|
imageWidth = 1000,
|
|
imageHeight = 500,
|
|
viewportWidth = 1000,
|
|
viewportHeight = 2000,
|
|
scale = 1f,
|
|
offset = Offset.Zero,
|
|
insets = ViewerBarInsets(status = 100, navigation = 100),
|
|
),
|
|
)
|
|
}
|
|
|
|
@Test
|
|
fun `panning into the status bar hides only that bar`() {
|
|
assertEquals(
|
|
ViewerBars(status = true),
|
|
viewerBars(
|
|
imageWidth = 1000,
|
|
imageHeight = 500,
|
|
viewportWidth = 1000,
|
|
viewportHeight = 2000,
|
|
scale = 2f,
|
|
offset = Offset(0f, -500f),
|
|
insets = ViewerBarInsets(status = 100, navigation = 100),
|
|
),
|
|
)
|
|
}
|
|
|
|
@Test
|
|
fun `native scale reverses fitting a tall image`() {
|
|
assertEquals(
|
|
1.25f,
|
|
nativeScale(
|
|
imageWidth = 1000,
|
|
imageHeight = 2000,
|
|
viewportWidth = 1000,
|
|
viewportHeight = 1600,
|
|
),
|
|
)
|
|
}
|
|
|
|
@Test
|
|
fun `native scale leaves a small image alone`() {
|
|
assertEquals(
|
|
1f,
|
|
nativeScale(
|
|
imageWidth = 500,
|
|
imageHeight = 500,
|
|
viewportWidth = 1000,
|
|
viewportHeight = 1000,
|
|
),
|
|
)
|
|
}
|
|
|
|
@Test
|
|
fun `zoom keeps the region panned to in the center`() {
|
|
assertEquals(
|
|
Offset(240f, -160f),
|
|
zoomOffset(
|
|
offset = Offset(120f, -80f),
|
|
centroid = Offset(500f, 1000f),
|
|
pan = Offset.Zero,
|
|
oldScale = 2f,
|
|
newScale = 4f,
|
|
viewportCenter = Offset(500f, 1000f),
|
|
),
|
|
)
|
|
}
|
|
|
|
@Test
|
|
fun `zoom keeps an off-center pinch beneath moving fingers`() {
|
|
assertEquals(
|
|
Offset(460f, 420f),
|
|
zoomOffset(
|
|
offset = Offset(100f, -100f),
|
|
centroid = Offset(250f, 400f),
|
|
pan = Offset(10f, 20f),
|
|
oldScale = 2f,
|
|
newScale = 4f,
|
|
viewportCenter = Offset(500f, 1000f),
|
|
),
|
|
)
|
|
}
|
|
}
|