Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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.bubbles; |
| 18 | |
| 19 | import static junit.framework.Assert.assertEquals; |
| 20 | import static junit.framework.Assert.assertNotSame; |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 21 | |
| 22 | import static org.mockito.Mockito.verify; |
| 23 | |
| 24 | import android.graphics.Color; |
| 25 | import android.graphics.PointF; |
| 26 | import android.testing.AndroidTestingRunner; |
| 27 | import android.testing.TestableLooper; |
| 28 | import android.view.View; |
| 29 | import android.widget.TextView; |
| 30 | |
| 31 | import androidx.test.filters.SmallTest; |
| 32 | |
| 33 | import com.android.systemui.R; |
| 34 | import com.android.systemui.SysuiTestCase; |
| 35 | |
| 36 | import org.junit.Before; |
| 37 | import org.junit.Test; |
| 38 | import org.junit.runner.RunWith; |
| 39 | import org.mockito.Mockito; |
| 40 | import org.mockito.MockitoAnnotations; |
| 41 | |
| 42 | @SmallTest |
| 43 | @RunWith(AndroidTestingRunner.class) |
| 44 | @TestableLooper.RunWithLooper(setAsMainLooper = true) |
| 45 | public class BubbleFlyoutViewTest extends SysuiTestCase { |
| 46 | private BubbleFlyoutView mFlyout; |
| 47 | private TextView mFlyoutText; |
Lyn Han | 61d5d56 | 2019-07-01 17:39:38 -0700 | [diff] [blame] | 48 | private float[] mDotCenter = new float[2]; |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 49 | |
| 50 | @Before |
| 51 | public void setUp() throws Exception { |
| 52 | MockitoAnnotations.initMocks(this); |
| 53 | mFlyout = new BubbleFlyoutView(getContext()); |
| 54 | |
| 55 | mFlyoutText = mFlyout.findViewById(R.id.bubble_flyout_text); |
Lyn Han | 61d5d56 | 2019-07-01 17:39:38 -0700 | [diff] [blame] | 56 | mDotCenter[0] = 30; |
| 57 | mDotCenter[1] = 30; |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | @Test |
| 61 | public void testShowFlyout_isVisible() { |
Joshua Tsuji | 14e6855 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 62 | mFlyout.setupFlyoutStartingAsDot( |
Lyn Han | 61d5d56 | 2019-07-01 17:39:38 -0700 | [diff] [blame] | 63 | "Hello", new PointF(100, 100), 500, true, Color.WHITE, null, null, mDotCenter); |
Joshua Tsuji | 14e6855 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 64 | mFlyout.setVisibility(View.VISIBLE); |
| 65 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 66 | assertEquals("Hello", mFlyoutText.getText()); |
| 67 | assertEquals(View.VISIBLE, mFlyout.getVisibility()); |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | @Test |
| 71 | public void testFlyoutHide_runsCallback() { |
| 72 | Runnable after = Mockito.mock(Runnable.class); |
Joshua Tsuji | 14e6855 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 73 | mFlyout.setupFlyoutStartingAsDot( |
Lyn Han | 61d5d56 | 2019-07-01 17:39:38 -0700 | [diff] [blame] | 74 | "Hello", new PointF(100, 100), 500, true, Color.WHITE, null, after, mDotCenter); |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 75 | mFlyout.hideFlyout(); |
| 76 | |
| 77 | verify(after).run(); |
| 78 | } |
| 79 | |
| 80 | @Test |
| 81 | public void testSetCollapsePercent() { |
Joshua Tsuji | 14e6855 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 82 | mFlyout.setupFlyoutStartingAsDot( |
Lyn Han | 61d5d56 | 2019-07-01 17:39:38 -0700 | [diff] [blame] | 83 | "Hello", new PointF(100, 100), 500, true, Color.WHITE, null, null, mDotCenter); |
Joshua Tsuji | 14e6855 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 84 | mFlyout.setVisibility(View.VISIBLE); |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 85 | |
| 86 | mFlyout.setCollapsePercent(1f); |
| 87 | assertEquals(0f, mFlyoutText.getAlpha(), 0.01f); |
| 88 | assertNotSame(0f, mFlyoutText.getTranslationX()); // Should have moved to collapse. |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 89 | |
| 90 | mFlyout.setCollapsePercent(0f); |
| 91 | assertEquals(1f, mFlyoutText.getAlpha(), 0.01f); |
| 92 | assertEquals(0f, mFlyoutText.getTranslationX()); |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 93 | } |
| 94 | } |