Skip to content

Commit

Permalink
Use localized string in UI test (#462)
Browse files Browse the repository at this point in the history
* Use localized string in UI test

* revert the controlToken URL change. Will add Control Token tag in wiki for scaffold so that same no. can be use for params & control url
  • Loading branch information
mishramayank1 committed Jul 28, 2023
1 parent 8de514d commit 4562f31
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 302 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,6 @@ open class BaseTest {
// Verify component is displayed
component.assertExists(errorMessage)
}

fun getString(resId: Int) = context.resources.getString(resId)
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
package com.microsoft.fluentuidemo.demos

import android.content.Intent
import android.content.res.Resources
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.test.*
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.click
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTouchInput
import androidx.compose.ui.test.swipeDown
import androidx.compose.ui.test.swipeUp
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.intent.Intents
import androidx.test.platform.app.InstrumentationRegistry
import com.microsoft.fluentui.tokenized.drawer.DRAWER_CONTENT_TAG
import com.microsoft.fluentui.tokenized.drawer.DRAWER_HANDLE_TAG
import com.microsoft.fluentui.tokenized.drawer.DRAWER_SCRIM_TAG
import com.microsoft.fluentuidemo.BaseTest
import com.microsoft.fluentuidemo.DemoActivity
import org.junit.After
import com.microsoft.fluentuidemo.R
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import java.util.*

class V2BottomDrawerUITest : BaseTest() {

Expand Down Expand Up @@ -50,8 +48,11 @@ class V2BottomDrawerUITest : BaseTest() {

@Test
fun testBottomDrawer1() {
composeTestRule.onNodeWithText("Bottom Slide Over", useUnmergedTree = true).performClick()
composeTestRule.onNodeWithText("Open Drawer").performClick()
composeTestRule.onNodeWithText(
getString(R.string.drawer_bottom_slide_over),
useUnmergedTree = true
).performClick()
composeTestRule.onNodeWithText(getString(R.string.drawer_open)).performClick()
openCheckForVerticalDrawer()

val scrimEnd = drawerHandle.fetchSemanticsNode().positionInRoot.y.toInt()
Expand All @@ -71,8 +72,11 @@ class V2BottomDrawerUITest : BaseTest() {

@Test
fun testBottomDrawer2() {
composeTestRule.onNodeWithText("Bottom Slide Over", useUnmergedTree = true).performClick()
composeTestRule.onNodeWithText("Open Drawer").performClick()
composeTestRule.onNodeWithText(
getString(R.string.drawer_bottom_slide_over),
useUnmergedTree = true
).performClick()
composeTestRule.onNodeWithText(getString(R.string.drawer_open)).performClick()
openCheckForVerticalDrawer()

//SwipeDown on drawerHandle should close it.
Expand All @@ -87,8 +91,11 @@ class V2BottomDrawerUITest : BaseTest() {

@Test
fun testBottomDrawer3() {
composeTestRule.onNodeWithText("Bottom Slide Over", useUnmergedTree = true).performClick()
composeTestRule.onNodeWithText("Open Drawer").performClick()
composeTestRule.onNodeWithText(
getString(R.string.drawer_bottom_slide_over),
useUnmergedTree = true
).performClick()
composeTestRule.onNodeWithText(getString(R.string.drawer_open)).performClick()
openCheckForVerticalDrawer()

val drawerStart = drawerHandle.fetchSemanticsNode().positionInRoot.y.toInt()
Expand All @@ -108,8 +115,11 @@ class V2BottomDrawerUITest : BaseTest() {

@Test
fun testBottomDrawer4() {
composeTestRule.onNodeWithText("Bottom Slide Over", useUnmergedTree = true).performClick()
composeTestRule.onNodeWithText("Open Drawer").performClick()
composeTestRule.onNodeWithText(
getString(R.string.drawer_bottom_slide_over),
useUnmergedTree = true
).performClick()
composeTestRule.onNodeWithText(getString(R.string.drawer_open)).performClick()
openCheckForVerticalDrawer()

val scrimEnd = drawerHandle.fetchSemanticsNode().positionInRoot.y.toInt()
Expand All @@ -130,8 +140,11 @@ class V2BottomDrawerUITest : BaseTest() {

@Test
fun testBottomDrawer5() {
composeTestRule.onNodeWithText("Bottom Slide Over", useUnmergedTree = true).performClick()
composeTestRule.onNodeWithText("Open Drawer").performClick()
composeTestRule.onNodeWithText(
getString(R.string.drawer_bottom_slide_over),
useUnmergedTree = true
).performClick()
composeTestRule.onNodeWithText(getString(R.string.drawer_open)).performClick()
openCheckForVerticalDrawer()

//SwipeDown a little should not close the drawer
Expand All @@ -148,8 +161,11 @@ class V2BottomDrawerUITest : BaseTest() {

@Test
fun testBottomDrawer6() {
composeTestRule.onNodeWithText("Bottom Slide Over", useUnmergedTree = true).performClick()
composeTestRule.onNodeWithText("Expand Drawer").performClick()
composeTestRule.onNodeWithText(
getString(R.string.drawer_bottom_slide_over),
useUnmergedTree = true
).performClick()
composeTestRule.onNodeWithText(getString(R.string.drawer_expand)).performClick()
openCheckForVerticalDrawer()

//SwipeDown on drawerHandle should close it.
Expand All @@ -164,9 +180,12 @@ class V2BottomDrawerUITest : BaseTest() {

@Test
fun testBottomDrawer7() {
composeTestRule.onNodeWithText("Bottom Slide Over", useUnmergedTree = true).performClick()
composeTestRule.onNodeWithText(
getString(R.string.drawer_bottom_slide_over),
useUnmergedTree = true
).performClick()
composeTestRule.onNodeWithText("Show Handle", useUnmergedTree = true).performClick()
composeTestRule.onNodeWithText("Open Drawer").performClick()
composeTestRule.onNodeWithText(getString(R.string.drawer_open)).performClick()

//Content should be visible without handle
drawerContent.assertExists("Drawer Content not shown")
Expand All @@ -189,8 +208,8 @@ class V2BottomDrawerUITest : BaseTest() {
// Investigated that the animateTo is not invoked with one click.
// However, it is invoked 2 time on next click & then 2 times in retry.

composeTestRule.onNodeWithText("Open Drawer").performClick()
composeTestRule.onNodeWithText("Open Drawer").performClick()
composeTestRule.onNodeWithText(getString(R.string.drawer_open)).performClick()
composeTestRule.onNodeWithText(getString(R.string.drawer_open)).performClick()
//SwipeDown on drawerHandle should close it.
drawerHandle.performTouchInput {
swipeDown(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package com.microsoft.fluentuidemo.demos

import android.content.Intent
import androidx.compose.ui.test.*
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.intent.Intents
import androidx.test.platform.app.InstrumentationRegistry
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertIsEnabled
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.onAllNodesWithText
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.microsoft.fluentuidemo.BaseTest
import com.microsoft.fluentuidemo.DemoActivity
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import java.util.*

class V2ButtonsActivityUITest : BaseTest() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.microsoft.fluentui.tokenized.notification.*
import com.microsoft.fluentuidemo.BaseTest
import com.microsoft.fluentuidemo.R
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -80,14 +81,16 @@ class V2CardNudgeActivityUITest : BaseTest() {
fun testLeftSwipe() {
composeTestRule.onNodeWithTag(CARD_NUDGE).performTouchInput { swipeLeft() }
composeTestRule.onNodeWithTag(CARD_NUDGE).performClick()
composeTestRule.onNodeWithText("Left Swiped", substring = true).assertExists()
composeTestRule.onNodeWithText(getString(R.string.fluentui_left_swiped), substring = true)
.assertExists()
}

@Test
fun testRightSwipe() {
composeTestRule.onNodeWithTag(CARD_NUDGE).performTouchInput { swipeRight() }
composeTestRule.onNodeWithTag(CARD_NUDGE).performClick()
composeTestRule.onNodeWithText("Right Swiped", substring = true).assertExists()
composeTestRule.onNodeWithText(getString(R.string.fluentui_right_swiped), substring = true)
.assertExists()
}

}
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
package com.microsoft.fluentuidemo.demos

import android.content.Intent
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso
import androidx.test.espresso.intent.Intents
import androidx.test.platform.app.InstrumentationRegistry
import com.microsoft.fluentui.tokenized.menu.DIALOG_TEST_TAG
import com.microsoft.fluentuidemo.BaseTest
import com.microsoft.fluentuidemo.DemoActivity
import org.junit.After
import com.microsoft.fluentuidemo.R
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import java.util.*

class V2DialogActivityUITest: BaseTest() {
class V2DialogActivityUITest : BaseTest() {

@Before
fun initialize() {
Expand All @@ -27,17 +20,17 @@ class V2DialogActivityUITest: BaseTest() {

@Test
fun testDialog() {
composeTestRule.onNodeWithText("Show Dialog").performClick()
val dialog = composeTestRule.onNodeWithTag("Dialog")
composeTestRule.onNodeWithText(getString(R.string.show_dialog)).performClick()
val dialog = composeTestRule.onNodeWithTag(DIALOG_TEST_TAG)
dialog.assertExists()
dialog.assertIsDisplayed()
composeTestRule.onNodeWithText("Ok").assertExists().assertIsDisplayed()
composeTestRule.onNodeWithText(getString(R.string.ok)).assertExists().assertIsDisplayed()
}

@Test
fun testBackPressDialog() {
composeTestRule.onNodeWithText("Show Dialog").performClick()
val dialog = composeTestRule.onNodeWithTag("Dialog")
composeTestRule.onNodeWithText(getString(R.string.show_dialog)).performClick()
val dialog = composeTestRule.onNodeWithTag(DIALOG_TEST_TAG)
dialog.assertExists()
dialog.assertIsDisplayed()
Espresso.pressBack()
Expand All @@ -47,8 +40,8 @@ class V2DialogActivityUITest: BaseTest() {
@Test
fun testBackPressDismissDialog() {
composeTestRule.onNodeWithTag("back press").performClick()
composeTestRule.onNodeWithText("Show Dialog").performClick()
val dialog = composeTestRule.onNodeWithTag("Dialog")
composeTestRule.onNodeWithText(getString(R.string.show_dialog)).performClick()
val dialog = composeTestRule.onNodeWithTag(DIALOG_TEST_TAG)
dialog.assertExists()
dialog.assertIsDisplayed()
Espresso.pressBack()
Expand Down
Loading

0 comments on commit 4562f31

Please sign in to comment.