Skip to content

Commit cf95ed2

Browse files
committed
New menu item is "Clear cache" instead of "Clear caches"
Renaming methods accordingly Fixed test
1 parent 4e9b74a commit cf95ed2

5 files changed

Lines changed: 35 additions & 34 deletions

File tree

libs/SalesforceSDK/res/values/sf__strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<string name="sf__more_options">More Options</string>
2525
<string name="sf__pick_server">Change Server</string>
2626
<string name="sf__clear_cookies">Clear Cookies</string>
27-
<string name="sf__clear_caches">Clear Caches</string>
27+
<string name="sf__clear_cache">Clear cache</string>
2828
<string name="sf__reload">Reload</string>
2929
<string name="sf__launch_idp">Log In with IDP App</string>
3030
<string name="sf__login_with_biometric">Log In with Biometric</string>

libs/SalesforceSDK/src/com/salesforce/androidsdk/ui/LoginViewModel.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ package com.salesforce.androidsdk.ui
2828

2929
import android.webkit.CookieManager
3030
import android.webkit.URLUtil
31+
import android.webkit.WebView
3132
import androidx.annotation.VisibleForTesting
3233
import androidx.compose.runtime.Composable
3334
import androidx.compose.runtime.derivedStateOf
@@ -241,8 +242,8 @@ open class LoginViewModel(val bootConfig: BootConfig) : ViewModel() {
241242
open fun clearCookies() =
242243
CookieManager.getInstance().removeAllCookies(null)
243244

244-
/** Clear WebView Caches. */
245-
open fun clearCaches(webView: android.webkit.WebView) {
245+
/** Clear WebView Cache. */
246+
open fun clearWebViewCache(webView: WebView) {
246247
webView.clearCache(true)
247248
}
248249

libs/SalesforceSDK/src/com/salesforce/androidsdk/ui/components/LoginView.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ import androidx.lifecycle.LiveData
107107
import androidx.lifecycle.viewmodel.compose.viewModel
108108
import com.salesforce.androidsdk.R.string.sf__back_button_content_description
109109
import com.salesforce.androidsdk.R.string.sf__clear_cookies
110-
import com.salesforce.androidsdk.R.string.sf__clear_caches
110+
import com.salesforce.androidsdk.R.string.sf__clear_cache
111111
import com.salesforce.androidsdk.R.string.sf__launch_idp
112112
import com.salesforce.androidsdk.R.string.sf__loading_indicator
113113
import com.salesforce.androidsdk.R.string.sf__more_options
@@ -150,7 +150,7 @@ fun LoginView() {
150150
titleTextColor = viewModel.titleTextColor ?: viewModel.dynamicHeaderTextColor.value,
151151
showServerPicker = viewModel.showServerPicker,
152152
clearCookies = { viewModel.clearCookies() },
153-
clearCaches = { viewModel.clearCaches(activity.webView) },
153+
clearWebViewCache = { viewModel.clearWebViewCache(activity.webView) },
154154
reloadWebView = { viewModel.reloadWebView() },
155155
shouldShowBackButton = viewModel.shouldShowBackButton,
156156
finish = { activity.handleBackBehavior() },
@@ -248,7 +248,7 @@ internal fun DefaultTopAppBar(
248248
titleTextColor: Color,
249249
showServerPicker: MutableState<Boolean>,
250250
clearCookies: () -> Unit,
251-
clearCaches: () -> Unit,
251+
clearWebViewCache: () -> Unit,
252252
reloadWebView: () -> Unit,
253253
shouldShowBackButton: Boolean,
254254
finish: () -> Unit,
@@ -298,8 +298,8 @@ internal fun DefaultTopAppBar(
298298
reloadWebView()
299299
showMenu = false
300300
}
301-
MenuItem(stringResource(sf__clear_caches)) {
302-
clearCaches()
301+
MenuItem(stringResource(sf__clear_cache)) {
302+
clearWebViewCache()
303303
reloadWebView()
304304
showMenu = false
305305
}
@@ -482,7 +482,7 @@ private fun AppBarPreview() {
482482
titleTextColor = Color.Black,
483483
showServerPicker = remember { mutableStateOf(false) },
484484
clearCookies = { },
485-
clearCaches = { },
485+
clearWebViewCache = { },
486486
reloadWebView = { },
487487
shouldShowBackButton = false,
488488
finish = { },
@@ -502,7 +502,7 @@ private fun AppBarLoadingPreview() {
502502
titleTextColor = Color.Black,
503503
showServerPicker = remember { mutableStateOf(false) },
504504
clearCookies = { },
505-
clearCaches = { },
505+
clearWebViewCache = { },
506506
reloadWebView = { },
507507
shouldShowBackButton = false,
508508
finish = { },
@@ -522,7 +522,7 @@ private fun AppBarBackButtonPreview() {
522522
titleTextColor = Color.Black,
523523
showServerPicker = remember { mutableStateOf(false) },
524524
clearCookies = { },
525-
clearCaches = { },
525+
clearWebViewCache = { },
526526
reloadWebView = { },
527527
shouldShowBackButton = true,
528528
finish = { },
@@ -542,7 +542,7 @@ private fun AppBarDarkPreview() {
542542
titleTextColor = Color.White,
543543
showServerPicker = remember { mutableStateOf(false) },
544544
clearCookies = { },
545-
clearCaches = { },
545+
clearWebViewCache = { },
546546
reloadWebView = { },
547547
shouldShowBackButton = true,
548548
finish = { },
@@ -562,7 +562,7 @@ private fun BlueAppBarPreview() {
562562
titleTextColor = Color.White,
563563
showServerPicker = remember { mutableStateOf(false) },
564564
clearCookies = { },
565-
clearCaches = { },
565+
clearWebViewCache = { },
566566
reloadWebView = { },
567567
shouldShowBackButton = true,
568568
finish = { },
@@ -582,7 +582,7 @@ private fun BlueAppBarLoadingPreview() {
582582
titleTextColor = Color.White,
583583
showServerPicker = remember { mutableStateOf(false) },
584584
clearCookies = { },
585-
clearCaches = { },
585+
clearWebViewCache = { },
586586
reloadWebView = { },
587587
shouldShowBackButton = true,
588588
finish = { },
@@ -601,7 +601,7 @@ private fun CustomTextAppBarPreview() {
601601
titleTextColor = Color.White,
602602
showServerPicker = remember { mutableStateOf(false) },
603603
clearCookies = { },
604-
clearCaches = { },
604+
clearWebViewCache = { },
605605
reloadWebView = { },
606606
shouldShowBackButton = false,
607607
finish = { },
@@ -620,7 +620,7 @@ private fun CustomTextAppBarLoadingPreview() {
620620
titleTextColor = Color.White,
621621
showServerPicker = remember { mutableStateOf(false) },
622622
clearCookies = { },
623-
clearCaches = { },
623+
clearWebViewCache = { },
624624
reloadWebView = { },
625625
shouldShowBackButton = false,
626626
finish = { },
@@ -639,7 +639,7 @@ private fun LongCustomTextAppBarPreview() {
639639
titleTextColor = Color.Black,
640640
showServerPicker = remember { mutableStateOf(false) },
641641
clearCookies = { },
642-
clearCaches = { },
642+
clearWebViewCache = { },
643643
reloadWebView = { },
644644
shouldShowBackButton = true,
645645
finish = { },

libs/test/SalesforceSDKTest/src/com/salesforce/androidsdk/auth/LoginViewModelTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import android.webkit.WebView
3030
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
3131
import androidx.test.ext.junit.runners.AndroidJUnit4
3232
import androidx.test.platform.app.InstrumentationRegistry
33-
import org.mockito.Mockito.mock
34-
import org.mockito.Mockito.verify
33+
import io.mockk.mockk
34+
import io.mockk.verify
3535
import com.salesforce.androidsdk.R.string.oauth_display_type
3636
import com.salesforce.androidsdk.app.SalesforceSDKManager
3737
import com.salesforce.androidsdk.auth.OAuth2.getFrontdoorUrl
@@ -201,15 +201,15 @@ class LoginViewModelTest {
201201
}
202202

203203
@Test
204-
fun clearCaches_CallsWebViewClearCache_WithTrueParameter() {
204+
fun clearWebViewCache_CallsWebViewClearCache_WithTrueParameter() {
205205
// Arrange
206-
val mockWebView = mock(WebView::class.java)
206+
val mockWebView = mockk<WebView>(relaxed = true)
207207

208208
// Act
209-
viewModel.clearCaches(mockWebView)
209+
viewModel.clearWebViewCache(mockWebView)
210210

211211
// Assert
212-
verify(mockWebView).clearCache(true)
212+
verify { mockWebView.clearCache(true) }
213213
}
214214

215215
private fun generateExpectedAuthorizationUrl(

libs/test/SalesforceSDKTest/src/com/salesforce/androidsdk/ui/LoginViewActivityTest.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@ class LoginViewActivityTest {
186186
}
187187

188188
@Test
189-
fun topAppBar_ClearCachesButton_ClearsCachesAndReloads() {
190-
var clearCachesCalled = false
189+
fun topAppBar_ClearCacheButton_ClearsCacheAndReloads() {
190+
var clearCacheCalled = false
191191
var reloadCalled = false
192192
androidComposeTestRule.setContent {
193193
DefaultTopAppBarTestWrapper(
194-
clearCaches = { clearCachesCalled = true },
194+
clearWebViewCache = { clearCacheCalled = true },
195195
reloadWebView = { reloadCalled = true },
196196
)
197197
}
@@ -203,21 +203,21 @@ class LoginViewActivityTest {
203203
val menu = androidComposeTestRule.onNodeWithContentDescription(
204204
androidComposeTestRule.activity.getString(R.string.sf__more_options)
205205
)
206-
val clearCachesButton = androidComposeTestRule.onNodeWithText(
207-
androidComposeTestRule.activity.getString(R.string.sf__clear_caches)
206+
val clearCacheButton = androidComposeTestRule.onNodeWithText(
207+
androidComposeTestRule.activity.getString(R.string.sf__clear_cache)
208208
)
209209

210210
backButton.assertDoesNotExist()
211211
titleText.assertIsDisplayed()
212212
menu.assertIsDisplayed()
213213

214214
menu.performClick()
215-
clearCachesButton.assertIsDisplayed()
216-
Assert.assertFalse("Clear caches should not be called yet.", clearCachesCalled)
215+
clearCacheButton.assertIsDisplayed()
216+
Assert.assertFalse("Clear cache should not be called yet.", clearCacheCalled)
217217
Assert.assertFalse("Reload should not be called yet.", reloadCalled)
218218

219-
clearCachesButton.performClick()
220-
Assert.assertTrue("Clear caches should be called.", clearCachesCalled)
219+
clearCacheButton.performClick()
220+
Assert.assertTrue("Clear cache should be called.", clearCacheCalled)
221221
Assert.assertTrue("Reload should be called.", reloadCalled)
222222
}
223223

@@ -399,14 +399,14 @@ class LoginViewActivityTest {
399399
titleTextColor: Color = Color.Black,
400400
showServerPicker: MutableState<Boolean> = remember { mutableStateOf(false) },
401401
clearCookies: () -> Unit = { },
402-
clearCaches: () -> Unit = { },
402+
clearWebViewCache: () -> Unit = { },
403403
reloadWebView: () -> Unit = { },
404404
shouldShowBackButton: Boolean = false,
405405
finish: () -> Unit = { },
406406
) {
407407
DefaultTopAppBar(
408408
backgroundColor, titleText, titleTextColor, showServerPicker, clearCookies,
409-
clearCaches, reloadWebView, shouldShowBackButton, finish
409+
clearWebViewCache, reloadWebView, shouldShowBackButton, finish
410410
)
411411
}
412412

0 commit comments

Comments
 (0)