[go: nahoru, domu]

blob: 3c23b2933ed93d5941b40590f9d4892cc7279065 [file] [log] [blame]
/*
* Copyright 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package androidx.ui.androidview.test
import android.util.TypedValue
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.widget.RelativeLayout
import androidx.test.espresso.Espresso
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withParent
import androidx.test.filters.SmallTest
import androidx.ui.androidview.AndroidView
import androidx.ui.core.Owner
import androidx.ui.test.createComposeRule
import org.hamcrest.CoreMatchers.instanceOf
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import kotlin.math.roundToInt
@SmallTest
@RunWith(JUnit4::class)
class ComposedViewTest {
@get:Rule
val composeTestRule = createComposeRule()
@Test
fun androidViewTest() {
composeTestRule.setContent {
AndroidView(R.layout.test_layout)
}
Espresso
.onView(instanceOf(RelativeLayout::class.java))
.check(matches(isDisplayed()))
}
@Test
fun androidViewTest_preservesLayoutParams() {
composeTestRule.setContent {
AndroidView(R.layout.test_layout)
}
Espresso
.onView(withParent(withParent(instanceOf(Owner::class.java))))
.check(matches(isDisplayed()))
.check { view, exception ->
if (view.layoutParams.width !=
TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
300f,
view.context.resources.displayMetrics
).roundToInt()
) {
throw exception
}
if (view.layoutParams.height != WRAP_CONTENT) {
throw exception
}
}
}
}