Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6a98f299 authored by Josh's avatar Josh
Browse files

Rewriting ShortcutHelperViewModelTest to reduce brittleness

Shortcut helper view model test has been updated to use FakeRepositories
to simplify testing. This removes the need to worry about implementation
details and mocking behaviors of Repository dependencies. This is also
groundwork for future tests.

Flag: com.android.systemui.extended_apps_shortcut_category
Test: atest com.android.systemui.keyboard.shortcut
Bug: 405985619

Change-Id: Iec4501574192a95b37b9c8b6118c1c47a5cd00d9
parent ae1dc9ac
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -92,7 +92,8 @@ class CustomShortcutCategoriesRepositoryTest : SysuiTestCase() {
    private val inputManager = kosmos.fakeInputManager.inputManager
    private val testScope = kosmos.testScope
    private val helper = kosmos.shortcutHelperTestHelper
    private val repo = kosmos.customShortcutCategoriesRepository
    private val repo =
        kosmos.customShortcutCategoriesRepository as CustomShortcutCategoriesRepository

    @Before
    fun setup() {
+11 −0
Original line number Diff line number Diff line
@@ -319,6 +319,12 @@ object TestShortcuts {
            )
            .apply { packageName = standardPackageName1 }

    private val standardAppSubCategory1 =
        ShortcutSubCategory(
            standardAppGroup1.label!!.toString(),
            listOf(standardShortcut1, standardShortcut2, standardShortcut3),
        )

    private val standardSystemAppSubcategoryWithCustomHomeShortcut =
        ShortcutSubCategory("System controls", listOf(customGoHomeShortcut))

@@ -396,6 +402,11 @@ object TestShortcuts {
        )

    val currentAppGroups = listOf(standardAppGroup1)
    val currentAppCategory =
        ShortcutCategory(
            type = ShortcutCategoryType.CurrentApp(standardAppGroup1.packageName.toString()),
            subCategories = listOf(standardAppSubCategory1),
        )
    val currentAppPackageName = standardPackageName1

    val systemGroups = listOf(standardGroup3, standardGroup2, standardGroup1)
+109 −120

File changed.

Preview size limit exceeded, changes collapsed.

+10 −3

File changed.

Preview size limit exceeded, changes collapsed.

+40 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.systemui.keyboard.shortcut.data.repository

import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategory
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutHelperState
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.combine

class FakeShortcutCategoriesRepository(stateRepository: ShortcutHelperStateRepository) :
    ShortcutCategoriesRepository {

    private val _categories = MutableStateFlow<List<ShortcutCategory>>(emptyList())
    override val categories =
        combine(stateRepository.state, _categories) { state, categories ->
            if (state is ShortcutHelperState.Active) {
                categories
            } else {
                emptyList()
            }
        }

    fun setShortcutCategories(vararg categories: ShortcutCategory) {
        _categories.value = categories.asList()
    }
}