1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.screenshot.ui.viewmodel 18 19 import android.view.accessibility.AccessibilityManager 20 import androidx.test.ext.junit.runners.AndroidJUnit4 21 import androidx.test.filters.SmallTest 22 import com.google.common.truth.Truth.assertThat 23 import org.junit.Test 24 import org.junit.runner.RunWith 25 import org.mockito.Mockito.mock 26 27 @SmallTest 28 @RunWith(AndroidJUnit4::class) 29 class ScreenshotViewModelTest { 30 private val accessibilityManager: AccessibilityManager = mock(AccessibilityManager::class.java) 31 private val appearance = ActionButtonAppearance(null, "Label", "Description") <lambda>null32 private val onclick = {} 33 34 @Test testAddActionnull35 fun testAddAction() { 36 val viewModel = ScreenshotViewModel(accessibilityManager) 37 38 assertThat(viewModel.actions.value).isEmpty() 39 40 viewModel.addAction(appearance, true, onclick) 41 42 assertThat(viewModel.actions.value).hasSize(1) 43 44 val added = viewModel.actions.value[0] 45 assertThat(added.appearance).isEqualTo(appearance) 46 assertThat(added.onClicked).isEqualTo(onclick) 47 assertThat(added.showDuringEntrance).isTrue() 48 } 49 50 @Test testRemoveActionnull51 fun testRemoveAction() { 52 val viewModel = ScreenshotViewModel(accessibilityManager) 53 val firstId = viewModel.addAction(ActionButtonAppearance(null, "", ""), false, {}) 54 val secondId = viewModel.addAction(appearance, false, onclick) 55 56 assertThat(viewModel.actions.value).hasSize(2) 57 assertThat(firstId).isNotEqualTo(secondId) 58 59 viewModel.removeAction(firstId) 60 61 assertThat(viewModel.actions.value).hasSize(1) 62 63 val remaining = viewModel.actions.value[0] 64 assertThat(remaining.appearance).isEqualTo(appearance) 65 assertThat(remaining.showDuringEntrance).isFalse() 66 assertThat(remaining.onClicked).isEqualTo(onclick) 67 } 68 69 @Test testUpdateActionAppearancenull70 fun testUpdateActionAppearance() { 71 val viewModel = ScreenshotViewModel(accessibilityManager) 72 val id = viewModel.addAction(appearance, false, onclick) 73 val otherAppearance = ActionButtonAppearance(null, "Other", "Other") 74 75 viewModel.updateActionAppearance(id, otherAppearance) 76 77 assertThat(viewModel.actions.value).hasSize(1) 78 val updated = viewModel.actions.value[0] 79 assertThat(updated.appearance).isEqualTo(otherAppearance) 80 assertThat(updated.onClicked).isEqualTo(onclick) 81 } 82 } 83