From ccaaf8c3a2e491942f9f7d760ba15d5f07fb80d5 Mon Sep 17 00:00:00 2001 From: Matt Casey Date: Wed, 22 May 2024 13:52:13 +0000 Subject: Don't allow the only selected item to be unselected. Bug: 341923156 Test: atest SelectionInteractorTest Flag: None Change-Id: I5a67d6ad6b628ac5fa73c70e2ca2b8c6d04724ae --- .../domain/interactor/SelectionInteractorTest.kt | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/unit/src/com/android/intentresolver/contentpreview/payloadtoggle/domain/interactor/SelectionInteractorTest.kt (limited to 'tests') diff --git a/tests/unit/src/com/android/intentresolver/contentpreview/payloadtoggle/domain/interactor/SelectionInteractorTest.kt b/tests/unit/src/com/android/intentresolver/contentpreview/payloadtoggle/domain/interactor/SelectionInteractorTest.kt new file mode 100644 index 00000000..a64807b7 --- /dev/null +++ b/tests/unit/src/com/android/intentresolver/contentpreview/payloadtoggle/domain/interactor/SelectionInteractorTest.kt @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * 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 com.android.intentresolver.contentpreview.payloadtoggle.domain.interactor + +import android.content.Intent +import android.net.Uri +import com.android.intentresolver.contentpreview.payloadtoggle.data.repository.previewSelectionsRepository +import com.android.intentresolver.contentpreview.payloadtoggle.shared.model.PreviewModel +import com.android.intentresolver.util.runKosmosTest +import com.google.common.truth.Truth.assertThat +import org.junit.Test + +class SelectionInteractorTest { + @Test + fun singleSelection_removalPrevented() = runKosmosTest { + val initialPreview = + PreviewModel(uri = Uri.fromParts("scheme", "ssp", "fragment"), mimeType = null) + previewSelectionsRepository.selections.value = setOf(initialPreview) + + val underTest = + SelectionInteractor( + previewSelectionsRepository, + { Intent() }, + updateTargetIntentInteractor + ) + + assertThat(underTest.selections.value).isEqualTo(setOf(initialPreview)) + + // Shouldn't do anything! + underTest.unselect(initialPreview) + + assertThat(underTest.selections.value).isEqualTo(setOf(initialPreview)) + } + + @Test + fun multipleSelections_removalAllowed() = runKosmosTest { + val first = PreviewModel(uri = Uri.fromParts("scheme", "ssp", "fragment"), mimeType = null) + val second = + PreviewModel(uri = Uri.fromParts("scheme2", "ssp2", "fragment2"), mimeType = null) + previewSelectionsRepository.selections.value = setOf(first, second) + + val underTest = + SelectionInteractor( + previewSelectionsRepository, + { Intent() }, + updateTargetIntentInteractor + ) + + underTest.unselect(first) + + assertThat(underTest.selections.value).isEqualTo(setOf(second)) + } +} -- cgit v1.2.3-59-g8ed1b