[go: nahoru, domu]

blob: 0e1f9b4e8aa98b90e9f28f3671b0c9163270958a [file] [log] [blame]
Filip Pavlis4570f202020-04-17 18:40:22 +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
17package androidx.ui.test.selectors
18
19import androidx.test.filters.MediumTest
Filip Pavlis659ea722020-07-13 14:14:32 +010020import androidx.ui.test.onAncestors
Filip Pavlis4570f202020-04-17 18:40:22 +010021import androidx.ui.test.assert
22import androidx.ui.test.assertCountEquals
23import androidx.ui.test.createComposeRule
Filip Pavlis659ea722020-07-13 14:14:32 +010024import androidx.ui.test.onNodeWithTag
25import androidx.ui.test.onFirst
Filip Pavlis4570f202020-04-17 18:40:22 +010026import androidx.ui.test.hasTestTag
Filip Pavlis659ea722020-07-13 14:14:32 +010027import androidx.ui.test.onParent
Filip Pavlis4570f202020-04-17 18:40:22 +010028import androidx.ui.test.util.BoundaryNode
29import org.junit.Rule
30import org.junit.Test
31import org.junit.runner.RunWith
32import org.junit.runners.JUnit4
33
34@MediumTest
35@RunWith(JUnit4::class)
36class AncestorsSelectorTest {
37
38 @get:Rule
39 val composeTestRule = createComposeRule()
40
41 @Test
42 fun threeAncestors() {
43 composeTestRule.setContent {
44 BoundaryNode(testTag = "NodeA") {
45 BoundaryNode(testTag = "NodeB") {
46 BoundaryNode(testTag = "NodeC") {
47 BoundaryNode(testTag = "NodeD")
48 }
49 }
50 }
51 }
52
Filip Pavlis659ea722020-07-13 14:14:32 +010053 onNodeWithTag("NodeD")
54 .onAncestors()
Matvei Malkov1da47fe2020-05-15 12:40:16 +010055 .assertCountEquals(4)
Filip Pavlis21b8c202020-04-23 14:36:29 +010056 .apply {
57 get(0).assert(hasTestTag("NodeC"))
58 get(1).assert(hasTestTag("NodeB"))
59 get(2).assert(hasTestTag("NodeA"))
Filip Pavlis4570f202020-04-17 18:40:22 +010060 }
61 }
62
63 @Test
64 fun threeAncestors_navigateUp() {
65 composeTestRule.setContent {
66 BoundaryNode(testTag = "NodeA") {
67 BoundaryNode(testTag = "NodeB") {
68 BoundaryNode(testTag = "NodeC") {
69 BoundaryNode(testTag = "NodeD")
70 }
71 }
72 }
73 }
74
Filip Pavlis659ea722020-07-13 14:14:32 +010075 onNodeWithTag("NodeD")
76 .onAncestors()
77 .onFirst()
78 .onAncestors()
Matvei Malkov1da47fe2020-05-15 12:40:16 +010079 .assertCountEquals(3)
Filip Pavlis21b8c202020-04-23 14:36:29 +010080 .apply {
81 get(0).assert(hasTestTag("NodeB"))
82 get(1).assert(hasTestTag("NodeA"))
Filip Pavlis4570f202020-04-17 18:40:22 +010083 }
84 }
85
86 @Test
87 fun noAncestors() {
88 composeTestRule.setContent {
89 BoundaryNode(testTag = "Node")
90 }
91
Filip Pavlis659ea722020-07-13 14:14:32 +010092 onNodeWithTag("Node")
93 .onParent()
94 .onAncestors()
Filip Pavlis4570f202020-04-17 18:40:22 +010095 .assertCountEquals(0)
96 }
97}