Skip to content

Commit 14558b4

Browse files
wcshidsn5ft
authored andcommitted
Add ChipGroup unit test.
PiperOrigin-RevId: 225190750
1 parent 4cf6ece commit 14558b4

File tree

4 files changed

+145
-0
lines changed

4 files changed

+145
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2018 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+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:tools="http://schemas.android.com/tools"
19+
package="com.google.android.material.chip">
20+
21+
<uses-sdk android:minSdkVersion="14"/>
22+
23+
<application/>
24+
</manifest>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2018 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+
package com.google.android.material.chip;
17+
18+
import com.google.android.material.R;
19+
20+
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertNotEquals;
22+
import static org.junit.Assert.assertTrue;
23+
24+
import android.support.v7.app.AppCompatActivity;
25+
import android.view.View;
26+
import org.junit.Before;
27+
import org.junit.Test;
28+
import org.junit.runner.RunWith;
29+
import org.robolectric.Robolectric;
30+
import org.robolectric.RobolectricTestRunner;
31+
import org.robolectric.RuntimeEnvironment;
32+
import org.robolectric.annotation.internal.DoNotInstrument;
33+
34+
/** Tests for {@link com.google.android.material.chip.ChipGroup}. */
35+
@RunWith(RobolectricTestRunner.class)
36+
@DoNotInstrument
37+
public class ChipGroupTest {
38+
39+
private static final int CHIP_GROUP_SPACING = 4;
40+
private ChipGroup chipgroup;
41+
42+
@Before
43+
public void themeApplicationContext() {
44+
RuntimeEnvironment.application.setTheme(
45+
R.style.Theme_MaterialComponents_Light_NoActionBar_Bridge);
46+
AppCompatActivity activity = Robolectric.buildActivity(AppCompatActivity.class).setup().get();
47+
View inflated = activity.getLayoutInflater().inflate(R.layout.test_reflow_chipgroup, null);
48+
chipgroup = inflated.findViewById(R.id.chip_group);
49+
}
50+
51+
@Test
52+
public void testSetChipSpacing() {
53+
chipgroup.setChipSpacing(CHIP_GROUP_SPACING);
54+
assertEquals(chipgroup.getChipSpacingHorizontal(), chipgroup.getChipSpacingVertical());
55+
assertEquals(CHIP_GROUP_SPACING, chipgroup.getChipSpacingHorizontal());
56+
}
57+
58+
@Test
59+
public void testSelection() {
60+
chipgroup.setSingleSelection(true);
61+
assertTrue(chipgroup.isSingleSelection());
62+
assertEquals(View.NO_ID, chipgroup.getCheckedChipId());
63+
int chipId = chipgroup.getChildAt(0).getId();
64+
assertNotEquals(View.NO_ID, chipId);
65+
chipgroup.check(chipId);
66+
assertEquals(chipId, chipgroup.getCheckedChipId());
67+
chipgroup.clearCheck();
68+
assertEquals(View.NO_ID, chipgroup.getCheckedChipId());
69+
}
70+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2018 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
https://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
18+
<!-- Reflow chip group. -->
19+
<com.google.android.material.chip.ChipGroup
20+
xmlns:android="http://schemas.android.com/apk/res/android"
21+
android:id="@+id/chip_group"
22+
android:layout_width="match_parent"
23+
android:layout_height="wrap_content"
24+
android:layout_margin="16dp">
25+
<com.google.android.material.chip.Chip
26+
xmlns:android="http://schemas.android.com/apk/res/android"
27+
android:id="@+id/filter_chip"
28+
style="@style/Widget.MaterialComponents.Chip.Filter"
29+
android:layout_width="wrap_content"
30+
android:layout_height="wrap_content"
31+
android:ellipsize="end"
32+
android:text="@string/chip_text"/>
33+
</com.google.android.material.chip.ChipGroup>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2018 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+
<resources>
17+
<string name="chip_text">Chip text</string>
18+
</resources>

0 commit comments

Comments
 (0)