[go: nahoru, domu]

blob: 5b4ac595f94ed07f02d5d3420831e06412894ed6 [file] [log] [blame]
Filip Pavlis028c0d52020-06-29 15:07:53 +01001/*
2 * Copyright 2020 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
Louis Pullen-Freilichddda7be2020-07-17 18:28:12 +010017package androidx.compose.foundation
Filip Pavlis028c0d52020-06-29 15:07:53 +010018
19import androidx.compose.Composable
20import androidx.ui.core.Modifier
21import androidx.ui.core.testTag
Louis Pullen-Freilich623e4052020-07-19 20:24:03 +010022import androidx.compose.foundation.layout.DpConstraints
23import androidx.compose.foundation.layout.Stack
24import androidx.compose.foundation.layout.preferredSizeIn
Filip Pavlis028c0d52020-06-29 15:07:53 +010025import androidx.ui.test.ComposeTestRule
26import androidx.ui.test.SemanticsNodeInteraction
Filip Pavlis659ea722020-07-13 14:14:32 +010027import androidx.ui.test.onNodeWithTag
Filip Pavlis028c0d52020-06-29 15:07:53 +010028import androidx.ui.unit.dp
29
30/**
31 * Constant to emulate very big but finite constraints
32 */
33val BigTestConstraints = DpConstraints(maxWidth = 5000.dp, maxHeight = 5000.dp)
34
35fun ComposeTestRule.setContentForSizeAssertions(
36 parentConstraints: DpConstraints = BigTestConstraints,
37 children: @Composable () -> Unit
38): SemanticsNodeInteraction {
39 setContent {
40 Stack {
41 Stack(
42 Modifier.preferredSizeIn(parentConstraints)
43 .testTag("containerForSizeAssertion")) {
44 children()
45 }
46 }
47 }
48
Filip Pavlis659ea722020-07-13 14:14:32 +010049 return onNodeWithTag("containerForSizeAssertion")
Filip Pavlis028c0d52020-06-29 15:07:53 +010050}