blob: a8961a85c4c7049bce1042cf31b83a24d9a884d2 [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;
Joshua Tsuji6549e702019-05-02 13:13:16 -040021
22import static org.mockito.Mockito.verify;
23
24import android.graphics.Color;
25import android.graphics.PointF;
26import android.testing.AndroidTestingRunner;
27import android.testing.TestableLooper;
28import android.view.View;
29import android.widget.TextView;
30
31import androidx.test.filters.SmallTest;
32
33import com.android.systemui.R;
34import com.android.systemui.SysuiTestCase;
35
36import org.junit.Before;
37import org.junit.Test;
38import org.junit.runner.RunWith;
39import org.mockito.Mockito;
40import org.mockito.MockitoAnnotations;
41
42@SmallTest
43@RunWith(AndroidTestingRunner.class)
44@TestableLooper.RunWithLooper(setAsMainLooper = true)
45public class BubbleFlyoutViewTest extends SysuiTestCase {
46 private BubbleFlyoutView mFlyout;
47 private TextView mFlyoutText;
Lyn Han61d5d562019-07-01 17:39:38 -070048 private float[] mDotCenter = new float[2];
Joshua Tsuji6549e702019-05-02 13:13:16 -040049
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 Han61d5d562019-07-01 17:39:38 -070056 mDotCenter[0] = 30;
57 mDotCenter[1] = 30;
Joshua Tsuji6549e702019-05-02 13:13:16 -040058 }
59
60 @Test
61 public void testShowFlyout_isVisible() {
Joshua Tsuji14e68552019-06-06 17:17:08 -040062 mFlyout.setupFlyoutStartingAsDot(
Lyn Han61d5d562019-07-01 17:39:38 -070063 "Hello", new PointF(100, 100), 500, true, Color.WHITE, null, null, mDotCenter);
Joshua Tsuji14e68552019-06-06 17:17:08 -040064 mFlyout.setVisibility(View.VISIBLE);
65
Joshua Tsuji6549e702019-05-02 13:13:16 -040066 assertEquals("Hello", mFlyoutText.getText());
67 assertEquals(View.VISIBLE, mFlyout.getVisibility());
Joshua Tsuji6549e702019-05-02 13:13:16 -040068 }
69
70 @Test
71 public void testFlyoutHide_runsCallback() {
72 Runnable after = Mockito.mock(Runnable.class);
Joshua Tsuji14e68552019-06-06 17:17:08 -040073 mFlyout.setupFlyoutStartingAsDot(
Lyn Han61d5d562019-07-01 17:39:38 -070074 "Hello", new PointF(100, 100), 500, true, Color.WHITE, null, after, mDotCenter);
Joshua Tsuji6549e702019-05-02 13:13:16 -040075 mFlyout.hideFlyout();
76
77 verify(after).run();
78 }
79
80 @Test
81 public void testSetCollapsePercent() {
Joshua Tsuji14e68552019-06-06 17:17:08 -040082 mFlyout.setupFlyoutStartingAsDot(
Lyn Han61d5d562019-07-01 17:39:38 -070083 "Hello", new PointF(100, 100), 500, true, Color.WHITE, null, null, mDotCenter);
Joshua Tsuji14e68552019-06-06 17:17:08 -040084 mFlyout.setVisibility(View.VISIBLE);
Joshua Tsuji6549e702019-05-02 13:13:16 -040085
86 mFlyout.setCollapsePercent(1f);
87 assertEquals(0f, mFlyoutText.getAlpha(), 0.01f);
88 assertNotSame(0f, mFlyoutText.getTranslationX()); // Should have moved to collapse.
Joshua Tsuji6549e702019-05-02 13:13:16 -040089
90 mFlyout.setCollapsePercent(0f);
91 assertEquals(1f, mFlyoutText.getAlpha(), 0.01f);
92 assertEquals(0f, mFlyoutText.getTranslationX());
Joshua Tsuji6549e702019-05-02 13:13:16 -040093 }
94}