Skip to content

Commit

Permalink
Tests for SettingsScreen (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
thebino authored Jul 27, 2023
1 parent 73cfe8b commit a5fe1c0
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ fun SettingsScreen(
@ReferenceDevices
@Composable
private fun Settings(
@PreviewParameter(PreviewAccountProvider::class) uiState: SettingsUiState,
@PreviewParameter(SettingsUiStateProvider::class) uiState: SettingsUiState,
) {
AppTheme {
SettingsScreen(
Expand All @@ -189,15 +189,25 @@ private fun Settings(
}
}

internal class PreviewAccountProvider : PreviewParameterProvider<SettingsUiState> {
internal class SettingsUiStateProvider : PreviewParameterProvider<SettingsUiState> {
override val values = sequenceOf(
SettingsUiState(
serverStatus = ServerStatus.UNAVAILABLE,
isServerSetupExpanded = true,
host = "https://demo.photos.network",
isHostVerified = true,
appVersion = "1.0.0",
),
SettingsUiState(
serverStatus = ServerStatus.PROGRESS,
isServerSetupExpanded = false,
appVersion = "1.0.0",
),
SettingsUiState(
serverStatus = ServerStatus.AVAILABLE,
isServerSetupExpanded = false,
appVersion = "1.0.0",
),
SettingsUiState(serverStatus = ServerStatus.PROGRESS, isServerSetupExpanded = true),
SettingsUiState(serverStatus = ServerStatus.AVAILABLE, isServerSetupExpanded = true),
)
override val count: Int = values.count()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2020-2023 Photos.network developers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package photos.network.ui.settings

import app.cash.paparazzi.DeviceConfig
import app.cash.paparazzi.InstantAnimationsRule
import app.cash.paparazzi.Paparazzi
import com.android.ide.common.rendering.api.SessionParams
import org.junit.Rule
import org.junit.Test
import photos.network.api.ServerStatus
import photos.network.ui.common.theme.AppTheme

class SettingsScreen {
@get:Rule
val instantAnimationsRule = InstantAnimationsRule()

@get:Rule
val paparazzi = Paparazzi(
deviceConfig = DeviceConfig.PIXEL_5,
showSystemUi = false,
supportsRtl = true,
renderingMode = SessionParams.RenderingMode.SHRINK,
)

@Test
fun default_dark() {
paparazzi.snapshot {
AppTheme(useDarkTheme = true) {
SettingsScreen(
uiState = SettingsUiState(
serverStatus = ServerStatus.UNAVAILABLE,
isServerSetupExpanded = true,
host = "https://demo.photos.network",
isHostVerified = true,
appVersion = "1.0.0",
),
)
}
}
}

@Test
fun default_light() {
paparazzi.snapshot {
AppTheme(useDarkTheme = false) {
SettingsScreen(
uiState = SettingsUiState(
serverStatus = ServerStatus.UNAVAILABLE,
isServerSetupExpanded = true,
host = "https://demo.photos.network",
isHostVerified = true,
appVersion = "1.0.0",
),
)
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a5fe1c0

Please sign in to comment.