Skip to content

Commit 5ddf0a8

Browse files
committed
Add screenshot tests
1 parent 5d194bf commit 5ddf0a8

68 files changed

Lines changed: 219 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
package io.homeassistant.companion.android.frontend
2+
3+
import android.annotation.SuppressLint
4+
import android.webkit.WebChromeClient
5+
import android.webkit.WebViewClient
6+
import androidx.compose.runtime.Composable
7+
import com.android.tools.screenshot.PreviewTest
8+
import com.wifi.improv.DeviceState
9+
import com.wifi.improv.ErrorState
10+
import io.homeassistant.companion.android.common.compose.theme.HAThemeForPreview
11+
import io.homeassistant.companion.android.frontend.improv.ImprovUIState
12+
import io.homeassistant.companion.android.frontend.js.FrontendJsBridge
13+
import io.homeassistant.companion.android.frontend.permissions.PermissionRequest
14+
import io.homeassistant.companion.android.util.compose.HAPreviews
15+
16+
/**
17+
* Screenshot coverage for the improv flow as composed inside [FrontendScreenContent]: both the
18+
* onboarding bottom sheet (driven by [ImprovUIState] variants) and the permission rationale
19+
* prompt (driven by [PermissionRequest.Improv] with `showRationale = true`).
20+
*/
21+
@SuppressLint("InlinedApi")
22+
class FrontendScreenImprovScreenshotTest {
23+
24+
@PreviewTest
25+
@HAPreviews
26+
@Composable
27+
fun `FrontendScreen Improv SearchingDevice`() {
28+
HAThemeForPreview {
29+
FrontendImprovContent(
30+
improvUiState = ImprovUIState.SearchingDevice(deviceName = "Smart Plug"),
31+
)
32+
}
33+
}
34+
35+
@PreviewTest
36+
@HAPreviews
37+
@Composable
38+
fun `FrontendScreen Improv ConfiguringDevice`() {
39+
HAThemeForPreview {
40+
FrontendImprovContent(
41+
improvUiState = ImprovUIState.ConfiguringDevice(
42+
deviceName = "Smart Plug",
43+
deviceAddress = "A1:B2:C3:D4:E5:F6",
44+
activeSsid = "Home Wi-Fi",
45+
),
46+
)
47+
}
48+
}
49+
50+
@PreviewTest
51+
@HAPreviews
52+
@Composable
53+
fun `FrontendScreen Improv Provisioning connecting`() {
54+
HAThemeForPreview {
55+
FrontendImprovContent(
56+
improvUiState = ImprovUIState.Provisioning(
57+
deviceName = "Smart Plug",
58+
deviceAddress = "A1:B2:C3:D4:E5:F6",
59+
state = null,
60+
),
61+
)
62+
}
63+
}
64+
65+
@PreviewTest
66+
@HAPreviews
67+
@Composable
68+
fun `FrontendScreen Improv Provisioning authorization required`() {
69+
HAThemeForPreview {
70+
FrontendImprovContent(
71+
improvUiState = ImprovUIState.Provisioning(
72+
deviceName = "Smart Plug",
73+
deviceAddress = "A1:B2:C3:D4:E5:F6",
74+
state = DeviceState.AUTHORIZATION_REQUIRED,
75+
),
76+
)
77+
}
78+
}
79+
80+
@PreviewTest
81+
@HAPreviews
82+
@Composable
83+
fun `FrontendScreen Improv Provisioning sending wifi`() {
84+
HAThemeForPreview {
85+
FrontendImprovContent(
86+
improvUiState = ImprovUIState.Provisioning(
87+
deviceName = "Smart Plug",
88+
deviceAddress = "A1:B2:C3:D4:E5:F6",
89+
state = DeviceState.PROVISIONING,
90+
),
91+
)
92+
}
93+
}
94+
95+
@PreviewTest
96+
@HAPreviews
97+
@Composable
98+
fun `FrontendScreen Improv Errored unable to connect`() {
99+
HAThemeForPreview {
100+
FrontendImprovContent(
101+
improvUiState = ImprovUIState.Errored(
102+
deviceName = "Smart Plug",
103+
deviceAddress = "A1:B2:C3:D4:E5:F6",
104+
error = ErrorState.UNABLE_TO_CONNECT,
105+
),
106+
)
107+
}
108+
}
109+
110+
@PreviewTest
111+
@HAPreviews
112+
@Composable
113+
fun `FrontendScreen Improv Errored not authorized`() {
114+
HAThemeForPreview {
115+
FrontendImprovContent(
116+
improvUiState = ImprovUIState.Errored(
117+
deviceName = "Smart Plug",
118+
deviceAddress = "A1:B2:C3:D4:E5:F6",
119+
error = ErrorState.NOT_AUTHORIZED,
120+
),
121+
)
122+
}
123+
}
124+
125+
@PreviewTest
126+
@HAPreviews
127+
@Composable
128+
fun `FrontendScreen Improv Provisioned`() {
129+
HAThemeForPreview {
130+
FrontendImprovContent(
131+
improvUiState = ImprovUIState.Provisioned(domain = "esphome"),
132+
)
133+
}
134+
}
135+
136+
@PreviewTest
137+
@HAPreviews
138+
@Composable
139+
fun `FrontendScreen Improv permission rationale Bluetooth and Location`() {
140+
HAThemeForPreview {
141+
FrontendImprovContent(
142+
pendingPermissionRequest = PermissionRequest.Improv(
143+
permissions = listOf(
144+
android.Manifest.permission.BLUETOOTH_SCAN,
145+
android.Manifest.permission.ACCESS_FINE_LOCATION,
146+
),
147+
showRationale = true,
148+
onResult = {},
149+
onDismiss = {},
150+
),
151+
)
152+
}
153+
}
154+
155+
@PreviewTest
156+
@HAPreviews
157+
@Composable
158+
fun `FrontendScreen Improv permission rationale Bluetooth only`() {
159+
HAThemeForPreview {
160+
FrontendImprovContent(
161+
pendingPermissionRequest = PermissionRequest.Improv(
162+
permissions = listOf(
163+
android.Manifest.permission.BLUETOOTH_SCAN,
164+
android.Manifest.permission.BLUETOOTH_CONNECT,
165+
),
166+
showRationale = true,
167+
onResult = {},
168+
onDismiss = {},
169+
),
170+
)
171+
}
172+
}
173+
174+
@PreviewTest
175+
@HAPreviews
176+
@Composable
177+
fun `FrontendScreen Improv permission rationale Location only`() {
178+
HAThemeForPreview {
179+
FrontendImprovContent(
180+
pendingPermissionRequest = PermissionRequest.Improv(
181+
permissions = listOf(android.Manifest.permission.ACCESS_FINE_LOCATION),
182+
showRationale = true,
183+
onResult = {},
184+
onDismiss = {},
185+
),
186+
)
187+
}
188+
}
189+
190+
@Composable
191+
private fun FrontendImprovContent(
192+
improvUiState: ImprovUIState? = null,
193+
pendingPermissionRequest: PermissionRequest? = null,
194+
) {
195+
FrontendScreenContent(
196+
onBackClick = {},
197+
viewState = FrontendViewState.Content(
198+
serverId = 1,
199+
url = "https://example.com",
200+
improvUiState = improvUiState,
201+
),
202+
pendingPermissionRequest = pendingPermissionRequest,
203+
webViewClient = WebViewClient(),
204+
webChromeClient = WebChromeClient(),
205+
frontendJsCallback = FrontendJsBridge.noOp,
206+
onBlockInsecureRetry = {},
207+
onOpenExternalLink = {},
208+
onBlockInsecureHelpClick = {},
209+
onOpenSettings = {},
210+
onChangeSecurityLevel = {},
211+
onOpenLocationSettings = {},
212+
onConfigureHomeNetwork = { _ -> },
213+
onSecurityLevelHelpClick = {},
214+
onShowSnackbar = { _, _ -> true },
215+
onWebViewCreationFailed = {},
216+
)
217+
}
218+
}

0 commit comments

Comments
 (0)