1 /*
2  * Copyright 2022 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  *      https://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 @file:Suppress("DEPRECATION")
18 
19 package com.google.accompanist.themeadapter.material
20 
21 import androidx.appcompat.app.AppCompatActivity
22 import androidx.compose.material.MaterialTheme
23 import androidx.compose.ui.text.font.Font
24 import androidx.compose.ui.text.font.FontWeight
25 import androidx.compose.ui.text.font.toFontFamily
26 import androidx.test.filters.SdkSuppress
27 import com.google.accompanist.themeadapter.material.test.R
28 import org.junit.Test
29 import org.junit.runner.RunWith
30 import org.junit.runners.Parameterized
31 
32 /**
33  * Version of [BaseMdcThemeTest] which is designed to be run on device/emulators.
34  */
35 @RunWith(Parameterized::class)
36 class InstrumentedMdcThemeTest<T : AppCompatActivity>(
37     activityClass: Class<T>
38 ) : BaseMdcThemeTest<T>(activityClass) {
39     companion object {
40         @JvmStatic
41         @Parameterized.Parameters
activitiesnull42         fun activities() = listOf(
43             DarkMdcActivity::class.java,
44             LightMdcActivity::class.java
45         )
46     }
47 
48     /**
49      * On API 21-22, the family is loaded with only the 400 font.
50      *
51      * This only works on device as Robolectric seems to always use the behavior from API 23+,
52      * which is not what we want to test.
53      */
54     @Test
55     @SdkSuppress(maxSdkVersion = 22)
56     fun type_rubik_family_api21() = composeTestRule.setContent {
57         val rubik = Font(R.font.rubik, FontWeight.W400).toFontFamily()
58         WithThemeOverlay(R.style.ThemeOverlay_MdcThemeTest_DefaultFontFamily_Rubik) {
59             MdcTheme(setDefaultFontFamily = true) {
60                 MaterialTheme.typography.assertFontFamilies(expected = rubik)
61             }
62         }
63         WithThemeOverlay(R.style.ThemeOverlay_MdcThemeTest_DefaultAndroidFontFamily_Rubik) {
64             MdcTheme(setDefaultFontFamily = true) {
65                 MaterialTheme.typography.assertFontFamilies(expected = rubik)
66             }
67         }
68     }
69 }
70