1 /* 2 * Copyright (C) 2024 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 package com.android.photopicker.core.components 18 19 import android.content.Intent 20 import androidx.compose.material.icons.Icons 21 import androidx.compose.material.icons.outlined.Image 22 import androidx.compose.runtime.CompositionLocalProvider 23 import androidx.compose.ui.test.assertIsDisplayed 24 import androidx.compose.ui.test.junit4.createComposeRule 25 import androidx.compose.ui.test.onNodeWithText 26 import androidx.test.ext.junit.runners.AndroidJUnit4 27 import androidx.test.filters.SmallTest 28 import com.android.photopicker.core.configuration.LocalPhotopickerConfiguration 29 import com.android.photopicker.core.configuration.TestPhotopickerConfiguration 30 import com.android.photopicker.core.theme.PhotopickerTheme 31 import org.junit.Rule 32 import org.junit.Test 33 import org.junit.runner.RunWith 34 35 @SmallTest 36 @RunWith(AndroidJUnit4::class) 37 class EmptyStateTest { 38 39 companion object { 40 private val EMPTY_STATE_TEST_TITLE = "No photos yet" 41 private val EMPTY_STATE_TEST_BODY = "Take some more photos!" 42 } 43 44 @get:Rule val composeTestRule = createComposeRule() 45 46 @Test testEmptyStateDisplaysTitleAndBodynull47 fun testEmptyStateDisplaysTitleAndBody() { 48 composeTestRule.setContent { 49 CompositionLocalProvider( 50 51 // Required for PhotopickerTheme 52 LocalPhotopickerConfiguration provides 53 TestPhotopickerConfiguration.build { 54 action("TEST_ACTION") 55 intent(Intent("TEST_ACTION")) 56 } 57 ) { 58 // PhotopickerTheme is needed for CustomAccentColor support 59 PhotopickerTheme( 60 config = 61 TestPhotopickerConfiguration.build { 62 action("TEST_ACTION") 63 intent(Intent("TEST_ACTION")) 64 } 65 ) { 66 EmptyState( 67 icon = Icons.Outlined.Image, 68 title = EMPTY_STATE_TEST_TITLE, 69 body = EMPTY_STATE_TEST_BODY, 70 ) 71 } 72 } 73 } 74 75 composeTestRule.onNodeWithText(EMPTY_STATE_TEST_TITLE).assertIsDisplayed() 76 composeTestRule.onNodeWithText(EMPTY_STATE_TEST_BODY).assertIsDisplayed() 77 } 78 } 79