Filip Pavlis | 028c0d5 | 2020-06-29 15:07:53 +0100 | [diff] [blame] | 1 | /* |
| 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-Freilich | ddda7be | 2020-07-17 18:28:12 +0100 | [diff] [blame] | 17 | package androidx.compose.foundation |
Filip Pavlis | 028c0d5 | 2020-06-29 15:07:53 +0100 | [diff] [blame] | 18 | |
| 19 | import androidx.compose.Composable |
| 20 | import androidx.ui.core.Modifier |
| 21 | import androidx.ui.core.testTag |
Louis Pullen-Freilich | 623e405 | 2020-07-19 20:24:03 +0100 | [diff] [blame] | 22 | import androidx.compose.foundation.layout.DpConstraints |
| 23 | import androidx.compose.foundation.layout.Stack |
| 24 | import androidx.compose.foundation.layout.preferredSizeIn |
Filip Pavlis | 028c0d5 | 2020-06-29 15:07:53 +0100 | [diff] [blame] | 25 | import androidx.ui.test.ComposeTestRule |
| 26 | import androidx.ui.test.SemanticsNodeInteraction |
Filip Pavlis | 659ea72 | 2020-07-13 14:14:32 +0100 | [diff] [blame] | 27 | import androidx.ui.test.onNodeWithTag |
Filip Pavlis | 028c0d5 | 2020-06-29 15:07:53 +0100 | [diff] [blame] | 28 | import androidx.ui.unit.dp |
| 29 | |
| 30 | /** |
| 31 | * Constant to emulate very big but finite constraints |
| 32 | */ |
| 33 | val BigTestConstraints = DpConstraints(maxWidth = 5000.dp, maxHeight = 5000.dp) |
| 34 | |
| 35 | fun 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 Pavlis | 659ea72 | 2020-07-13 14:14:32 +0100 | [diff] [blame] | 49 | return onNodeWithTag("containerForSizeAssertion") |
Filip Pavlis | 028c0d5 | 2020-06-29 15:07:53 +0100 | [diff] [blame] | 50 | } |