Skip to content

Commit

Permalink
update unit tests after rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
cmonfortep committed Jan 30, 2025
1 parent 2e86760 commit 650b8d6
Showing 1 changed file with 66 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.duckduckgo.autofill.api.domain.app.LoginCredentials
import com.duckduckgo.autofill.api.store.AutofillStore
import com.duckduckgo.autofill.impl.service.AutofillFieldType.PASSWORD
import com.duckduckgo.autofill.impl.service.AutofillFieldType.USERNAME
import com.duckduckgo.autofill.impl.service.mapper.AppCredentialProvider
import com.duckduckgo.common.test.CoroutineTestRule
import kotlinx.coroutines.test.runTest
import org.junit.Rule
Expand All @@ -48,6 +49,7 @@ class RealAutofillProviderSuggestionsTest {
}

private val autofillStore = mock<AutofillStore>()
private val appCredentialProvider = mock<AppCredentialProvider>()

private val mockViewProvider = mock<AutofillServiceViewProvider>()

Expand All @@ -61,6 +63,7 @@ class RealAutofillProviderSuggestionsTest {
autofillStore = autofillStore,
viewProvider = mockViewProvider,
suggestionsFormatter = suggestionFormatter,
appCredentialProvider = appCredentialProvider,
)

@Test
Expand All @@ -76,8 +79,8 @@ class RealAutofillProviderSuggestionsTest {
testee.buildSuggestionsResponse(
context = context,
AutofillRootNode(
"com.example.app",
null,
"example.com",
listOf(
ParsedAutofillField(autofillId(), "", "", "", USERNAME, viewNode()),
),
Expand All @@ -101,8 +104,8 @@ class RealAutofillProviderSuggestionsTest {
testee.buildSuggestionsResponse(
context = context,
AutofillRootNode(
"com.example.app",
null,
"example.com",
listOf(
ParsedAutofillField(autofillId(), "", "", "", USERNAME, viewNode()),
),
Expand Down Expand Up @@ -131,8 +134,8 @@ class RealAutofillProviderSuggestionsTest {
testee.buildSuggestionsResponse(
context = context,
AutofillRootNode(
"com.example.app",
null,
"example.com",
listOf(
ParsedAutofillField(autofillId(), "", "", "", USERNAME, viewNode()),
),
Expand Down Expand Up @@ -161,8 +164,8 @@ class RealAutofillProviderSuggestionsTest {
testee.buildSuggestionsResponse(
context = context,
AutofillRootNode(
"com.example.app",
null,
"example.com",
listOf(
ParsedAutofillField(autofillId(), "", "", "", USERNAME, viewNode()),
),
Expand Down Expand Up @@ -190,8 +193,35 @@ class RealAutofillProviderSuggestionsTest {
testee.buildSuggestionsResponse(
context = context,
AutofillRootNode(
"com.example.app",
null,
"example.com",
listOf(
ParsedAutofillField(autofillId(), "", "", "", USERNAME, viewNode()),
),
),
mock(),
)

verify(mockViewProvider, times(3)).createFormPresentation(any(), any(), any(), any())
}

@Test
fun whenCredentialsForPackageAndDomainFoundThenAddBothTypeSuggestions() = runTest {
val credentialsDomain = listOf(
LoginCredentials(1L, "username", "password", "example.com"),
)
val credentialsPackage = listOf(
LoginCredentials(2L, "username2", "password2", "example2.com"),
)
whenever(autofillStore.getCredentials(any())).thenReturn(credentialsDomain)
whenever(appCredentialProvider.getCredentials(any())).thenReturn(credentialsPackage)
whenever(mockViewProvider.createFormPresentation(any(), any(), any(), any())).thenReturn(mock())

testee.buildSuggestionsResponse(
context = context,
AutofillRootNode(
"com.example.app",
"example.com",
listOf(
ParsedAutofillField(autofillId(), "", "", "", USERNAME, viewNode()),
),
Expand All @@ -202,6 +232,33 @@ class RealAutofillProviderSuggestionsTest {
verify(mockViewProvider, times(3)).createFormPresentation(any(), any(), any(), any())
}

@Test
fun whenCredentialsForPackageAndDomainAreSameThenDedupSuggestions() = runTest {
val credentialsDomain = listOf(
LoginCredentials(1L, "username", "password", "example.com"),
)
val credentialsPackage = listOf(
LoginCredentials(1L, "username", "password", "example.com"),
)
whenever(autofillStore.getCredentials(any())).thenReturn(credentialsDomain)
whenever(appCredentialProvider.getCredentials(any())).thenReturn(credentialsPackage)
whenever(mockViewProvider.createFormPresentation(any(), any(), any(), any())).thenReturn(mock())

testee.buildSuggestionsResponse(
context = context,
AutofillRootNode(
"com.example.app",
"example.com",
listOf(
ParsedAutofillField(autofillId(), "", "", "", USERNAME, viewNode()),
),
),
mock(),
)

verify(mockViewProvider, times(2)).createFormPresentation(any(), any(), any(), any())
}

@Test
fun whenNoCredentialsFoundThenOnlyOpenDDGAppItemIsAdded() = runTest {
whenever(autofillStore.getCredentials(any())).thenReturn(emptyList())
Expand All @@ -210,8 +267,8 @@ class RealAutofillProviderSuggestionsTest {
testee.buildSuggestionsResponse(
context = context,
AutofillRootNode(
"com.example.app",
null,
"example.com",
listOf(
ParsedAutofillField(autofillId(), "", "", "", USERNAME, viewNode()),
),
Expand All @@ -233,8 +290,8 @@ class RealAutofillProviderSuggestionsTest {
testee.buildSuggestionsResponse(
context = context,
AutofillRootNode(
"com.example.app",
null,
"example.com",
listOf(
ParsedAutofillField(autofillId(), "", "", "", USERNAME, viewNode()),
ParsedAutofillField(autofillId(), "", "", "", PASSWORD, viewNode()),
Expand All @@ -259,8 +316,8 @@ class RealAutofillProviderSuggestionsTest {
testee.buildSuggestionsResponse(
context = context,
AutofillRootNode(
"com.example.app",
null,
"example.com",
listOf(
ParsedAutofillField(autofillId(), "", "", "", USERNAME, viewNode()),
ParsedAutofillField(autofillId(), "", "", "", PASSWORD, viewNode()),
Expand All @@ -287,8 +344,8 @@ class RealAutofillProviderSuggestionsTest {
testee.buildSuggestionsResponse(
context = context,
AutofillRootNode(
"com.example.app",
null,
"example.com",
listOf(
ParsedAutofillField(autofillId(), "", "", "", USERNAME, viewNode()),
ParsedAutofillField(autofillId(), "", "", "", PASSWORD, viewNode()),
Expand Down

0 comments on commit 650b8d6

Please sign in to comment.