From 4c2243cda13a50100f697d9d0259440d09d5fb05 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Thu, 2 Jul 2026 17:40:14 +0300 Subject: [PATCH] Fix search screen preview tests and add snapshots --- .../Screens/SearchScreen/View/SearchScreen.swift | 13 ++++++++++++- .../PreviewTests/searchScreen.Empty-iPad-en-GB.png | 4 ++-- .../PreviewTests/searchScreen.Empty-iPad-pseudo.png | 4 ++-- .../searchScreen.Empty-iPhone-en-GB.png | 4 ++-- .../searchScreen.Empty-iPhone-pseudo.png | 4 ++-- .../searchScreen.Loading-messages-iPad-en-GB.png | 3 +++ .../searchScreen.Loading-messages-iPad-pseudo.png | 3 +++ .../searchScreen.Loading-messages-iPhone-en-GB.png | 3 +++ .../searchScreen.Loading-messages-iPhone-pseudo.png | 3 +++ .../searchScreen.Messages-iPad-en-GB.png | 3 +++ .../searchScreen.Messages-iPad-pseudo.png | 3 +++ .../searchScreen.Messages-iPhone-en-GB.png | 3 +++ .../searchScreen.Messages-iPhone-pseudo.png | 3 +++ .../searchScreen.No-results-iPad-en-GB.png | 4 ++-- .../searchScreen.No-results-iPad-pseudo.png | 4 ++-- .../searchScreen.No-results-iPhone-en-GB.png | 4 ++-- .../searchScreen.No-results-iPhone-pseudo.png | 4 ++-- .../PreviewTests/searchScreen.Rooms-iPad-en-GB.png | 3 +++ .../PreviewTests/searchScreen.Rooms-iPad-pseudo.png | 3 +++ .../searchScreen.Rooms-iPhone-en-GB.png | 3 +++ .../searchScreen.Rooms-iPhone-pseudo.png | 3 +++ 21 files changed, 64 insertions(+), 17 deletions(-) create mode 100644 PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Loading-messages-iPad-en-GB.png create mode 100644 PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Loading-messages-iPad-pseudo.png create mode 100644 PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Loading-messages-iPhone-en-GB.png create mode 100644 PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Loading-messages-iPhone-pseudo.png create mode 100644 PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Messages-iPad-en-GB.png create mode 100644 PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Messages-iPad-pseudo.png create mode 100644 PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Messages-iPhone-en-GB.png create mode 100644 PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Messages-iPhone-pseudo.png create mode 100644 PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Rooms-iPad-en-GB.png create mode 100644 PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Rooms-iPad-pseudo.png create mode 100644 PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Rooms-iPhone-en-GB.png create mode 100644 PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Rooms-iPhone-pseudo.png diff --git a/ElementX/Sources/Screens/SearchScreen/View/SearchScreen.swift b/ElementX/Sources/Screens/SearchScreen/View/SearchScreen.swift index 23560c749..f0f3fd3be 100644 --- a/ElementX/Sources/Screens/SearchScreen/View/SearchScreen.swift +++ b/ElementX/Sources/Screens/SearchScreen/View/SearchScreen.swift @@ -74,7 +74,7 @@ struct SearchScreen: View { } .frame(maxHeight: .infinity, alignment: .top) .background(Color.compound.bgCanvasDefault) - .searchable(text: $context.searchQuery, placement: .toolbarPrincipal) + .conditionalSearchable(searchQuery: $context.searchQuery) .searchFocused($isSearchFieldFocused) .autocorrectionDisabled(true) .background(tabShortcuts) @@ -213,6 +213,17 @@ struct SearchScreen: View { } } +private extension View { + /// Searchable makes the preview contents randomly appear lower + @ViewBuilder func conditionalSearchable(searchQuery: Binding) -> some View { + if !ProcessInfo.isXcodePreview, !ProcessInfo.isRunningTests { + searchable(text: searchQuery, placement: .toolbarPrincipal) + } else { + self + } + } +} + private struct SearchScreenRoomCell: View { let room: SearchScreenRoom let context: SearchScreenViewModel.Context diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Empty-iPad-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Empty-iPad-en-GB.png index fd8c9a10a..a5b339a1f 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Empty-iPad-en-GB.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Empty-iPad-en-GB.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0a93a6802d8a053abd390e9311921294dfbab18844eb17a63eaf4b8c623173a9 -size 85119 +oid sha256:8332e6211e8fdad7dd1623748771d2008c17c2d8193a3ffe957346c8d94f4086 +size 94641 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Empty-iPad-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Empty-iPad-pseudo.png index cd515fcab..a6445b31a 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Empty-iPad-pseudo.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Empty-iPad-pseudo.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:72835c30b6f459759cbbae44aaba4aed0c39674c49879602c7a8a319323b9db1 -size 88205 +oid sha256:aa5e1fa38d7bbfadb55daf260435e11c9860ae1f63411dfb756cbcf6a50f70c5 +size 102168 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Empty-iPhone-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Empty-iPhone-en-GB.png index c92f88904..9d0713129 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Empty-iPhone-en-GB.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Empty-iPhone-en-GB.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:25f1c159081bfcf7e1fb181bb6f1ee2f614a1ae3759052cc5dac3f7266b271ba -size 42662 +oid sha256:b5fa800dc1baf2e5e52b39cdeb460d0463bde64f3ab721124050cfc992f308cf +size 50335 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Empty-iPhone-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Empty-iPhone-pseudo.png index d1ff6de07..93d69800f 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Empty-iPhone-pseudo.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Empty-iPhone-pseudo.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:513a8d3815582253be1eecf22a7726c7917c9e83e7465aa5e7b90ef2d7944c1e -size 49713 +oid sha256:98a12236fc3813000eec89080c4a5e6fb4414ab690750c0c9fbf6ddc79b5d7fb +size 61874 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Loading-messages-iPad-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Loading-messages-iPad-en-GB.png new file mode 100644 index 000000000..0269dee21 --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Loading-messages-iPad-en-GB.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:11753001e5dbeb4bf3d2b71991096ffacba68ac9e4b244763affcefca20567cb +size 94885 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Loading-messages-iPad-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Loading-messages-iPad-pseudo.png new file mode 100644 index 000000000..7a646a095 --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Loading-messages-iPad-pseudo.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:df702d4f0929233e211341424ff14f8ed6ff1f558f7dcbfdcc627338e0612c79 +size 103618 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Loading-messages-iPhone-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Loading-messages-iPhone-en-GB.png new file mode 100644 index 000000000..4d6edbfd7 --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Loading-messages-iPhone-en-GB.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:759a3218edd55b0d4505108523f6d620a5db73fbf5f3b46ceb4f348e2b890486 +size 52394 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Loading-messages-iPhone-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Loading-messages-iPhone-pseudo.png new file mode 100644 index 000000000..b681524b5 --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Loading-messages-iPhone-pseudo.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd7cdf5319f41f891a6577565db68863f002c1fec23f7be265e039d3a51aaa9d +size 62596 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Messages-iPad-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Messages-iPad-en-GB.png new file mode 100644 index 000000000..0269dee21 --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Messages-iPad-en-GB.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:11753001e5dbeb4bf3d2b71991096ffacba68ac9e4b244763affcefca20567cb +size 94885 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Messages-iPad-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Messages-iPad-pseudo.png new file mode 100644 index 000000000..7a646a095 --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Messages-iPad-pseudo.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:df702d4f0929233e211341424ff14f8ed6ff1f558f7dcbfdcc627338e0612c79 +size 103618 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Messages-iPhone-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Messages-iPhone-en-GB.png new file mode 100644 index 000000000..4d6edbfd7 --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Messages-iPhone-en-GB.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:759a3218edd55b0d4505108523f6d620a5db73fbf5f3b46ceb4f348e2b890486 +size 52394 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Messages-iPhone-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Messages-iPhone-pseudo.png new file mode 100644 index 000000000..b681524b5 --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Messages-iPhone-pseudo.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd7cdf5319f41f891a6577565db68863f002c1fec23f7be265e039d3a51aaa9d +size 62596 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.No-results-iPad-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.No-results-iPad-en-GB.png index dba50b36d..657fc130b 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.No-results-iPad-en-GB.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.No-results-iPad-en-GB.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3d6cd51861f45a9e393eb3194ee7224a094646ce4385f2aa8ecb1be404bbaa6d -size 87898 +oid sha256:2e2a5821c0b45c566cbf23b7fc4a20c89d944e3b7fa7d0e527976926fe162386 +size 94721 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.No-results-iPad-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.No-results-iPad-pseudo.png index 808e93546..da5986713 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.No-results-iPad-pseudo.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.No-results-iPad-pseudo.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c96db7daacd17e38fb6d0d74cc9de51f52b0c17fb2c02c2c162d8384ca1ab6d2 -size 94243 +oid sha256:a31e6c8f3c6c12244291dfbe8796d46e68f77b7f4601bd6af8ef248024ce84c8 +size 102826 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.No-results-iPhone-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.No-results-iPhone-en-GB.png index c789b0415..46e831804 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.No-results-iPhone-en-GB.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.No-results-iPhone-en-GB.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:31369bff674e454cb3cacdcb7a33efe035c838e4d09b549ba07979597d74a744 -size 49368 +oid sha256:09248c6998a1e731ed447c927f2f8a03c3ed72083090f56a8d8864d2d51db579 +size 51932 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.No-results-iPhone-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.No-results-iPhone-pseudo.png index 977678ec9..817bca09c 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.No-results-iPhone-pseudo.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.No-results-iPhone-pseudo.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7cc94abaa65358e0cf82a0635b0aaa5f7858f0a765b3ddf0f8b647cba493cfe6 -size 58249 +oid sha256:1f28caa2bc1a7aef205404d2af3ffb348b389c9eb83169482fcc1350c6120bab +size 62489 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Rooms-iPad-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Rooms-iPad-en-GB.png new file mode 100644 index 000000000..54d4ddaba --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Rooms-iPad-en-GB.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b4aa5c23728897a395066dab65511f747347ed866968d96191377a206c037938 +size 174905 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Rooms-iPad-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Rooms-iPad-pseudo.png new file mode 100644 index 000000000..142797aa1 --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Rooms-iPad-pseudo.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5b58acb1090b90d13fa175b3dd8bf4318bdb41b51dcbe26d328d7ab0c57be0f4 +size 177766 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Rooms-iPhone-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Rooms-iPhone-en-GB.png new file mode 100644 index 000000000..dae6bd8de --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Rooms-iPhone-en-GB.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:795306316da27b79588f5e941988c9ec851d59aa23b8c0153ffa5401837dc9ec +size 123602 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Rooms-iPhone-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Rooms-iPhone-pseudo.png new file mode 100644 index 000000000..acfae06c3 --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/searchScreen.Rooms-iPhone-pseudo.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1ad0f4d5f683254c0e0cf59f103f462338c77b56616570ef77cd8e334a76243a +size 126165