From feb87558a8537b9168773b2129d23df12d26d387 Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 13 Mar 2024 15:25:36 +0100 Subject: [PATCH] RoomList : add some more tests --- .../impl/RoomListContentStateProvider.kt | 2 + .../impl/components/RoomListContentView.kt | 5 +- .../RoomListFiltersEmptyStateResourcesTest.kt | 75 +++++++++++++++++++ .../filters/RoomListFiltersPresenterTests.kt | 4 + 4 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 features/roomlist/impl/src/test/kotlin/io/element/android/features/roomlist/impl/filters/RoomListFiltersEmptyStateResourcesTest.kt diff --git a/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListContentStateProvider.kt b/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListContentStateProvider.kt index 7f066628df..284abb5d0f 100644 --- a/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListContentStateProvider.kt +++ b/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListContentStateProvider.kt @@ -19,11 +19,13 @@ package io.element.android.features.roomlist.impl import androidx.compose.ui.tooling.preview.PreviewParameterProvider import io.element.android.features.roomlist.impl.model.RoomListRoomSummary import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.persistentListOf open class RoomListContentStateProvider : PreviewParameterProvider { override val values: Sequence get() = sequenceOf( aRoomsContentState(), + aRoomsContentState(summaries = persistentListOf()), aSkeletonContentState(), anEmptyContentState(), aMigrationContentState(), diff --git a/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/components/RoomListContentView.kt b/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/components/RoomListContentView.kt index 1e3d66750f..1bb5af4e7a 100644 --- a/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/components/RoomListContentView.kt +++ b/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/components/RoomListContentView.kt @@ -56,6 +56,7 @@ import io.element.android.features.roomlist.impl.filters.RoomListFilter import io.element.android.features.roomlist.impl.filters.RoomListFiltersEmptyStateResources import io.element.android.features.roomlist.impl.filters.RoomListFiltersState import io.element.android.features.roomlist.impl.filters.aRoomListFiltersState +import io.element.android.features.roomlist.impl.filters.selection.FilterSelectionState import io.element.android.features.roomlist.impl.migration.MigrationScreenView import io.element.android.features.roomlist.impl.model.RoomListRoomSummary import io.element.android.libraries.designsystem.preview.ElementPreview @@ -311,7 +312,9 @@ private fun EmptyScaffold( internal fun RoomListContentViewPreview(@PreviewParameter(RoomListContentStateProvider::class) state: RoomListContentState) = ElementPreview { RoomListContentView( contentState = state, - filtersState = aRoomListFiltersState(), + filtersState = aRoomListFiltersState( + filterSelectionStates = RoomListFilter.entries.map { FilterSelectionState(it, isSelected = true) } + ), eventSink = {}, onVerifyClicked = { }, onConfirmRecoveryKeyClicked = { }, diff --git a/features/roomlist/impl/src/test/kotlin/io/element/android/features/roomlist/impl/filters/RoomListFiltersEmptyStateResourcesTest.kt b/features/roomlist/impl/src/test/kotlin/io/element/android/features/roomlist/impl/filters/RoomListFiltersEmptyStateResourcesTest.kt new file mode 100644 index 0000000000..b9cdf5a03f --- /dev/null +++ b/features/roomlist/impl/src/test/kotlin/io/element/android/features/roomlist/impl/filters/RoomListFiltersEmptyStateResourcesTest.kt @@ -0,0 +1,75 @@ +/* + * 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. + */ + +package io.element.android.features.roomlist.impl.filters + +import com.google.common.truth.Truth.assertThat +import io.element.android.features.roomlist.impl.R +import org.junit.Test + +class RoomListFiltersEmptyStateResourcesTest { + @Test + fun `fromSelectedFilters should return null when selectedFilters is empty`() { + val selectedFilters = emptyList() + val result = RoomListFiltersEmptyStateResources.fromSelectedFilters(selectedFilters) + assertThat(result).isNull() + } + + @Test + fun `fromSelectedFilters should return exact RoomListFiltersEmptyStateResources when selectedFilters has only unread filter`() { + val selectedFilters = listOf(RoomListFilter.Unread) + val result = RoomListFiltersEmptyStateResources.fromSelectedFilters(selectedFilters) + assertThat(result).isNotNull() + assertThat(result?.title).isEqualTo(R.string.screen_roomlist_filter_unreads_empty_state_title) + assertThat(result?.subtitle).isEqualTo(R.string.screen_roomlist_filter_mixed_empty_state_subtitle) + } + + @Test + fun `fromSelectedFilters should return exact RoomListFiltersEmptyStateResources when selectedFilters has only people filter`() { + val selectedFilters = listOf(RoomListFilter.People) + val result = RoomListFiltersEmptyStateResources.fromSelectedFilters(selectedFilters) + assertThat(result).isNotNull() + assertThat(result?.title).isEqualTo(R.string.screen_roomlist_filter_people_empty_state_title) + assertThat(result?.subtitle).isEqualTo(R.string.screen_roomlist_filter_mixed_empty_state_subtitle) + } + + @Test + fun `fromSelectedFilters should return exact RoomListFiltersEmptyStateResources when selectedFilters has only rooms filter`() { + val selectedFilters = listOf(RoomListFilter.Rooms) + val result = RoomListFiltersEmptyStateResources.fromSelectedFilters(selectedFilters) + assertThat(result).isNotNull() + assertThat(result?.title).isEqualTo(R.string.screen_roomlist_filter_rooms_empty_state_title) + assertThat(result?.subtitle).isEqualTo(R.string.screen_roomlist_filter_mixed_empty_state_subtitle) + } + + @Test + fun `fromSelectedFilters should return exact RoomListFiltersEmptyStateResources when selectedFilters has only favourites filter`() { + val selectedFilters = listOf(RoomListFilter.Favourites) + val result = RoomListFiltersEmptyStateResources.fromSelectedFilters(selectedFilters) + assertThat(result).isNotNull() + assertThat(result?.title).isEqualTo(R.string.screen_roomlist_filter_favourites_empty_state_title) + assertThat(result?.subtitle).isEqualTo(R.string.screen_roomlist_filter_favourites_empty_state_subtitle) + } + + @Test + fun `fromSelectedFilters should return exact RoomListFiltersEmptyStateResources when selectedFilters has multiple filters`() { + val selectedFilters = listOf(RoomListFilter.Unread, RoomListFilter.People, RoomListFilter.Rooms, RoomListFilter.Favourites) + val result = RoomListFiltersEmptyStateResources.fromSelectedFilters(selectedFilters) + assertThat(result).isNotNull() + assertThat(result?.title).isEqualTo(R.string.screen_roomlist_filter_mixed_empty_state_title) + assertThat(result?.subtitle).isEqualTo(R.string.screen_roomlist_filter_mixed_empty_state_subtitle) + } +} diff --git a/features/roomlist/impl/src/test/kotlin/io/element/android/features/roomlist/impl/filters/RoomListFiltersPresenterTests.kt b/features/roomlist/impl/src/test/kotlin/io/element/android/features/roomlist/impl/filters/RoomListFiltersPresenterTests.kt index e1f806f247..756fe1aa0e 100644 --- a/features/roomlist/impl/src/test/kotlin/io/element/android/features/roomlist/impl/filters/RoomListFiltersPresenterTests.kt +++ b/features/roomlist/impl/src/test/kotlin/io/element/android/features/roomlist/impl/filters/RoomListFiltersPresenterTests.kt @@ -68,6 +68,9 @@ class RoomListFiltersPresenterTests { filterSelectionState(RoomListFilter.Favourites, false), ).inOrder() + assertThat(state.selectedFilters()).containsExactly( + RoomListFilter.Rooms, + ) val roomListCurrentFilter = roomListService.allRooms.currentFilter.value as MatrixRoomListFilter.All assertThat(roomListCurrentFilter.filters).containsExactly( MatrixRoomListFilter.Category.Group, @@ -82,6 +85,7 @@ class RoomListFiltersPresenterTests { filterSelectionState(RoomListFilter.Rooms, false), filterSelectionState(RoomListFilter.Favourites, false), ).inOrder() + assertThat(state.selectedFilters()).isEmpty() val roomListCurrentFilter = roomListService.allRooms.currentFilter.value as MatrixRoomListFilter.All assertThat(roomListCurrentFilter.filters).isEmpty() }