Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix outdated preview data docs #1153

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions docusaurus/docs/Android/04-ui-components/06-ui-previews.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ Now, you can implement your preview composable like the example below:
@Preview
@Composable
private fun CallContentPreview() {
StreamMockUtils.initializeStreamVideo(LocalContext.current)
StreamPreviewDataUtils.initializeStreamVideo(LocalContext.current)
VideoTheme {
CallContent(
modifier = Modifier.background(color = VideoTheme.colors.appBackground),
call = mockCall,
call = previewCall,
)
}
}
Expand All @@ -49,29 +48,29 @@ After adding the above example to your project, you'll see the following preview

You should follow the steps below to make your previews work well:

1. Initialize a mock `StreamVideo` with the following method: `StreamMockUtils.initializeStreamVideo`.
1. Initialize a mock `StreamVideo` with the following method: `StreamPreviewDataUtils.initializeStreamVideo`.
2. Wrap your composable with the `VideoTheme`.
3. Use the provided mock instances for Stream Video UI components.

This library provides the following mocks:

- **mockCall**: Mock a `Call` that contains few of mock users.
- **mockParticipant**: Mock a `ParticipantState` instance.
- **mockParticipantList**: Mock a list of `ParticipantState` instances.
- **mockUsers**: Mock a list of `User` instances.
- **mockVideoMediaTrack**: Mock a new `MediaTrack` instance.
- **previewCall**: Mock a `Call` that contains few of mock users.
- **previewParticipant**: Mock a `ParticipantState` instance.
- **previewParticipantsList**: Mock a list of `ParticipantState` instances.
- **previewUsers**: Mock a list of `User` instances.
- **previewVideoMediaTrack**: Mock a new `MediaTrack` instance.

For example, you can build a preview Composable for `ParticipantVideo` as in the example below:

```kotlin
@Preview
@Composable
private fun ParticipantVideoPreview() {
StreamMockUtils.initializeStreamVideo(LocalContext.current)
StreamPreviewDataUtils.initializeStreamVideo(LocalContext.current)
VideoTheme {
ParticipantVideoRenderer(
call = mockCall,
participant = mockParticipant,
call = previewCall,
participant = previewParticipant,
)
}
}
Expand Down
10 changes: 5 additions & 5 deletions docusaurus/docs/Android/04-ui-components/07-ui-testing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ScreenTests {
composable: @Composable () -> Unit
) {
paparazzi.snapshot(name = name) {
StreamMockUtils.initializeStreamVideo(LocalContext.current)
StreamPreviewDataUtils.initializeStreamVideo(LocalContext.current)
CompositionLocalProvider(
LocalInspectionMode provides true,
LocalAvatarPreviewPlaceholder provides
Expand All @@ -49,7 +49,7 @@ class ScreenTests {
@Test
fun `snapshot CallContent component`() {
snapshot(name = "CallContent") {
CallContent(call = mockCall)
CallContent(call = previewCall)
}
}

Expand All @@ -58,7 +58,7 @@ class ScreenTests {
snapshot(name = "CallLobby") {
CallLobby(
modifier = Modifier.fillMaxWidth(),
call = mockCall
call = previewCall
)
}
}
Expand All @@ -70,7 +70,7 @@ Let's break the code down line by line.
First, you should initialize Stream Video SDK with the `initializeStreamVideo()` method. You can learn more about our mock library on [UI Previews](07-ui-previews.mdx).

```kotlin
StreamMockUtils.initializeStreamVideo(LocalContext.current)
StreamPreviewDataUtils.initializeStreamVideo(LocalContext.current)
```

Next, you should enable `LocalInspectionMode` with the `CompositionLocalProvider` and allow Stream UI components to be rendered for the test environment.
Expand All @@ -90,7 +90,7 @@ Finally, snapshot Stream Video components or your own Composable functions that
@Test
fun `snapshot CallContent component`() {
snapshot(name = "CallContent") {
CallContent(call = mockCall)
CallContent(call = previewCall)
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public final class io/getstream/video/android/mock/StreamPreviewDataUtils {
}

public final class io/getstream/video/android/mock/StreamPreviewDataUtilsKt {
public static final fun getMockVideoMediaTrack ()Lio/getstream/video/android/core/model/MediaTrack;
public static final fun getPreviewCall ()Lio/getstream/video/android/core/Call;
public static final fun getPreviewMember ()Lio/getstream/video/android/core/MemberState;
public static final fun getPreviewMemberListState ()Ljava/util/List;
Expand All @@ -16,5 +15,6 @@ public final class io/getstream/video/android/mock/StreamPreviewDataUtilsKt {
public static final fun getPreviewThreeMembers ()Ljava/util/List;
public static final fun getPreviewTwoMembers ()Ljava/util/List;
public static final fun getPreviewUsers ()Ljava/util/List;
public static final fun getPreviewVideoMediaTrack ()Lio/getstream/video/android/core/model/MediaTrack;
}

Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public val previewCall: Call = Call(
).apply {
val participants = previewUsers.take(2).map { user ->
val sessionId = if (user == previewUsers.first()) {
sessionId ?: UUID.randomUUID().toString()
sessionId
} else {
UUID.randomUUID().toString()
}
Expand All @@ -70,7 +70,7 @@ public val previewCall: Call = Call(
}

/** Mock a new [MediaTrack]. */
public val mockVideoMediaTrack: MediaTrack
public val previewVideoMediaTrack: MediaTrack
inline get() = io.getstream.video.android.core.model.VideoTrack(
UUID.randomUUID().toString(),
VideoTrack(123),
Expand Down Expand Up @@ -146,7 +146,7 @@ public val previewMemberListState: List<MemberState>
previewCall.state.clearParticipants()
previewUsers.forEach { user ->
val sessionId = if (user == previewUsers.first()) {
previewCall.sessionId ?: UUID.randomUUID().toString()
previewCall.sessionId
} else {
UUID.randomUUID().toString()
}
Expand Down
Loading