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

Commit 6beb1964 authored by Andrew Cole's avatar Andrew Cole Committed by Android (Google) Code Review
Browse files

Merge "Test Week - ShortcutUtilTest" into main

parents 78524ae6 9b3b54eb
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -54,14 +54,6 @@ public class ShortcutUtil {
                ? ((WorkspaceItemInfo) info).getPersonKeys() : Utilities.EMPTY_STRING_ARRAY;
    }

    /**
     * Returns true if the item is a deep shortcut.
     */
    public static boolean isDeepShortcut(ItemInfo info) {
        return info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT
                && info instanceof WorkspaceItemInfo;
    }

    private static boolean isActive(ItemInfo info) {
        boolean isLoading = info instanceof WorkspaceItemInfo
                && ((WorkspaceItemInfo) info).hasPromiseIconUi();
+72 −0
Original line number Diff line number Diff line
/*
 * 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.launcher3.util

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.launcher3.Utilities
import com.android.launcher3.model.data.WorkspaceItemInfo
import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
import org.junit.runner.RunWith

@SmallTest
@RunWith(AndroidJUnit4::class)
class ShortcutUtilTest {

    @Test
    fun `supportsShortcuts returns true if the item is active and it is an app`() {
        // A blank workspace item info should be active and should be ITEM_TYPE_APPLICATION
        val itemInfo = WorkspaceItemInfo()
        // Action
        val result = ShortcutUtil.supportsShortcuts(itemInfo)
        // Verify
        assertEquals(true, result)
    }

    @Test
    fun `supportsDeepShortcuts returns true if the app is active and an app and widgets are enabled`() {
        // Setup
        val itemInfo = WorkspaceItemInfo()
        // Action
        val result = ShortcutUtil.supportsDeepShortcuts(itemInfo)
        // Verify
        assertEquals(true, result)
    }

    @Test
    fun `getShortcutIdIfPinnedShortcut returns null if the item is an app`() {
        // Setup
        val itemInfo = WorkspaceItemInfo()
        // Action
        val result = ShortcutUtil.getShortcutIdIfPinnedShortcut(itemInfo)
        // Verify
        assertNull(result)
    }

    @Test
    fun `getPersonKeysIfPinnedShortcut returns empty string array if item type is an app`() {
        // Setup
        val itemInfo = WorkspaceItemInfo()
        // Action
        val result = ShortcutUtil.getPersonKeysIfPinnedShortcut(itemInfo)
        // Verify
        assertArrayEquals(Utilities.EMPTY_STRING_ARRAY, result)
    }
}