[go: nahoru, domu]

blob: 1ebcc152f21877eb79d75419325e913bcf4c506a [file] [log] [blame]
Filip Pavlisde9c6fe2020-05-04 14:19:02 +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
20import androidx.ui.test.assert
Filip Pavlis659ea722020-07-13 14:14:32 +010021import androidx.ui.test.onChildren
Filip Pavlisde9c6fe2020-05-04 14:19:02 +010022import androidx.ui.test.createComposeRule
Filip Pavlis659ea722020-07-13 14:14:32 +010023import androidx.ui.test.onNodeWithTag
Filip Pavlisde9c6fe2020-05-04 14:19:02 +010024import androidx.ui.test.hasTestTag
Filip Pavlis659ea722020-07-13 14:14:32 +010025import androidx.ui.test.onLast
Filip Pavlisde9c6fe2020-05-04 14:19:02 +010026import androidx.ui.test.util.BoundaryNode
27import androidx.ui.test.util.expectErrorMessageStartsWith
28import org.junit.Rule
29import org.junit.Test
30import org.junit.runner.RunWith
31import org.junit.runners.JUnit4
32
33@MediumTest
34@RunWith(JUnit4::class)
35class LastNodeSelectorTest {
36
37 @get:Rule
38 val composeTestRule = createComposeRule()
39
40 @Test
41 fun twoNodes_getLast() {
42 composeTestRule.setContent {
43 BoundaryNode(testTag = "Parent") {
44 BoundaryNode(testTag = "Child1")
45 BoundaryNode(testTag = "Child2")
46 }
47 }
48
Filip Pavlis659ea722020-07-13 14:14:32 +010049 onNodeWithTag("Parent")
50 .onChildren()
51 .onLast()
Filip Pavlisde9c6fe2020-05-04 14:19:02 +010052 .assert(hasTestTag("Child2"))
53 }
54
55 @Test
56 fun zeroNodes_getLast() {
57 composeTestRule.setContent {
58 BoundaryNode(testTag = "Parent")
59 }
60
Filip Pavlis659ea722020-07-13 14:14:32 +010061 onNodeWithTag("Parent")
62 .onChildren()
63 .onLast()
Filip Pavlisde9c6fe2020-05-04 14:19:02 +010064 .assertDoesNotExist()
65 }
66
67 @Test
68 fun zeroNodes_getLast_fail() {
69 composeTestRule.setContent {
70 BoundaryNode(testTag = "Parent")
71 }
72
73 expectErrorMessageStartsWith("" +
74 "Failed: assertExists.\n" +
75 "Reason: Expected exactly '1' node but could not find any node that satisfies: " +
76 "(((TestTag = 'Parent').children).last)") {
Filip Pavlis659ea722020-07-13 14:14:32 +010077 onNodeWithTag("Parent")
78 .onChildren()
79 .onLast()
Filip Pavlisde9c6fe2020-05-04 14:19:02 +010080 .assertExists()
81 }
82 }
83}