Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
Revert "Revert delete PRs (#836)" (#842)
Browse files Browse the repository at this point in the history
This reverts commit 974a585.
  • Loading branch information
Elise Richards authored Jul 30, 2019
1 parent 65279d8 commit 19ddc12
Show file tree
Hide file tree
Showing 35 changed files with 546 additions and 79 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package mozilla.lockbox.robots

import br.com.concretesolutions.kappuccino.actions.ClickActions
import br.com.concretesolutions.kappuccino.assertions.VisibilityAssertions
import mozilla.lockbox.R

// DeleteCredentialDisclaimer
class DeleteCredentialDisclaimerRobot : BaseTestRobot {

override fun exists() = VisibilityAssertions.displayed { id(R.id.alertTitle) }

fun tapCancelButton() = ClickActions.click { text(R.string.cancel) }
fun tapDeleteButton() = ClickActions.click { text("DELETE") }
}

fun deleteCredentialDisclaimer(f: DeleteCredentialDisclaimerRobot.() -> Unit) = DeleteCredentialDisclaimerRobot().apply(f)
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class ItemDetailRobot : BaseTestRobot {
fun toastIsDisplayed(id: Int, activityRule: ActivityTestRule<RootActivity>) =
onView(withText(id)).inRoot(withDecorView(not(`is`(activityRule.activity.getWindow().decorView))))
.check(matches(isDisplayed()))

fun tapKebabMenu() = ClickActions.click { id(R.id.kebabMenu) }
}

fun itemDetail(f: ItemDetailRobot.() -> Unit) = ItemDetailRobot().apply(f)
21 changes: 21 additions & 0 deletions app/src/androidTest/java/mozilla/lockbox/robots/KebabMenuRobot.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package mozilla.lockbox.robots

import br.com.concretesolutions.kappuccino.actions.ClickActions
import br.com.concretesolutions.kappuccino.assertions.VisibilityAssertions
import mozilla.lockbox.R

// KebabMenu
class KebabMenuRobot : BaseTestRobot {
override fun exists() = VisibilityAssertions.displayed { text("Delete") }

fun tapEditButton() = ClickActions.click { text(R.string.edit) }
fun tapDeleteButton() = ClickActions.click { text(R.string.delete) }
}

fun kebabMenu(f: KebabMenuRobot.() -> Unit) = KebabMenuRobot().apply(f)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.rule.ActivityTestRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.espresso.Espresso.pressBack
Expand Down Expand Up @@ -76,6 +77,19 @@ open class ScreenshotsTest {
.check(matches(isDisplayed()))
Screengrab.screenshot("item-detail-screen")

onView(withId(R.id.kebabMenu)).perform(click())
Screengrab.screenshot("item-menu")

onView(withText(R.string.delete)).perform(click())
Screengrab.screenshot("item-delete-disclaimer")

onView(withText(R.string.cancel)).perform(click())
/* Edit Menu Not developed yet
onView(withId(R.id.kebabMenu)).perform(click())
onView(withText(R.string.edit)).perform(click())
Screengrab.screenshot("item-edit-menu")
*/

onView(withId(R.id.inputUsername)).perform(click())
Screengrab.screenshot("username-copied-screen")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import mozilla.lockbox.R
import mozilla.lockbox.robots.itemDetail
import mozilla.lockbox.robots.itemList
import mozilla.lockbox.robots.kebabMenu
import mozilla.lockbox.robots.deleteCredentialDisclaimer
import mozilla.lockbox.view.RootActivity
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -40,4 +42,22 @@ open class ItemDetailsTest {
itemDetail { tapCopyPass() }
itemDetail { toastIsDisplayed(R.string.toast_password_copied, activityRule) }
}

@Test
fun deleteItem() {
navigator.gotoItemDetailKebabMenu()
kebabMenu { tapDeleteButton() }
// First tap on Cancel delete credencial
deleteCredentialDisclaimer { tapCancelButton() }
itemDetail { exists() }
// Now delete the credential
// Disabled until issue #807 is fixed
// and logins can be added after removal
/*
itemDetail { tapKebabMenu() }
kebabMenu { tapDeleteButton() }
deleteCredentialDisclaimer { tapDeleteButton() }
itemList { exists() }
*/
}
}
8 changes: 8 additions & 0 deletions app/src/androidTest/java/mozilla/lockbox/uiTests/Navigator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import mozilla.lockbox.robots.fingerprintOnboardingScreen
import mozilla.lockbox.robots.fxaLogin
import mozilla.lockbox.robots.itemDetail
import mozilla.lockbox.robots.itemList
import mozilla.lockbox.robots.kebabMenu
import mozilla.lockbox.robots.lockScreen
import mozilla.lockbox.robots.onboardingConfirmationScreen
import mozilla.lockbox.robots.securityDisclaimer
Expand Down Expand Up @@ -292,6 +293,13 @@ class Navigator {
itemDetail { exists() }
}

fun gotoItemDetailKebabMenu(position: Int = 0) {
gotoItemList()
gotoItemDetail_from_itemList(position)
itemDetail { tapKebabMenu() }
kebabMenu { exists() }
}

fun back(remainInApplication: Boolean = true) {
closeSoftKeyboard()
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

package mozilla.lockbox.action

import mozilla.components.service.sync.logins.ServerPassword
import mozilla.appservices.logins.ServerPassword
import mozilla.lockbox.model.SyncCredentials

sealed class DataStoreAction(
Expand Down
44 changes: 32 additions & 12 deletions app/src/main/java/mozilla/lockbox/action/DialogAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package mozilla.lockbox.action

import mozilla.appservices.logins.ServerPassword
import mozilla.lockbox.R
import mozilla.lockbox.flux.Action
import mozilla.lockbox.model.DialogViewModel
Expand All @@ -15,15 +16,17 @@ sealed class DialogAction(
val positiveButtonActionList: List<Action> = emptyList(),
val negativeButtonActionList: List<Action> = emptyList()
) : RouteAction(TelemetryEventMethod.show, TelemetryEventObject.dialog) {

object SecurityDisclaimer : DialogAction(
DialogViewModel(
R.string.no_device_security_title,
R.string.no_device_security_message,
R.string.set_up_security_button,
R.string.cancel
),
listOf(RouteAction.SystemSetting(SettingIntent.Security))
listOf(SystemSetting(SettingIntent.Security))
)

object UnlinkDisclaimer : DialogAction(
DialogViewModel(
R.string.disconnect_disclaimer_title,
Expand All @@ -34,17 +37,34 @@ sealed class DialogAction(
),
listOf(LifecycleAction.UserReset)
)

object OnboardingSecurityDialog : DialogAction(
DialogViewModel(
R.string.secure_your_device,
R.string.device_security_description,
R.string.set_up_now,
R.string.skip_button
),
listOf(
RouteAction.SystemSetting(SettingIntent.Security),
RouteAction.Login
),
listOf(RouteAction.Login)
DialogViewModel(
R.string.secure_your_device,
R.string.device_security_description,
R.string.set_up_now,
R.string.skip_button
),
listOf(
SystemSetting(SettingIntent.Security),
Login
),
listOf(Login)
)

data class DeleteConfirmationDialog(
val item: ServerPassword?
) : DialogAction(
DialogViewModel(
R.string.delete_this_login,
R.string.delete_description,
R.string.delete,
R.string.cancel,
R.color.red
),
listOf(
DataStoreAction.Delete(item),
ItemList
)
)
}
8 changes: 8 additions & 0 deletions app/src/main/java/mozilla/lockbox/action/ItemDetailAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@

package mozilla.lockbox.action

import androidx.annotation.StringRes
import mozilla.lockbox.R

sealed class ItemDetailAction(
override val eventMethod: TelemetryEventMethod,
override val eventObject: TelemetryEventObject
) : TelemetryAction {
data class TogglePassword(val displayed: Boolean)
: ItemDetailAction(TelemetryEventMethod.tap, TelemetryEventObject.reveal_password)

enum class EditItemMenu(@StringRes val titleId: Int) {
EDIT(R.string.edit),
DELETE(R.string.delete)
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/mozilla/lockbox/action/SettingAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Setting {
val ms: Long = this.seconds * 1000
}

enum class ItemListSort(val titleId: Int, val valueId: Int) {
enum class ItemListSort(@StringRes val titleId: Int, @StringRes val valueId: Int) {
ALPHABETICALLY(R.string.all_logins_a_z, R.string.sort_menu_az),
RECENTLY_USED(R.string.all_logins_recent, R.string.sort_menu_recent)
}
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/java/mozilla/lockbox/action/TelemetryAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface TelemetryAction : Action {
val extras: Map<String, Any>?
get() = null

open fun createEvent(category: String = "action"): TelemetryEvent {
fun createEvent(category: String = "action"): TelemetryEvent {
val evt = TelemetryEvent.create(
category,
eventMethod.name,
Expand All @@ -37,8 +37,6 @@ enum class TelemetryEventMethod {
background,
setting_changed,
show,
delete,
edit,
canceled,
login_selected,
autofill_locked,
Expand All @@ -60,7 +58,9 @@ enum class TelemetryEventMethod {
autofill_multiple,
autofill_cancel,
autofill_error,
autofill_filter
autofill_filter,
delete,
edit
}

enum class TelemetryEventObject {
Expand Down Expand Up @@ -102,5 +102,6 @@ enum class TelemetryEventObject {
dialog,
datastore,
delete_credential,
edit_credential
edit_credential,
entry_kebab
}
45 changes: 45 additions & 0 deletions app/src/main/java/mozilla/lockbox/adapter/DeleteItemAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package mozilla.lockbox.adapter

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.TextView
import mozilla.lockbox.R
import mozilla.lockbox.action.ItemDetailAction

class DeleteItemAdapter(
context: Context,
textViewResourceId: Int,
val values: ArrayList<ItemDetailAction.EditItemMenu>
) : ArrayAdapter<ItemDetailAction.EditItemMenu>(context, textViewResourceId, values) {

private var selectedIndex = -1

fun setSelection(position: Int) {
selectedIndex = position
notifyDataSetChanged()
}

override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val label = super.getView(position, convertView, parent) as TextView
label.setTextAppearance(R.style.TextAppearanceWidgetEventToolbarTitle)
label.setTextColor(label.resources.getColor(R.color.text_white, null))
label.setBackgroundColor(label.resources.getColor(R.color.color_primary, null))
label.text = context.resources.getString(values[position].titleId)
label.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_menu_kebab, 0)

return label
}

override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View {
val label = super.getDropDownView(position, convertView, parent) as TextView
label.setTextAppearance(R.style.TextAppearanceSortMenuItem)
label.text = context.resources.getString(values[position].titleId)
label.background = context.resources.getDrawable(R.drawable.button_pressed_white, null)
val padding = label.resources.getDimensionPixelSize(R.dimen.sort_item_padding)
label.setPadding(padding, padding, padding, padding)

return label
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class SectionedAdapter(
else
baseAdapter.getItemViewType(sectionedPositionToPosition(position)) + 1
}

class Section(internal var firstPosition: Int, @StringRes title: Int) {
internal var sectionedPosition: Int = 0
@StringRes var title: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.annotation.StringRes
import androidx.appcompat.app.AlertDialog
import io.reactivex.Observable
import io.reactivex.ObservableEmitter
import kotlinx.android.synthetic.main.list_cell_setting_toggle.*
import mozilla.lockbox.R
import mozilla.lockbox.model.DialogViewModel

Expand All @@ -25,7 +26,7 @@ object AlertDialogHelper {
viewModel: DialogViewModel
): Observable<AlertState> {
return Observable.create { emitter ->
val builder = AlertDialog.Builder(context, R.style.AlertDialogStyle)
val builder = AlertDialog.Builder(context, R.style.DeleteDialogStyle)

viewModel.title?.let {
val titleString = context.getString(it)
Expand Down Expand Up @@ -62,7 +63,6 @@ object AlertDialogHelper {
setUpDismissal(builder, emitter)

val dialog = builder.create()

dialog.show()

val defaultColor = context.getColor(R.color.violet_70)
Expand Down
Loading

0 comments on commit 19ddc12

Please sign in to comment.