1 /* 2 * Copyright (C) 2023 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.intentresolver.contentpreview 18 19 import android.view.LayoutInflater 20 import android.view.View 21 import android.view.ViewGroup 22 import android.widget.TextView 23 import androidx.test.ext.junit.runners.AndroidJUnit4 24 import androidx.test.platform.app.InstrumentationRegistry 25 import com.android.intentresolver.R 26 import com.android.intentresolver.widget.ActionRow 27 import com.google.common.truth.Truth.assertThat 28 import java.util.function.Consumer 29 import org.junit.Test 30 import org.junit.runner.RunWith 31 import org.mockito.kotlin.doReturn 32 import org.mockito.kotlin.mock 33 34 @RunWith(AndroidJUnit4::class) 35 class FileContentPreviewUiTest { 36 private val fileCount = 2 37 private val text = "Sharing 2 files" 38 private val testMetadataText: CharSequence = "Test metadata text" 39 private val actionFactory = 40 object : ChooserContentPreviewUi.ActionFactory { getEditButtonRunnablenull41 override fun getEditButtonRunnable(): Runnable? = null 42 override fun getCopyButtonRunnable(): Runnable? = null 43 override fun createCustomActions(): List<ActionRow.Action> = emptyList() 44 override fun getModifyShareAction(): ActionRow.Action? = null 45 override fun getExcludeSharedTextAction(): Consumer<Boolean> = Consumer<Boolean> {} 46 } 47 private val headlineGenerator = <lambda>null48 mock<HeadlineGenerator> { on { getFilesHeadline(fileCount) } doReturn text } 49 50 private val context 51 get() = InstrumentationRegistry.getInstrumentation().context 52 53 private val testSubject = 54 FileContentPreviewUi( 55 fileCount, 56 actionFactory, 57 headlineGenerator, 58 testMetadataText, 59 ) 60 61 @Test test_display_titleAndMetadataIsDisplayednull62 fun test_display_titleAndMetadataIsDisplayed() { 63 val layoutInflater = LayoutInflater.from(context) 64 val gridLayout = 65 layoutInflater.inflate(R.layout.chooser_grid_scrollable_preview, null, false) 66 as ViewGroup 67 val headlineRow = gridLayout.requireViewById<View>(R.id.chooser_headline_row_container) 68 69 assertThat(headlineRow.findViewById<View>(R.id.headline)).isNull() 70 assertThat(headlineRow.findViewById<View>(R.id.metadata)).isNull() 71 72 val previewView = 73 testSubject.display( 74 context.resources, 75 layoutInflater, 76 gridLayout, 77 headlineRow, 78 ) 79 80 assertThat(previewView).isNotNull() 81 val headlineView = headlineRow.findViewById<TextView>(R.id.headline) 82 assertThat(headlineView).isNotNull() 83 assertThat(headlineView?.text).isEqualTo(text) 84 val metadataView = headlineRow.findViewById<TextView>(R.id.metadata) 85 assertThat(metadataView?.text).isEqualTo(testMetadataText) 86 } 87 } 88