1 /* 2 * Copyright 2021 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.appcompattheme 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.appcompattheme.test.R 28 import org.junit.Test 29 import org.junit.runner.RunWith 30 import org.junit.runners.Parameterized 31 32 /** 33 * Version of [BaseAppCompatThemeTest] which is designed to be run on device/emulators. 34 */ 35 @RunWith(Parameterized::class) 36 class InstrumentedAppCompatThemeTest<T : AppCompatActivity>( 37 activityClass: Class<T> 38 ) : BaseAppCompatThemeTest<T>(activityClass) { 39 companion object { 40 @JvmStatic 41 @Parameterized.Parameters activitiesnull42 fun activities() = listOf( 43 DarkAppCompatActivity::class.java, 44 LightAppCompatActivity::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 59 WithThemeOverlay(R.style.ThemeOverlay_RubikFontFamily) { 60 AppCompatTheme { 61 MaterialTheme.typography.assertFontFamily(expected = rubik) 62 } 63 } 64 } 65 } 66