diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index ed94e2d78a..3848191bf7 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -21,6 +21,18 @@ jobs: - name: Run code quality check suite run: ./tools/check/check_code_quality.sh + checkScreesnhot: + name: Search for invalid screenshot files + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.9 + uses: actions/setup-python@v5 + with: + python-version: 3.9 + - name: Search for invalid screenshot files + run: ./tools/test/checkInvalidScreenshots.py + check: name: Project Check Suite runs-on: ubuntu-latest diff --git a/.github/workflows/sync-sas-strings.yml b/.github/workflows/sync-sas-strings.yml index ba0a1fbdc7..79de1b7691 100644 --- a/.github/workflows/sync-sas-strings.yml +++ b/.github/workflows/sync-sas-strings.yml @@ -13,7 +13,7 @@ jobs: # No concurrency required, runs every time on a schedule. steps: - uses: actions/checkout@v4 - - name: Set up Python 3.8 + - name: Set up Python 3.9 uses: actions/setup-python@v5 with: python-version: 3.9 diff --git a/.gitignore b/.gitignore index d9614fd6e2..823b4e4872 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,9 @@ out/ .gradle/ build/ +# Python cache +__pycache__/ + # Local configuration file (sdk path, etc) local.properties diff --git a/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/userlist/UserListStateProvider.kt b/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/userlist/UserListStateProvider.kt index 225812b415..193fa7e71f 100644 --- a/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/userlist/UserListStateProvider.kt +++ b/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/userlist/UserListStateProvider.kt @@ -19,6 +19,7 @@ package io.element.android.features.createroom.impl.userlist import androidx.compose.ui.tooling.preview.PreviewParameterProvider import io.element.android.libraries.designsystem.theme.components.SearchBarResultState import io.element.android.libraries.matrix.ui.components.aMatrixUserList +import io.element.android.libraries.usersearch.api.UserSearchResult import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toImmutableList @@ -38,14 +39,14 @@ open class UserListStateProvider : PreviewParameterProvider { isSearchActive = true, searchQuery = "@someone:matrix.org", selectedUsers = aMatrixUserList().toImmutableList(), - searchResults = SearchBarResultState.Results(aListOfSelectedUsers()), + searchResults = SearchBarResultState.Results(aListOfUserSearchResults()), ), aUserListState().copy( isSearchActive = true, searchQuery = "@someone:matrix.org", selectionMode = SelectionMode.Multiple, selectedUsers = aMatrixUserList().toImmutableList(), - searchResults = SearchBarResultState.Results(aListOfSelectedUsers()), + searchResults = SearchBarResultState.Results(aListOfUserSearchResults()), ), aUserListState().copy( isSearchActive = true, @@ -67,3 +68,4 @@ fun aUserListState() = UserListState( ) fun aListOfSelectedUsers() = aMatrixUserList().take(6).toImmutableList() +fun aListOfUserSearchResults() = aMatrixUserList().take(6).map { UserSearchResult(it) }.toImmutableList() diff --git a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/ModalBottomSheet.kt b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/ModalBottomSheet.kt index 6230592edd..2a11472f9e 100644 --- a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/ModalBottomSheet.kt +++ b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/ModalBottomSheet.kt @@ -31,6 +31,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Shape +import androidx.compose.ui.platform.LocalInspectionMode import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp @@ -58,10 +59,11 @@ fun ModalBottomSheet( windowInsets: WindowInsets = BottomSheetDefaults.windowInsets, content: @Composable ColumnScope.() -> Unit, ) { + val safeSheetState = if (LocalInspectionMode.current) sheetStateForPreview() else sheetState androidx.compose.material3.ModalBottomSheet( onDismissRequest = onDismissRequest, modifier = modifier, - sheetState = sheetState, + sheetState = safeSheetState, shape = shape, containerColor = containerColor, contentColor = contentColor, @@ -102,7 +104,6 @@ private fun ContentToPreview() { ) { ModalBottomSheet( onDismissRequest = {}, - sheetState = sheetStateForPreview(), ) { Text( text = "Sheet Content", diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.createroom.impl.components_UserListView_null_UserListView-Day-2_3_null_5,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.createroom.impl.components_UserListView_null_UserListView-Day-2_3_null_5,NEXUS_5,1.0,en].png index 2f2ac0e0c0..1380fc9c04 100644 --- a/tests/uitests/src/test/snapshots/images/ui_S_t[f.createroom.impl.components_UserListView_null_UserListView-Day-2_3_null_5,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.createroom.impl.components_UserListView_null_UserListView-Day-2_3_null_5,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3764d8bd7dc2783a8af43aad65a217d7e533ed17c4d4367b7994470bf35b62b0 -size 4462 +oid sha256:ac4629968854e34cb676e9348bdad7eb4bd747aed13bf0283d5a9382fde1a46d +size 41643 diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.createroom.impl.components_UserListView_null_UserListView-Day-2_3_null_6,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.createroom.impl.components_UserListView_null_UserListView-Day-2_3_null_6,NEXUS_5,1.0,en].png index 2f2ac0e0c0..cd136e61bd 100644 --- a/tests/uitests/src/test/snapshots/images/ui_S_t[f.createroom.impl.components_UserListView_null_UserListView-Day-2_3_null_6,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.createroom.impl.components_UserListView_null_UserListView-Day-2_3_null_6,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3764d8bd7dc2783a8af43aad65a217d7e533ed17c4d4367b7994470bf35b62b0 -size 4462 +oid sha256:33eb14ad0f5b9a8cd73122b87f217e76e0d0527df009bd2669643153671bd889 +size 57450 diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.createroom.impl.components_UserListView_null_UserListView-Night-2_4_null_5,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.createroom.impl.components_UserListView_null_UserListView-Night-2_4_null_5,NEXUS_5,1.0,en].png index 2f2ac0e0c0..aee005a9ee 100644 --- a/tests/uitests/src/test/snapshots/images/ui_S_t[f.createroom.impl.components_UserListView_null_UserListView-Night-2_4_null_5,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.createroom.impl.components_UserListView_null_UserListView-Night-2_4_null_5,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3764d8bd7dc2783a8af43aad65a217d7e533ed17c4d4367b7994470bf35b62b0 -size 4462 +oid sha256:2120e963b9fd9ea9397b4a41d0d52906dd49f4c71530f2c8fdaad730239f428d +size 40630 diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.createroom.impl.components_UserListView_null_UserListView-Night-2_4_null_6,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.createroom.impl.components_UserListView_null_UserListView-Night-2_4_null_6,NEXUS_5,1.0,en].png index 2f2ac0e0c0..73a2881ea0 100644 --- a/tests/uitests/src/test/snapshots/images/ui_S_t[f.createroom.impl.components_UserListView_null_UserListView-Night-2_4_null_6,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.createroom.impl.components_UserListView_null_UserListView-Night-2_4_null_6,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3764d8bd7dc2783a8af43aad65a217d7e533ed17c4d4367b7994470bf35b62b0 -size 4462 +oid sha256:6e044b924c9c148788189980498c768875ca3ac4db6e048dfefa105b04586caa +size 56246 diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl_MessagesView_null_MessagesView-Day-0_0_null_2,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl_MessagesView_null_MessagesView-Day-0_0_null_2,NEXUS_5,1.0,en].png index 2f2ac0e0c0..e8e53e2110 100644 --- a/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl_MessagesView_null_MessagesView-Day-0_0_null_2,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl_MessagesView_null_MessagesView-Day-0_0_null_2,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3764d8bd7dc2783a8af43aad65a217d7e533ed17c4d4367b7994470bf35b62b0 -size 4462 +oid sha256:5f6f3350f9e409d8a6e87116b5500f519cad1f1d731f03b3674412207c6f4b1e +size 28044 diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl_MessagesView_null_MessagesView-Night-0_1_null_2,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl_MessagesView_null_MessagesView-Night-0_1_null_2,NEXUS_5,1.0,en].png index 2f2ac0e0c0..35a7ef73bc 100644 --- a/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl_MessagesView_null_MessagesView-Night-0_1_null_2,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl_MessagesView_null_MessagesView-Night-0_1_null_2,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3764d8bd7dc2783a8af43aad65a217d7e533ed17c4d4367b7994470bf35b62b0 -size 4462 +oid sha256:e56586426695abaf31a2e5fd3f4367177e69378daa5ed4f8a19ec93f768a60ff +size 24781 diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.roomlist.impl_RoomListView_null_RoomListView-Day-3_4_null_5,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.roomlist.impl_RoomListView_null_RoomListView-Day-3_4_null_5,NEXUS_5,1.0,en].png index 2f2ac0e0c0..b64e65bcf2 100644 --- a/tests/uitests/src/test/snapshots/images/ui_S_t[f.roomlist.impl_RoomListView_null_RoomListView-Day-3_4_null_5,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.roomlist.impl_RoomListView_null_RoomListView-Day-3_4_null_5,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3764d8bd7dc2783a8af43aad65a217d7e533ed17c4d4367b7994470bf35b62b0 -size 4462 +oid sha256:56aac7fa99de7ea4729c6bf33d938c627a2eb155149dcc07a4bdbc1c3a24bbd3 +size 23949 diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.roomlist.impl_RoomListView_null_RoomListView-Day-3_4_null_6,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.roomlist.impl_RoomListView_null_RoomListView-Day-3_4_null_6,NEXUS_5,1.0,en].png index 2f2ac0e0c0..6ff168997b 100644 --- a/tests/uitests/src/test/snapshots/images/ui_S_t[f.roomlist.impl_RoomListView_null_RoomListView-Day-3_4_null_6,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.roomlist.impl_RoomListView_null_RoomListView-Day-3_4_null_6,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3764d8bd7dc2783a8af43aad65a217d7e533ed17c4d4367b7994470bf35b62b0 -size 4462 +oid sha256:2202f45b9b2a9c99b7a3b2744e22077546b7154fb748cf6a83470e89971cb8cc +size 21801 diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.roomlist.impl_RoomListView_null_RoomListView-Night-3_5_null_5,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.roomlist.impl_RoomListView_null_RoomListView-Night-3_5_null_5,NEXUS_5,1.0,en].png index 2f2ac0e0c0..d3a7f2c973 100644 --- a/tests/uitests/src/test/snapshots/images/ui_S_t[f.roomlist.impl_RoomListView_null_RoomListView-Night-3_5_null_5,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.roomlist.impl_RoomListView_null_RoomListView-Night-3_5_null_5,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3764d8bd7dc2783a8af43aad65a217d7e533ed17c4d4367b7994470bf35b62b0 -size 4462 +oid sha256:38dcfa8c21ff100830ba53ac4a2555784b8e132031cb82ea90fad3cc153152e0 +size 21177 diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.roomlist.impl_RoomListView_null_RoomListView-Night-3_5_null_6,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.roomlist.impl_RoomListView_null_RoomListView-Night-3_5_null_6,NEXUS_5,1.0,en].png index 2f2ac0e0c0..ee9afc08a6 100644 --- a/tests/uitests/src/test/snapshots/images/ui_S_t[f.roomlist.impl_RoomListView_null_RoomListView-Night-3_5_null_6,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.roomlist.impl_RoomListView_null_RoomListView-Night-3_5_null_6,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3764d8bd7dc2783a8af43aad65a217d7e533ed17c4d4367b7994470bf35b62b0 -size 4462 +oid sha256:26352ab65c7d2ff59bcb63d05b398baae77f7e04a4120ebf2c6353fdd011fa3e +size 19330 diff --git a/tools/test/checkInvalidScreenshots.py b/tools/test/checkInvalidScreenshots.py new file mode 100755 index 0000000000..ab5ae5e952 --- /dev/null +++ b/tools/test/checkInvalidScreenshots.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 + +# Copyright (c) 2024 New Vector Ltd +# +# 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 +# +# http://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. + +import os + +from util import compare + + +def checkInvalidScreenshots(reference): + __doc__ = "Detect invalid screenshot, by comparing to an invalid reference." + path_of_screenshots = "tests/uitests/src/test/snapshots/images/" + files = os.listdir(path_of_screenshots) + counter = 0 + for file in files: + if not compare(reference, path_of_screenshots + file): + print("Invalid screenshot detected: " + file) + counter += 1 + return counter + + +def main(): + invalid_screenshot_reference_path = "tools/test/invalid_screenshot.png" + result = checkInvalidScreenshots(invalid_screenshot_reference_path) + if result > 0: + print("%d invalid screenshot(s) detected" % result) + print("Please check that the Preview is OK in Android Studio. You may want to use a Fake Composable for the screenshot to render correctly.") + exit(1) + else: + print("No invalid screenshot detected!") + exit(0) + + +main() diff --git a/tools/test/generateAllScreenshots.py b/tools/test/generateAllScreenshots.py index 010f6931a6..6ba1ab2b67 100755 --- a/tools/test/generateAllScreenshots.py +++ b/tools/test/generateAllScreenshots.py @@ -3,6 +3,7 @@ import os import re import sys +from util import compare # Read all arguments and return a list of them, this are the languages list. def readArguments(): @@ -40,20 +41,6 @@ def detectLanguages(): return languages -def compare(file1, file2): - __doc__ = "Compare two files, return True if different, False if identical." - # Compare file size - file1_stats = os.stat(file1) - file2_stats = os.stat(file2) - if file1_stats.st_size != file2_stats.st_size: - return True - # Compare file content - with open(file1, "rb") as f1, open(file2, "rb") as f2: - content1 = f1.read() - content2 = f2.read() - return content1 != content2 - - def deleteDuplicatedScreenshots(lang): __doc__ = "Delete screenshots identical to the English version for a language" print("Deleting screenshots identical to the English version for language %s..." % lang) diff --git a/tools/test/invalid_screenshot.png b/tools/test/invalid_screenshot.png new file mode 100644 index 0000000000..8da2be99c2 Binary files /dev/null and b/tools/test/invalid_screenshot.png differ diff --git a/tools/test/util.py b/tools/test/util.py new file mode 100644 index 0000000000..ce9ffc7594 --- /dev/null +++ b/tools/test/util.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +# Copyright (c) 2024 New Vector Ltd +# +# 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 +# +# http://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. + +import os + + +def compare(file1, file2): + __doc__ = "Compare two files, return True if different, False if identical." + # Compare file size + file1_stats = os.stat(file1) + file2_stats = os.stat(file2) + if file1_stats.st_size != file2_stats.st_size: + return True + # Compare file content + with open(file1, "rb") as f1, open(file2, "rb") as f2: + content1 = f1.read() + content2 = f2.read() + return content1 != content2