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; |
| 21 | import static junit.framework.Assert.assertTrue; |
| 22 | |
| 23 | import static org.mockito.Mockito.verify; |
| 24 | |
| 25 | import android.graphics.Color; |
| 26 | import android.graphics.PointF; |
| 27 | import android.testing.AndroidTestingRunner; |
| 28 | import android.testing.TestableLooper; |
| 29 | import android.view.View; |
| 30 | import android.widget.TextView; |
| 31 | |
| 32 | import androidx.test.filters.SmallTest; |
| 33 | |
| 34 | import com.android.systemui.R; |
| 35 | import com.android.systemui.SysuiTestCase; |
| 36 | |
| 37 | import org.junit.Before; |
| 38 | import org.junit.Test; |
| 39 | import org.junit.runner.RunWith; |
| 40 | import org.mockito.Mockito; |
| 41 | import org.mockito.MockitoAnnotations; |
| 42 | |
| 43 | @SmallTest |
| 44 | @RunWith(AndroidTestingRunner.class) |
| 45 | @TestableLooper.RunWithLooper(setAsMainLooper = true) |
| 46 | public class BubbleFlyoutViewTest extends SysuiTestCase { |
| 47 | private BubbleFlyoutView mFlyout; |
| 48 | private TextView mFlyoutText; |
| 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); |
| 56 | } |
| 57 | |
| 58 | @Test |
| 59 | public void testShowFlyout_isVisible() { |
| 60 | mFlyout.showFlyout("Hello", new PointF(100, 100), 500, true, Color.WHITE, null); |
| 61 | assertEquals("Hello", mFlyoutText.getText()); |
| 62 | assertEquals(View.VISIBLE, mFlyout.getVisibility()); |
| 63 | assertEquals(1f, mFlyoutText.getAlpha(), .01f); |
| 64 | } |
| 65 | |
| 66 | @Test |
| 67 | public void testFlyoutHide_runsCallback() { |
| 68 | Runnable after = Mockito.mock(Runnable.class); |
| 69 | mFlyout.showFlyout("Hello", new PointF(100, 100), 500, true, Color.WHITE, after); |
| 70 | mFlyout.hideFlyout(); |
| 71 | |
| 72 | verify(after).run(); |
| 73 | } |
| 74 | |
| 75 | @Test |
| 76 | public void testSetCollapsePercent() { |
| 77 | mFlyout.showFlyout("Hello", new PointF(100, 100), 500, true, Color.WHITE, null); |
| 78 | |
| 79 | float initialTranslationZ = mFlyout.getTranslationZ(); |
| 80 | |
| 81 | mFlyout.setCollapsePercent(1f); |
| 82 | assertEquals(0f, mFlyoutText.getAlpha(), 0.01f); |
| 83 | assertNotSame(0f, mFlyoutText.getTranslationX()); // Should have moved to collapse. |
| 84 | assertTrue(mFlyout.getTranslationZ() < initialTranslationZ); // Should be descending. |
| 85 | |
| 86 | mFlyout.setCollapsePercent(0f); |
| 87 | assertEquals(1f, mFlyoutText.getAlpha(), 0.01f); |
| 88 | assertEquals(0f, mFlyoutText.getTranslationX()); |
| 89 | assertEquals(initialTranslationZ, mFlyout.getTranslationZ()); |
| 90 | |
| 91 | } |
| 92 | } |