Fix power check dialog

added test

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2024-11-12 10:32:50 +01:00 committed by Alper Öztürk
parent 63756c7a14
commit d763717daa
3 changed files with 34 additions and 13 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View file

@ -7,8 +7,8 @@
*/
package com.nextcloud.client;
import android.app.Activity;
import android.content.Intent;
import android.os.Looper;
import com.nextcloud.client.preferences.SubFolderRule;
import com.owncloud.android.AbstractIT;
@ -25,6 +25,7 @@ import org.junit.Test;
import java.util.Objects;
import androidx.appcompat.app.AlertDialog;
import androidx.test.espresso.intent.rule.IntentsTestRule;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
@ -78,4 +79,24 @@ public class SyncedFoldersActivityIT extends AbstractIT {
screenshot(Objects.requireNonNull(sut.requireDialog().getWindow()).getDecorView());
}
@Test
@ScreenshotTest
public void showPowerCheckDialog() {
if (Looper.myLooper() == null) {
Looper.prepare();
}
Intent intent = new Intent(targetContext, SyncedFoldersActivity.class);
SyncedFoldersActivity activity = activityRule.launchActivity(intent);
AlertDialog sut = activity.buildPowerCheckDialog();
activity.runOnUiThread(sut::show);
getInstrumentation().waitForIdleSync();
shortSleep();
screenshot(Objects.requireNonNull(sut.getWindow()).getDecorView());
}
}

View file

@ -20,6 +20,7 @@ import android.text.TextUtils
import android.view.Menu
import android.view.MenuItem
import android.view.View
import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AlertDialog
import androidx.drawerlayout.widget.DrawerLayout
import androidx.lifecycle.Lifecycle
@ -31,7 +32,6 @@ import com.nextcloud.client.di.Injectable
import com.nextcloud.client.jobs.MediaFoldersDetectionWork
import com.nextcloud.client.jobs.NotificationWork
import com.nextcloud.client.jobs.upload.FileUploadWorker
import com.nextcloud.client.preferences.AppPreferences
import com.nextcloud.client.preferences.SubFolderRule
import com.nextcloud.utils.extensions.getParcelableArgument
import com.nextcloud.utils.extensions.isDialogFragmentReady
@ -56,7 +56,6 @@ import com.owncloud.android.ui.dialog.SyncedFolderPreferencesDialogFragment.OnSy
import com.owncloud.android.ui.dialog.parcel.SyncedFolderParcelable
import com.owncloud.android.utils.PermissionUtil
import com.owncloud.android.utils.SyncedFolderUtils
import com.owncloud.android.utils.theme.ViewThemeUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
@ -135,18 +134,12 @@ class SyncedFoldersActivity :
}
}
@Inject
lateinit var preferences: AppPreferences
@Inject
lateinit var powerManagementService: PowerManagementService
@Inject
lateinit var clock: Clock
@Inject
lateinit var viewThemeUtils: ViewThemeUtils
@Inject
lateinit var syncedFolderProvider: SyncedFolderProvider
@ -220,17 +213,23 @@ class SyncedFoldersActivity :
powerCheck.isChecked = !powerCheck.isChecked
return true
}
private fun showPowerCheckDialog() {
fun buildPowerCheckDialog(): AlertDialog {
val builder = MaterialAlertDialogBuilder(this)
.setView(R.id.root_layout)
.setPositiveButton(R.string.common_ok) { dialog, _ -> dialog.dismiss() }
.setTitle(R.string.autoupload_disable_power_save_check)
.setMessage(getString(R.string.power_save_check_dialog_message))
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(this, builder)
builder.create().show()
return builder.create()
}
@VisibleForTesting
fun showPowerCheckDialog() {
buildPowerCheckDialog().show()
}
/**
@ -636,6 +635,7 @@ class SyncedFoldersActivity :
binding.emptyList.emptyListIcon.visibility = View.VISIBLE
}
@Deprecated("Deprecated in Java")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == SyncedFolderPreferencesDialogFragment.REQUEST_CODE__SELECT_REMOTE_FOLDER &&
resultCode == RESULT_OK && dialogFragment != null