• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.systemui.statusbar.notification.stack
2 
3 import android.testing.AndroidTestingRunner
4 import android.testing.TestableLooper
5 import android.testing.TestableLooper.RunWithLooper
6 import androidx.test.filters.SmallTest
7 import com.android.systemui.SysuiTestCase
8 import com.android.systemui.flags.FakeFeatureFlags
9 import com.android.systemui.flags.Flags
10 import com.android.systemui.statusbar.notification.row.NotificationTestHelper
11 import com.android.systemui.util.mockito.mock
12 import junit.framework.Assert.assertEquals
13 import org.junit.Before
14 import org.junit.Test
15 import org.junit.runner.RunWith
16 
17 /** Tests for {@link NotificationTargetsHelper}. */
18 @SmallTest
19 @RunWith(AndroidTestingRunner::class)
20 @RunWithLooper
21 class NotificationTargetsHelperTest : SysuiTestCase() {
22     lateinit var notificationTestHelper: NotificationTestHelper
23     private val sectionsManager: NotificationSectionsManager = mock()
24     private val stackScrollLayout: NotificationStackScrollLayout = mock()
25 
26     @Before
setUpnull27     fun setUp() {
28         allowTestableLooperAsMainThread()
29         notificationTestHelper =
30             NotificationTestHelper(mContext, mDependency, TestableLooper.get(this))
31     }
32 
notificationTargetsHelpernull33     private fun notificationTargetsHelper(
34         notificationGroupCorner: Boolean = true,
35     ) =
36         NotificationTargetsHelper(
37             FakeFeatureFlags().apply {
38                 set(Flags.USE_ROUNDNESS_SOURCETYPES, notificationGroupCorner)
39             }
40         )
41 
42     @Test
targetsForFirstNotificationInGroupnull43     fun targetsForFirstNotificationInGroup() {
44         val children = notificationTestHelper.createGroup(3).childrenContainer
45         val swiped = children.attachedChildren[0]
46 
47         val actual =
48             notificationTargetsHelper()
49                 .findRoundableTargets(
50                     viewSwiped = swiped,
51                     stackScrollLayout = stackScrollLayout,
52                     sectionsManager = sectionsManager,
53                 )
54 
55         val expected =
56             RoundableTargets(
57                 before = children.notificationHeaderWrapper, // group header
58                 swiped = swiped,
59                 after = children.attachedChildren[1],
60             )
61         assertEquals(expected, actual)
62     }
63 
64     @Test
targetsForMiddleNotificationInGroupnull65     fun targetsForMiddleNotificationInGroup() {
66         val children = notificationTestHelper.createGroup(3).childrenContainer
67         val swiped = children.attachedChildren[1]
68 
69         val actual =
70             notificationTargetsHelper()
71                 .findRoundableTargets(
72                     viewSwiped = swiped,
73                     stackScrollLayout = stackScrollLayout,
74                     sectionsManager = sectionsManager,
75                 )
76 
77         val expected =
78             RoundableTargets(
79                 before = children.attachedChildren[0],
80                 swiped = swiped,
81                 after = children.attachedChildren[2],
82             )
83         assertEquals(expected, actual)
84     }
85 
86     @Test
targetsForLastNotificationInGroupnull87     fun targetsForLastNotificationInGroup() {
88         val children = notificationTestHelper.createGroup(3).childrenContainer
89         val swiped = children.attachedChildren[2]
90 
91         val actual =
92             notificationTargetsHelper()
93                 .findRoundableTargets(
94                     viewSwiped = swiped,
95                     stackScrollLayout = stackScrollLayout,
96                     sectionsManager = sectionsManager,
97                 )
98 
99         val expected =
100             RoundableTargets(
101                 before = children.attachedChildren[1],
102                 swiped = swiped,
103                 after = null,
104             )
105         assertEquals(expected, actual)
106     }
107 }
108