1 package com.android.systemui.statusbar.notification.stack
2 
3 import android.testing.TestableLooper
4 import android.testing.TestableLooper.RunWithLooper
5 import androidx.test.ext.junit.runners.AndroidJUnit4
6 import androidx.test.filters.SmallTest
7 import com.android.systemui.SysuiTestCase
8 import com.android.systemui.flags.FakeFeatureFlags
9 import com.android.systemui.statusbar.notification.row.NotificationTestHelper
10 import com.android.systemui.util.mockito.mock
11 import junit.framework.Assert.assertEquals
12 import org.junit.Before
13 import org.junit.Test
14 import org.junit.runner.RunWith
15 
16 /** Tests for {@link NotificationTargetsHelper}. */
17 @SmallTest
18 @RunWith(AndroidJUnit4::class)
19 @RunWithLooper
20 class NotificationTargetsHelperTest : SysuiTestCase() {
21     private val featureFlags = FakeFeatureFlags()
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), featureFlags)
31     }
32 
notificationTargetsHelpernull33     private fun notificationTargetsHelper() = NotificationTargetsHelper(featureFlags)
34 
35     @Test
36     fun targetsForFirstNotificationInGroup() {
37         val children = notificationTestHelper.createGroup(3).childrenContainer
38         val swiped = children.attachedChildren[0]
39 
40         val actual =
41             notificationTargetsHelper()
42                 .findRoundableTargets(
43                     viewSwiped = swiped,
44                     stackScrollLayout = stackScrollLayout,
45                     sectionsManager = sectionsManager,
46                 )
47 
48         val expected =
49             RoundableTargets(
50                 before = children.notificationHeaderWrapper, // group header
51                 swiped = swiped,
52                 after = children.attachedChildren[1],
53             )
54         assertEquals(expected, actual)
55     }
56 
57     @Test
targetsForMiddleNotificationInGroupnull58     fun targetsForMiddleNotificationInGroup() {
59         val children = notificationTestHelper.createGroup(3).childrenContainer
60         val swiped = children.attachedChildren[1]
61 
62         val actual =
63             notificationTargetsHelper()
64                 .findRoundableTargets(
65                     viewSwiped = swiped,
66                     stackScrollLayout = stackScrollLayout,
67                     sectionsManager = sectionsManager,
68                 )
69 
70         val expected =
71             RoundableTargets(
72                 before = children.attachedChildren[0],
73                 swiped = swiped,
74                 after = children.attachedChildren[2],
75             )
76         assertEquals(expected, actual)
77     }
78 
79     @Test
targetsForLastNotificationInGroupnull80     fun targetsForLastNotificationInGroup() {
81         val children = notificationTestHelper.createGroup(3).childrenContainer
82         val swiped = children.attachedChildren[2]
83 
84         val actual =
85             notificationTargetsHelper()
86                 .findRoundableTargets(
87                     viewSwiped = swiped,
88                     stackScrollLayout = stackScrollLayout,
89                     sectionsManager = sectionsManager,
90                 )
91 
92         val expected =
93             RoundableTargets(
94                 before = children.attachedChildren[1],
95                 swiped = swiped,
96                 after = null,
97             )
98         assertEquals(expected, actual)
99     }
100 }
101