Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.contentDescription
Expand Down Expand Up @@ -195,7 +196,8 @@ fun LoginServerListItem(
modifier = Modifier
.padding(end = PADDING_SIZE.dp)
.size(ICON_SIZE.dp)
.offset { offset },
.offset { offset }
.testTag(LoginViewTestTags.SERVER_DELETE_BUTTON),
) {
Icon(
Icons.TwoTone.Delete,
Expand Down Expand Up @@ -225,6 +227,7 @@ fun LoginServerListItem(
.background(colorScheme.error)
.width(DELETE_BUTTON_SIZE.dp)
.height(rowHeightDp.value)
.testTag(LoginViewTestTags.SERVER_CONFIRM_DELETE_BUTTON)
.clickable { removeServer(server) },
) {
val deleteContentDescription = stringResource(sf__server_delete_content_description)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.core.net.toUri
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
Expand All @@ -98,9 +99,11 @@ import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
Expand Down Expand Up @@ -234,6 +237,7 @@ fun LoginView() {
)
}

@OptIn(ExperimentalComposeUiApi::class)
Comment thread
wmathurin marked this conversation as resolved.
@Composable
internal fun LoginView(
dynamicBackgroundColor: MutableState<Color>,
Expand All @@ -254,6 +258,9 @@ internal fun LoginView(
)

Scaffold(
// Expose Compose testTags as Android resource-ids so UI automation (UIAutomator2/UTAM)
// can anchor on the stable, locale-invariant tags rather than localized contentDescriptions.
modifier = Modifier.semantics { testTagsAsResourceId = true },
bottomBar = bottomAppBar,
contentWindowInsets = WindowInsets.safeDrawing,
topBar = topAppBar,
Expand Down Expand Up @@ -285,7 +292,7 @@ internal fun LoginView(
}


@OptIn(ExperimentalMaterial3Api::class)
@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class)
@Composable
internal fun DefaultTopAppBar(
backgroundColor: Color,
Expand Down Expand Up @@ -324,6 +331,7 @@ internal fun DefaultTopAppBar(
disabledContainerColor = Color.Transparent,
disabledContentColor = Color.Transparent,
),
modifier = Modifier.testTag(LoginViewTestTags.MORE_OPTIONS_BUTTON),
) {
Icon(Icons.Default.MoreVert, contentDescription = moreOptionsDescription)
}
Expand All @@ -335,33 +343,36 @@ internal fun DefaultTopAppBar(
DropdownMenu(
expanded = showMenu,
onDismissRequest = { showMenu = false },
// The menu renders in its own popup window, so opt in here as well to expose
// the menu items' testTags as Android resource-ids for UI automation.
modifier = Modifier.semantics { testTagsAsResourceId = true },
) {
MenuItem(stringResource(sf__pick_server)) {
MenuItem(stringResource(sf__pick_server), testTag = LoginViewTestTags.MENU_ITEM_PICK_SERVER) {
showServerPicker.value = true
showMenu = false
}
MenuItem(stringResource(sf__clear_cookies)) {
MenuItem(stringResource(sf__clear_cookies), testTag = LoginViewTestTags.MENU_ITEM_CLEAR_COOKIES) {
clearCookies()
reloadWebView()
showMenu = false
}
MenuItem(stringResource(sf__clear_cache)) {
MenuItem(stringResource(sf__clear_cache), testTag = LoginViewTestTags.MENU_ITEM_CLEAR_CACHE) {
clearWebViewCache()
reloadWebView()
showMenu = false
}
MenuItem(stringResource(sf__reload)) {
MenuItem(stringResource(sf__reload), testTag = LoginViewTestTags.MENU_ITEM_RELOAD) {
reloadWebView()
showMenu = false
}
onLoginForAdmins?.let {
MenuItem(stringResource(sf__login_for_admins)) {
MenuItem(stringResource(sf__login_for_admins), testTag = LoginViewTestTags.MENU_ITEM_LOGIN_FOR_ADMINS) {
it.invoke()
showMenu = false
}
}
showDevSupport?.let {
MenuItem(stringResource(sf__dev_support_title_menu_item)) {
MenuItem(stringResource(sf__dev_support_title_menu_item), testTag = LoginViewTestTags.MENU_ITEM_DEV_SUPPORT) {
it.invoke()
showMenu = false
}
Expand All @@ -380,6 +391,7 @@ internal fun DefaultTopAppBar(
disabledContainerColor = Color.Transparent,
disabledContentColor = Color.Transparent,
),
modifier = Modifier.testTag(LoginViewTestTags.BACK_BUTTON),
) {
Icon(
Icons.AutoMirrored.Filled.ArrowBack,
Expand All @@ -403,6 +415,7 @@ internal fun DefaultLoadingIndicator() {
modifier = Modifier
.size(LOADING_INDICATOR_SIZE.dp)
.fillMaxSize()
.testTag(LoginViewTestTags.LOADING_INDICATOR)
.semantics { contentDescription = description },
)
}
Expand All @@ -411,6 +424,7 @@ internal fun DefaultLoadingIndicator() {
@Composable
internal fun MenuItem(
text: String,
testTag: String? = null,
onClick: () -> Unit,
) {
DropdownMenuItem(
Expand All @@ -422,7 +436,9 @@ internal fun MenuItem(
)
},
onClick = onClick,
modifier = Modifier.semantics { contentDescription = text }
modifier = Modifier
.then(if (testTag != null) Modifier.testTag(testTag) else Modifier)
Comment thread
wmathurin marked this conversation as resolved.
.semantics { contentDescription = text }
)
}

Expand Down Expand Up @@ -469,6 +485,7 @@ internal fun DefaultBottomAppBar(
.padding(PADDING_SIZE.dp)
.height(BUTTON_HEIGHT.dp)
.fillMaxWidth()
.testTag(LoginViewTestTags.LOGIN_BUTTON)
.shadow(LEVEL_3_ELEVATION.dp, buttonShape),
shape = buttonShape,
contentPadding = PaddingValues(PADDING_SIZE.dp),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Copyright (c) 2026-present, salesforce.com, inc.
* All rights reserved.
* Redistribution and use of this software in source and binary forms, with or
* without modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of salesforce.com, inc. nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission of salesforce.com, inc.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.salesforce.androidsdk.ui.components

/**
* Stable, locale-invariant test tags for the Mobile SDK login screen and the
* server / account picker bottom sheet.
*
* Each value is applied to its Compose node via [androidx.compose.ui.platform.testTag]. Because
* the composition roots that host these nodes opt in with
* `Modifier.semantics { testTagsAsResourceId = true }`, the tags are surfaced to UI automation
* (UIAutomator2 / UTAM) as Android `resource-id`s. Unlike the localized `contentDescription`
* strings the UI also exposes, these values never change across device languages, so test and
* page-object code can anchor on them in any locale — including right-to-left layouts.
*
* This object is the single source of truth for those values. It is intentionally public so that
* SDK instrumented tests, sample-app page objects (e.g. AuthFlowTester), and external UTAM page
* objects can all reference the same constants instead of duplicating the literal strings.
*
* IMPORTANT: These are test anchors only. Do NOT localize them and do NOT reuse them as
* user-facing strings.
*/
object LoginViewTestTags {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might appear to be an over investment given our future Login UX plans, but I actually see it being a useful bridge. If/when we introduce a new SDK provided default UI in 15.0 we can ensure these tags are used. And since they are public consuming apps can use them in their UI implementation if they chose to create their own. This make UI tests easier to migrate and hopefully ease the transition.


// region Login screen top bar
/** Three-dot "More Options" overflow button in the login top app bar. */
const val MORE_OPTIONS_BUTTON = "sf__more_options_button"

/** Navigation "back" button in the login top app bar (shown conditionally). */
const val BACK_BUTTON = "sf__back_button"
// endregion

// region Login screen overflow menu items
/** "Change Server" overflow menu item. */
const val MENU_ITEM_PICK_SERVER = "sf__menu_item_pick_server"

/** "Clear Cookies" overflow menu item. */
const val MENU_ITEM_CLEAR_COOKIES = "sf__menu_item_clear_cookies"

/** "Clear Cache" overflow menu item. */
const val MENU_ITEM_CLEAR_CACHE = "sf__menu_item_clear_cache"

/** "Reload" overflow menu item. */
const val MENU_ITEM_RELOAD = "sf__menu_item_reload"

/** "Login for Admins" overflow menu item (shown conditionally). */
const val MENU_ITEM_LOGIN_FOR_ADMINS = "sf__menu_item_login_for_admins"

/** "Developer Support" overflow menu item (debug builds only). */
const val MENU_ITEM_DEV_SUPPORT = "sf__menu_item_dev_support"
// endregion

// region Login screen body
/** Bottom-bar login action button (biometric / IDP / custom). */
const val LOGIN_BUTTON = "sf__login_button"

/** Indeterminate loading spinner shown over the login WebView. */
const val LOADING_INDICATOR = "sf__loading_indicator"
// endregion

// region Picker bottom sheet
/** Root container of the login-server picker bottom sheet. */
const val SERVER_PICKER = "sf__server_picker"

/** Root container of the user-account picker bottom sheet. */
const val ACCOUNT_PICKER = "sf__account_picker"

/** Back arrow shown in the picker header while adding a new connection. */
const val PICKER_BACK_BUTTON = "sf__picker_back_button"

/** Close (X) button in the picker header. */
const val PICKER_CLOSE_BUTTON = "sf__picker_close_button"

/** "Add New Connection" button in the login-server picker. */
const val CUSTOM_URL_BUTTON = "sf__custom_url_button"

/** "Add New Account" button in the user-account picker. */
const val ADD_NEW_ACCOUNT_BUTTON = "sf__add_new_account_button"

/** Name field in the picker's "Add Connection" form. */
const val PICKER_CUSTOM_LABEL = "sf__picker_custom_label"

/** URL field in the picker's "Add Connection" form. */
const val PICKER_CUSTOM_URL = "sf__picker_custom_url"

/** Save / apply button in the picker's "Add Connection" form. */
const val APPLY_BUTTON = "sf__apply_button"
// endregion

// region Server list item
/**
* Trash icon on a custom server row that arms the slide-to-delete affordance.
*
* Every custom server row carries this same tag by design, so a bare match resolves to
* multiple nodes. To target a specific row, combine it with a content matcher that
* identifies the row:
* ```
* onNode(hasTestTag(SERVER_DELETE_BUTTON) and hasAncestor(hasText("MyOrg")))
* ```
*/
const val SERVER_DELETE_BUTTON = "sf__server_delete_button"

/**
* Revealed confirm-delete target on a custom server row.
*
* Shared across all custom rows just like [SERVER_DELETE_BUTTON]; combine it with a content
* matcher (e.g. `and hasAncestor(hasText("MyOrg"))`) to target a specific row.
*/
const val SERVER_CONFIRM_DELETE_BUTTON = "sf__server_confirm_delete_button"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both SERVER_DELETE_BUTTON and SERVER_CONFIRM_DELETE_BUTTON are shared by every row in the list — all delete buttons get the same tag by design. That's expected Compose behaviour, but it will surprise the first person writing a test that targets a specific server row. Worth adding a one-liner KDoc note here (and on SERVER_DELETE_BUTTON above) pointing to the row-identity pattern:

// To target a specific row, combine with a content matcher:
// onNode(hasTestTag(SERVER_DELETE_BUTTON) and hasAncestor(hasText("MyOrg")))

// endregion
}
Loading
Loading