@@ -36,6 +36,7 @@ import com.amaze.filemanager.utils.smb.SmbUtil
3636import io.mockk.confirmVerified
3737import io.mockk.spyk
3838import io.mockk.verify
39+ import org.junit.Assert.assertEquals
3940import org.junit.Assert.assertTrue
4041import org.junit.Test
4142import org.robolectric.shadows.ShadowDialog
@@ -45,6 +46,64 @@ import org.robolectric.shadows.ShadowLooper
4546 * Tests [SmbConnectDialog].
4647 */
4748class SmbConnectDialogTest : AbstractMainActivityTestBase () {
49+ /* *
50+ * Test editing an existing connection pre-fills all dialog fields.
51+ * Regression test for https://github.com/TeamAmaze/AmazeFileManager/issues/4543
52+ */
53+ @Test
54+ fun testEditConnectionPreFillsAllFields () {
55+ val listener = spyk<SmbConnectionListener >()
56+ val encryptedPath =
57+ SmbUtil .getSmbEncryptedPath(
58+ AppConfig .getInstance(),
59+ " smb://user:password@192.168.1.100/share" ,
60+ )
61+ doTestWithDialog(
62+ listener = listener,
63+ arguments =
64+ Bundle ().also {
65+ it.putString(ARG_NAME , " My SMB Connection" )
66+ it.putString(ARG_PATH , encryptedPath)
67+ it.putBoolean(ARG_EDIT , true )
68+ },
69+ withDialog = { dialog, _ ->
70+ dialog.binding.run {
71+ assertEquals(" My SMB Connection" , this .connectionET.text.toString())
72+ assertEquals(" 192.168.1.100" , this .ipET.text.toString())
73+ assertEquals(" share" , this .shareET.text.toString())
74+ assertEquals(" user" , this .usernameET.text.toString())
75+ assertEquals(" password" , this .passwordET.text.toString())
76+ }
77+ },
78+ )
79+ }
80+
81+ /* *
82+ * Test editing an anonymous connection checks the anonymous checkbox.
83+ * Regression test for https://github.com/TeamAmaze/AmazeFileManager/issues/4543
84+ */
85+ @Test
86+ fun testEditAnonymousConnectionSetsAnonymousCheckbox () {
87+ val listener = spyk<SmbConnectionListener >()
88+ doTestWithDialog(
89+ listener = listener,
90+ arguments =
91+ Bundle ().also {
92+ it.putString(ARG_NAME , " Anonymous SMB" )
93+ it.putString(ARG_PATH , " smb://192.168.1.100/share" )
94+ it.putBoolean(ARG_EDIT , true )
95+ },
96+ withDialog = { dialog, _ ->
97+ dialog.binding.run {
98+ assertEquals(" Anonymous SMB" , this .connectionET.text.toString())
99+ assertEquals(" 192.168.1.100" , this .ipET.text.toString())
100+ assertEquals(" share" , this .shareET.text.toString())
101+ assertTrue(this .chkSmbAnonymous.isChecked)
102+ }
103+ },
104+ )
105+ }
106+
48107 /* *
49108 * Test call to [SmbConnectionListener.addConnection] is encrypted path.
50109 */
0 commit comments