Add unit test for Spa footer
Also add two buttons test for ActionButtonsTest. Bug: 260660819 Test: Unit test Change-Id: I01912a1a92271868396769879026f6c93d0bb0f4
This commit is contained in:
@@ -17,11 +17,13 @@
|
||||
package com.android.settingslib.spa.widget.button
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Close
|
||||
import androidx.compose.material.icons.outlined.Launch
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.getBoundsInRoot
|
||||
import androidx.compose.ui.test.junit4.createComposeRule
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
@@ -66,4 +68,19 @@ class ActionButtonsTest {
|
||||
|
||||
assertThat(clicked).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun twoButtons_positionIsAligned() {
|
||||
composeTestRule.setContent {
|
||||
ActionButtons(
|
||||
listOf(
|
||||
ActionButton(text = "Open", imageVector = Icons.Outlined.Launch) {},
|
||||
ActionButton(text = "Close", imageVector = Icons.Outlined.Close) {},
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
assertThat(composeTestRule.onNodeWithText("Open").getBoundsInRoot().top)
|
||||
.isEqualTo(composeTestRule.onNodeWithText("Close").getBoundsInRoot().top)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 com.android.settingslib.spa.widget.ui
|
||||
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.assertIsNotDisplayed
|
||||
import androidx.compose.ui.test.junit4.createComposeRule
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.onRoot
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class FooterTest {
|
||||
@get:Rule
|
||||
val composeTestRule = createComposeRule()
|
||||
|
||||
@Test
|
||||
fun footer_isEmpty() {
|
||||
composeTestRule.setContent {
|
||||
Footer(footerText = "")
|
||||
}
|
||||
|
||||
composeTestRule.onRoot().assertIsNotDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun footer_notEmpty_displayed() {
|
||||
composeTestRule.setContent {
|
||||
Footer(footerText = FOOTER_TEXT)
|
||||
}
|
||||
|
||||
composeTestRule.onNodeWithText(FOOTER_TEXT).assertIsDisplayed()
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val FOOTER_TEXT = "Footer text"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user