Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
No issue - Format PromptRequestTest.kt
Browse files Browse the repository at this point in the history
This formats `PromptRequestTest.kt` by breaking up the one single test into their individual `PromptRequest`.
  • Loading branch information
gabrielluong authored and mergify[bot] committed Apr 27, 2021
1 parent e068d4d commit dec1bf4
Showing 1 changed file with 90 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@
package mozilla.components.concept.engine.prompt

import mozilla.components.concept.engine.prompt.PromptRequest.Alert
import mozilla.components.concept.engine.prompt.PromptRequest.Authentication
import mozilla.components.concept.engine.prompt.PromptRequest.Color
import mozilla.components.concept.engine.prompt.PromptRequest.Confirm
import mozilla.components.concept.engine.prompt.PromptRequest.File
import mozilla.components.concept.engine.prompt.PromptRequest.MenuChoice
import mozilla.components.concept.engine.prompt.PromptRequest.MultipleChoice
import mozilla.components.concept.engine.prompt.PromptRequest.Popup
import mozilla.components.concept.engine.prompt.PromptRequest.Repost
import mozilla.components.concept.engine.prompt.PromptRequest.SaveLoginPrompt
import mozilla.components.concept.engine.prompt.PromptRequest.SelectLoginPrompt
import mozilla.components.concept.engine.prompt.PromptRequest.SingleChoice
import mozilla.components.concept.engine.prompt.PromptRequest.TextPrompt
import mozilla.components.concept.engine.prompt.PromptRequest.TimeSelection
import mozilla.components.concept.engine.prompt.PromptRequest.TimeSelection.Type
import mozilla.components.concept.storage.Login
import mozilla.components.support.test.mock
Expand All @@ -21,34 +31,48 @@ import java.util.Date
class PromptRequestTest {

@Test
fun `Create prompt requests`() {

fun `SingleChoice`() {
val single = SingleChoice(emptyArray()) {}
single.onConfirm(Choice(id = "", label = ""))
assertNotNull(single.choices)
}

@Test
fun `MultipleChoice`() {
val multiple = MultipleChoice(emptyArray()) {}
multiple.onConfirm(arrayOf(Choice(id = "", label = "")))
assertNotNull(multiple.choices)
}

@Test
fun `MenuChoice`() {
val menu = MenuChoice(emptyArray()) {}
menu.onConfirm(Choice(id = "", label = ""))
assertNotNull(menu.choices)
}

@Test
fun `Alert`() {
val alert = Alert("title", "message", true, {}) {}

assertEquals(alert.title, "title")
assertEquals(alert.message, "message")
assertEquals(alert.hasShownManyDialogs, true)

alert.onDismiss()
alert.onConfirm(true)

assertEquals(alert.title, "title")
assertEquals(alert.message, "message")
assertEquals(alert.hasShownManyDialogs, true)

alert.onDismiss()
alert.onConfirm(true)
}

val textPrompt = PromptRequest.TextPrompt(
@Test
fun `TextPrompt`() {
val textPrompt = TextPrompt(
"title",
"label",
"value",
Expand All @@ -59,39 +83,53 @@ class PromptRequestTest {
assertEquals(textPrompt.inputLabel, "label")
assertEquals(textPrompt.inputValue, "value")
assertEquals(textPrompt.hasShownManyDialogs, true)

textPrompt.onDismiss()
textPrompt.onConfirm(true, "")
}

val dateRequest = PromptRequest.TimeSelection(
@Test
fun `TimeSelection`() {
val dateRequest = TimeSelection(
"title",
Date(),
Date(),
Date(),
Type.DATE,
{}) {}

assertEquals(dateRequest.title, "title")
assertEquals(dateRequest.type, Type.DATE)
assertNotNull(dateRequest.initialDate)
assertNotNull(dateRequest.minimumDate)
assertNotNull(dateRequest.maximumDate)

dateRequest.onConfirm(Date())
dateRequest.onClear()
}

val filePickerRequest = PromptRequest.File(
@Test
fun `File`() {
val filePickerRequest = File(
emptyArray(),
true,
PromptRequest.File.FacingMode.NONE,
{ _, _ -> },
{ _, _ -> }
) {}

assertTrue(filePickerRequest.mimeTypes.isEmpty())
assertTrue(filePickerRequest.isMultipleFilesSelection)
assertEquals(filePickerRequest.captureMode, PromptRequest.File.FacingMode.NONE)

filePickerRequest.onSingleFileSelected(mock(), mock())
filePickerRequest.onMultipleFilesSelected(mock(), emptyArray())
filePickerRequest.onDismiss()
}

val promptRequest = PromptRequest.Authentication(
@Test
fun `Authentication`() {
val promptRequest = Authentication(
"title",
"message",
"username",
Expand All @@ -111,36 +149,41 @@ class PromptRequestTest {
assertFalse(promptRequest.onlyShowPassword)
assertFalse(promptRequest.previousFailed)
assertFalse(promptRequest.isCrossOrigin)

promptRequest.onConfirm("", "")
promptRequest.onDismiss()
}

val onConfirm: (String) -> Unit = {
}
val onDismiss: () -> Unit = {
}
@Test
fun `Color`() {
val onConfirm: (String) -> Unit = {}
val onDismiss: () -> Unit = {}

val colorRequest = Color("defaultColor", onConfirm, onDismiss)

val colorRequest = PromptRequest.Color("defaultColor", onConfirm, onDismiss)
assertEquals(colorRequest.defaultColor, "defaultColor")

colorRequest.onConfirm("")
colorRequest.onDismiss()
}

val popupRequest = PromptRequest.Popup("http://mozilla.slack.com/", {}, {})
@Test
fun `Popup`() {
val popupRequest = Popup("http://mozilla.slack.com/", {}, {})

assertEquals(popupRequest.targetUri, "http://mozilla.slack.com/")

popupRequest.onAllow()
popupRequest.onDeny()
}

val onConfirmPositiveButton: (Boolean) -> Unit = {
}

val onConfirmNegativeButton: (Boolean) -> Unit = {
}

val onConfirmNeutralButton: (Boolean) -> Unit = {
}
@Test
fun `Confirm`() {
val onConfirmPositiveButton: (Boolean) -> Unit = {}
val onConfirmNegativeButton: (Boolean) -> Unit = {}
val onConfirmNeutralButton: (Boolean) -> Unit = {}

val confirmRequest = PromptRequest.Confirm(
val confirmRequest = Confirm(
"title",
"message",
false,
Expand All @@ -157,41 +200,60 @@ class PromptRequestTest {
assertEquals(confirmRequest.positiveButtonTitle, "positive")
assertEquals(confirmRequest.negativeButtonTitle, "negative")
assertEquals(confirmRequest.neutralButtonTitle, "neutral")

confirmRequest.onConfirmPositiveButton(true)
confirmRequest.onConfirmNegativeButton(true)
confirmRequest.onConfirmNeutralButton(true)
}

@Test
fun `SaveLoginPrompt`() {
val onLoginDismiss: () -> Unit = {}
val onLoginConfirm: (Login) -> Unit = {}

val login = Login(null, "origin", username = "username", password = "password")
val loginSaveRequest =
PromptRequest.SaveLoginPrompt(0, listOf(login), onLoginDismiss, onLoginConfirm)

val loginSaveRequest = SaveLoginPrompt(0, listOf(login), onLoginDismiss, onLoginConfirm)

assertEquals(loginSaveRequest.logins, listOf(login))
assertEquals(loginSaveRequest.hint, 0)

loginSaveRequest.onConfirm(login)
loginSaveRequest.onDismiss()
}

@Test
fun `SelectLoginPrompt`() {
val onLoginDismiss: () -> Unit = {}
val onLoginConfirm: (Login) -> Unit = {}
val login = Login(null, "origin", username = "username", password = "password")

val loginSelectRequest =
PromptRequest.SelectLoginPrompt(listOf(login), onLoginDismiss, onLoginConfirm)
SelectLoginPrompt(listOf(login), onLoginDismiss, onLoginConfirm)

assertEquals(loginSelectRequest.logins, listOf(login))

loginSelectRequest.onConfirm(login)
loginSelectRequest.onDismiss()
}

// Now testing that a Repost PromptRequest can be successfully instantiated
@Test
fun `Repost`() {
var onAcceptWasCalled = false
var onDismissWasCalled = false
val repostRequest = PromptRequest.Repost(

val repostRequest = Repost(
onConfirm = {
onAcceptWasCalled = true
},
onDismiss = {
onDismissWasCalled = true
}
)

repostRequest.onConfirm()
assertTrue(onAcceptWasCalled)
repostRequest.onDismiss()

assertTrue(onAcceptWasCalled)
assertTrue(onDismissWasCalled)
}
}

0 comments on commit dec1bf4

Please sign in to comment.