Skip to content

Commit 7ee8fe3

Browse files
committed
Add WaveformSlider screenshot tests
1 parent 41f0f56 commit 7ee8fe3

9 files changed

Lines changed: 113 additions & 16 deletions

stream-chat-android-compose/api/stream-chat-android-compose.api

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,16 @@ public final class io/getstream/chat/android/compose/ui/components/audio/Composa
11491149
public final fun getLambda$655444177$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
11501150
}
11511151

1152+
public final class io/getstream/chat/android/compose/ui/components/audio/ComposableSingletons$WaveformSliderKt {
1153+
public static final field INSTANCE Lio/getstream/chat/android/compose/ui/components/audio/ComposableSingletons$WaveformSliderKt;
1154+
public fun <init> ()V
1155+
public final fun getLambda$-1036173266$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
1156+
public final fun getLambda$-1516446859$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
1157+
public final fun getLambda$-570083019$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
1158+
public final fun getLambda$53626762$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
1159+
public final fun getLambda$709997198$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
1160+
}
1161+
11521162
public final class io/getstream/chat/android/compose/ui/components/audio/WaveformSliderKt {
11531163
public static final fun StaticWaveformSlider (Ljava/util/List;FZLandroidx/compose/ui/Modifier;IZZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;II)V
11541164
}

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/components/audio/WaveformSlider.kt

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -227,27 +227,40 @@ internal fun WaveformTrack(
227227
@Preview(showBackground = true, widthDp = 250)
228228
@Composable
229229
private fun StaticWaveformSliderAtStartPreview() {
230-
ChatPreviewTheme { StaticWaveformSliderSample(progress = 0f, isPlaying = true) }
230+
ChatPreviewTheme { StaticWaveformSliderAtStart() }
231231
}
232232

233233
@Preview(showBackground = true, widthDp = 250)
234234
@Composable
235235
private fun StaticWaveformSliderMidwayPreview() {
236-
ChatPreviewTheme { StaticWaveformSliderSample(progress = 0.5f, isPlaying = true) }
236+
ChatPreviewTheme { StaticWaveformSliderMidway() }
237237
}
238238

239239
@Preview(showBackground = true, widthDp = 250)
240240
@Composable
241241
private fun StaticWaveformSliderPausedPreview() {
242-
ChatPreviewTheme { StaticWaveformSliderSample(progress = 0.3f, isPlaying = false) }
242+
ChatPreviewTheme { StaticWaveformSliderPaused() }
243243
}
244244

245245
@Preview(showBackground = true, widthDp = 250)
246246
@Composable
247247
private fun StaticWaveformSliderWithoutThumbPreview() {
248-
ChatPreviewTheme { StaticWaveformSliderSample(progress = 0.7f, isPlaying = true, isThumbVisible = false) }
248+
ChatPreviewTheme { StaticWaveformSliderWithoutThumb() }
249249
}
250250

251+
@Composable
252+
internal fun StaticWaveformSliderAtStart() = StaticWaveformSliderSample(progress = 0f, isPlaying = true)
253+
254+
@Composable
255+
internal fun StaticWaveformSliderMidway() = StaticWaveformSliderSample(progress = 0.5f, isPlaying = true)
256+
257+
@Composable
258+
internal fun StaticWaveformSliderPaused() = StaticWaveformSliderSample(progress = 0.3f, isPlaying = false)
259+
260+
@Composable
261+
internal fun StaticWaveformSliderWithoutThumb() =
262+
StaticWaveformSliderSample(progress = 0.7f, isPlaying = true, isThumbVisible = false)
263+
251264
@Composable
252265
private fun StaticWaveformSliderSample(progress: Float, isPlaying: Boolean, isThumbVisible: Boolean = true) {
253266
val previewWaveform = remember {
@@ -269,18 +282,22 @@ private fun StaticWaveformSliderSample(progress: Float, isPlaying: Boolean, isTh
269282
@Preview(showBackground = true, widthDp = 250)
270283
@Composable
271284
private fun FullWaveformTrackPreview() {
272-
ChatPreviewTheme {
273-
val waveform = List(100) { (it + 1) / 100f }
274-
WaveformTrack(
275-
modifier = Modifier
276-
.fillMaxWidth()
277-
.height(60.dp),
278-
waveformData = waveform,
279-
progress = 1f,
280-
adjustBarWidthToLimit = true,
281-
visibleBarLimit = 100,
282-
)
283-
}
285+
ChatPreviewTheme { FullWaveformTrack() }
286+
}
287+
288+
@Suppress("MagicNumber")
289+
@Composable
290+
internal fun FullWaveformTrack() {
291+
val waveform = List(100) { (it + 1) / 100f }
292+
WaveformTrack(
293+
modifier = Modifier
294+
.fillMaxWidth()
295+
.height(36.dp),
296+
waveformData = waveform,
297+
progress = 1f,
298+
adjustBarWidthToLimit = true,
299+
visibleBarLimit = 100,
300+
)
284301
}
285302

286303
private fun Offset.toHorizontalProgress(base: Float, isRtl: Boolean): Float {
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2014-2026 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Stream License;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://github.com/GetStream/stream-chat-android/blob/main/LICENSE
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.getstream.chat.android.compose.ui.components.audio
18+
19+
import androidx.compose.runtime.CompositionLocalProvider
20+
import androidx.compose.ui.platform.LocalLayoutDirection
21+
import androidx.compose.ui.unit.LayoutDirection
22+
import app.cash.paparazzi.DeviceConfig
23+
import app.cash.paparazzi.Paparazzi
24+
import com.android.ide.common.rendering.api.SessionParams
25+
import io.getstream.chat.android.compose.ui.PaparazziComposeTest
26+
import org.junit.Rule
27+
import org.junit.Test
28+
29+
internal class WaveformSliderTest : PaparazziComposeTest {
30+
31+
@get:Rule
32+
override val paparazzi = Paparazzi(
33+
deviceConfig = DeviceConfig.PIXEL_2,
34+
renderingMode = SessionParams.RenderingMode.SHRINK,
35+
)
36+
37+
@Test
38+
fun `slider playing at start`() {
39+
snapshotWithDarkModeRow { StaticWaveformSliderAtStart() }
40+
}
41+
42+
@Test
43+
fun `slider playing midway`() {
44+
snapshotWithDarkModeRow { StaticWaveformSliderMidway() }
45+
}
46+
47+
@Test
48+
fun `slider paused`() {
49+
snapshotWithDarkModeRow { StaticWaveformSliderPaused() }
50+
}
51+
52+
@Test
53+
fun `slider without thumb`() {
54+
snapshotWithDarkModeRow { StaticWaveformSliderWithoutThumb() }
55+
}
56+
57+
@Test
58+
fun `full track`() {
59+
snapshotWithDarkModeRow { FullWaveformTrack() }
60+
}
61+
62+
@Test
63+
fun `slider playing midway rtl`() {
64+
snapshotWithDarkModeRow {
65+
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) {
66+
StaticWaveformSliderMidway()
67+
}
68+
}
69+
}
70+
}
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)