blob: 173237f7b311d37fedc1422c1254a8925ebe2b3c [file] [log] [blame]
Joshua Tsuji6549e702019-05-02 13:13:16 -04001/*
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
17package com.android.systemui.bubbles;
18
19import static junit.framework.Assert.assertEquals;
20import static junit.framework.Assert.assertNotSame;
21import static junit.framework.Assert.assertTrue;
22
23import static org.mockito.Mockito.verify;
24
25import android.graphics.Color;
26import android.graphics.PointF;
27import android.testing.AndroidTestingRunner;
28import android.testing.TestableLooper;
29import android.view.View;
30import android.widget.TextView;
31
32import androidx.test.filters.SmallTest;
33
34import com.android.systemui.R;
35import com.android.systemui.SysuiTestCase;
36
37import org.junit.Before;
38import org.junit.Test;
39import org.junit.runner.RunWith;
40import org.mockito.Mockito;
41import org.mockito.MockitoAnnotations;
42
43@SmallTest
44@RunWith(AndroidTestingRunner.class)
45@TestableLooper.RunWithLooper(setAsMainLooper = true)
46public 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}