Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New arch] Pattern activity #3389

Merged
merged 27 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c58a9b8
Changed pattern classes to presentation.ui.security package
JuancaG05 Sep 20, 2021
18f76fb
Made some adaptations for PassCodeActivity to extend AppCompatActivit…
JuancaG05 Sep 20, 2021
c9eb179
Creation of PatternViewModel
JuancaG05 Sep 21, 2021
0e4b712
Kotlinization of PatternActivity
JuancaG05 Sep 21, 2021
5d67381
Removed unused imports
JuancaG05 Sep 21, 2021
c2b6241
Logic moved to the new ViewModel
JuancaG05 Sep 21, 2021
20847da
Adapted existing unit and UI tests
JuancaG05 Sep 21, 2021
d1b39fe
Removed unused imports
JuancaG05 Sep 21, 2021
7588a24
More unused imports removals
JuancaG05 Sep 21, 2021
35115d5
Added unit tests for the new ViewModel
JuancaG05 Sep 21, 2021
e1623dd
Kotlinizing PatternManager
JuancaG05 Sep 22, 2021
30e9f9a
Moved all classes to presentation.ui.security package
JuancaG05 Sep 29, 2021
68c0b07
Bumped biometric dependency from 1.0.1 to 1.1.0
JuancaG05 Sep 29, 2021
ebcc726
Kotlinized BiometricActivity
JuancaG05 Sep 30, 2021
0a66d4c
Kotlinized some more aspects in BiometricActivity
JuancaG05 Sep 30, 2021
24bf407
BiometricViewModel created
JuancaG05 Oct 4, 2021
376a08a
Unit tests created
JuancaG05 Oct 4, 2021
b50544b
Kotlinized BiometricManager
JuancaG05 Oct 5, 2021
d9635c6
Adapted invocations to BiometricManager from other classes
JuancaG05 Oct 5, 2021
dbaac15
Fixed some lint errors
JuancaG05 Oct 5, 2021
c2ab5d0
Fixed tests which use BiometricManager
JuancaG05 Oct 5, 2021
a4324cc
Fixed tests after rebase
JuancaG05 Oct 5, 2021
12baf04
Moved some logic to BiometricVM after rebase
JuancaG05 Oct 5, 2021
474d3a4
Removed unused imports
JuancaG05 Oct 5, 2021
fa44b04
Requested changes
JuancaG05 Oct 7, 2021
6aba9fc
Removed unused imports
JuancaG05 Oct 7, 2021
b8d74d3
Some improvements in tests
JuancaG05 Oct 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
appCompat = "1.2.0"
sqliteVersion = "2.1.0"
lifecycleLiveData = "2.3.1"
biometricVersion="1.0.1"
biometricVersion="1.1.0"
JuancaG05 marked this conversation as resolved.
Show resolved Hide resolved

// Kotlin
kotlinVersion = "1.5.21"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import com.owncloud.android.testutil.OC_AUTH_TOKEN_TYPE
import com.owncloud.android.testutil.OC_BASIC_PASSWORD
import com.owncloud.android.testutil.OC_BASIC_USERNAME
import com.owncloud.android.testutil.OC_SERVER_INFO
import com.owncloud.android.utils.click
import com.owncloud.android.utils.scrollAndClick
import com.owncloud.android.utils.matchers.assertVisibility
import com.owncloud.android.utils.matchers.isDisplayed
import com.owncloud.android.utils.matchers.isEnabled
Expand Down Expand Up @@ -189,7 +189,7 @@ class LoginActivityTest {

verify(exactly = 1) { ocAuthenticationViewModel.getServerInfo(OC_SERVER_INFO.baseUrl) }

R.id.centeredRefreshButton.click()
R.id.centeredRefreshButton.scrollAndClick()

verify(exactly = 2) { ocAuthenticationViewModel.getServerInfo(OC_SERVER_INFO.baseUrl) }
}
Expand Down Expand Up @@ -232,7 +232,7 @@ class LoginActivityTest {

R.id.hostUrlInput.typeText(OC_SERVER_INFO.baseUrl)

R.id.embeddedCheckServerButton.click()
R.id.embeddedCheckServerButton.scrollAndClick()

verify(exactly = 1) { ocAuthenticationViewModel.getServerInfo(OC_SERVER_INFO.baseUrl) }
}
Expand All @@ -242,7 +242,7 @@ class LoginActivityTest {
launchTest()
R.id.hostUrlInput.typeText(OC_SERVER_INFO.baseUrl)

R.id.thumbnail.click()
R.id.thumbnail.scrollAndClick()

verify(exactly = 1) { ocAuthenticationViewModel.getServerInfo(OC_SERVER_INFO.baseUrl) }
}
Expand Down Expand Up @@ -365,7 +365,7 @@ class LoginActivityTest {

R.id.hostUrlInput.typeText("")

R.id.embeddedCheckServerButton.click()
R.id.embeddedCheckServerButton.scrollAndClick()

with(R.id.server_status_text) {
isDisplayed(true)
Expand Down Expand Up @@ -427,7 +427,7 @@ class LoginActivityTest {

with(R.id.loginButton) {
isDisplayed(true)
click()
scrollAndClick()
}

verify(exactly = 1) { ocAuthenticationViewModel.loginBasic(OC_BASIC_USERNAME, OC_BASIC_PASSWORD, null) }
Expand All @@ -445,7 +445,7 @@ class LoginActivityTest {

with(R.id.loginButton) {
isDisplayed(true)
click()
scrollAndClick()
}

verify(exactly = 1) { ocAuthenticationViewModel.loginBasic(OC_BASIC_USERNAME, OC_BASIC_PASSWORD, null) }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,28 @@
package com.owncloud.android.settings.security

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.preference.PreferenceManager
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.replaceText
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.ActivityTestRule
import com.owncloud.android.R
import com.owncloud.android.presentation.ui.security.PassCodeActivity
import com.owncloud.android.utils.matchers.isDisplayed
import com.owncloud.android.utils.matchers.withText
import org.junit.After
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import com.owncloud.android.presentation.viewmodels.security.PassCodeViewModel
import com.owncloud.android.testutil.security.OC_PASSCODE_4_DIGITS
import com.owncloud.android.testutil.security.OC_PASSCODE_6_DIGITS
import com.owncloud.android.utils.click
import com.owncloud.android.utils.matchers.withChildCountAndId
import io.mockk.every
import io.mockk.mockk
import nthChildOf
Expand All @@ -55,17 +54,12 @@ import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.core.context.startKoin
import org.koin.core.context.stopKoin
import org.koin.dsl.module
import withChildViewCount

class PassCodeActivityTest {

@Rule
@JvmField
val activityRule = ActivityTestRule(PassCodeActivity::class.java, true, false)
private lateinit var activityScenario: ActivityScenario<PassCodeActivity>

private val intent = Intent()
private val errorMessage = "PassCode Activity error"
private val context = InstrumentationRegistry.getInstrumentation().targetContext
private lateinit var context: Context

private val defaultPassCode = arrayOf('1', '1', '1', '1', '1', '1')
private val wrongPassCode = arrayOf('1', '1', '1', '2', '2', '2')
Expand All @@ -74,6 +68,7 @@ class PassCodeActivityTest {

@Before
fun setUp() {
context = ApplicationProvider.getApplicationContext()
passCodeViewModel = mockk(relaxUnitFun = true)

stopKoin()
Expand Down Expand Up @@ -114,8 +109,10 @@ class PassCodeActivityTest {
}

// Check if required amount of input fields are actually displayed
onView(withId(R.id.passCodeTxtLayout)).check(matches(isDisplayed()))
onView(withId(R.id.passCodeTxtLayout)).check(matches(withChildViewCount(passCodeViewModel.getNumberOfPassCodeDigits(), withId(R.id.passCodeEditText))))
with(R.id.passCodeTxtLayout) {
isDisplayed(true)
withChildCountAndId(passCodeViewModel.getNumberOfPassCodeDigits(), R.id.passCodeEditText)
}

with(R.id.cancel) {
isDisplayed(true)
Expand All @@ -128,9 +125,9 @@ class PassCodeActivityTest {
//Open Activity in passcode creation mode
openPasscodeActivity(PassCodeActivity.ACTION_REQUEST_WITH_RESULT)

onView(withId(R.id.cancel)).perform(click())
R.id.cancel.click()

assertEquals(activityRule.activityResult.resultCode, Activity.RESULT_CANCELED)
assertEquals(activityScenario.result.resultCode, Activity.RESULT_CANCELED)
}

@Test
Expand Down Expand Up @@ -159,9 +156,11 @@ class PassCodeActivityTest {
typePasscode(defaultPassCode)

//Checking that the result returned is OK
assertEquals(activityRule.activityResult.resultCode, Activity.RESULT_OK)
assertEquals(activityScenario.result.resultCode, Activity.RESULT_OK)

assertTrue(errorMessage, activityRule.activity.isFinishing)
activityScenario.onActivity {
assertTrue(it.isFinishing)
}
}

@Test
Expand Down Expand Up @@ -198,8 +197,8 @@ class PassCodeActivityTest {
onView(nthChildOf(withId(R.id.passCodeTxtLayout), i)).perform(replaceText("1"))
}

onView(withId(R.id.cancel)).perform(click())
assertTrue(errorMessage, activityRule.activity.isFinishing)
R.id.cancel.click()
assertEquals(activityScenario.result.resultCode, Activity.RESULT_CANCELED)
}

@Test
Expand All @@ -210,13 +209,13 @@ class PassCodeActivityTest {
//First typing
typePasscode(defaultPassCode)

//Type incorrect passcode
//Type incomplete passcode
for (i in 0..1) {
onView(nthChildOf(withId(R.id.passCodeTxtLayout), i)).perform(replaceText("1"))
}

onView(withId(R.id.cancel)).perform(click())
assertTrue(errorMessage, activityRule.activity.isFinishing)
R.id.cancel.click()
assertEquals(activityScenario.result.resultCode, Activity.RESULT_CANCELED)
}

@Test
Expand All @@ -238,9 +237,8 @@ class PassCodeActivityTest {
//Open Activity in passcode deletion mode
openPasscodeActivity(PassCodeActivity.ACTION_CHECK_WITH_RESULT)

onView(withId(R.id.cancel)).perform(click())

assertEquals(activityRule.activityResult.resultCode, Activity.RESULT_CANCELED)
R.id.cancel.click()
assertEquals(activityScenario.result.resultCode, Activity.RESULT_CANCELED)
}

@Test
Expand All @@ -256,7 +254,9 @@ class PassCodeActivityTest {
//Type correct passcode
typePasscode(defaultPassCode)

assertTrue(errorMessage, activityRule.activity.isFinishing)
activityScenario.onActivity {
assertTrue(it.isFinishing)
}
}

@Test
Expand All @@ -283,8 +283,10 @@ class PassCodeActivityTest {
}

private fun openPasscodeActivity(mode: String) {
intent.action = mode
activityRule.launchActivity(intent)
val intent = Intent(context, PassCodeActivity::class.java).apply {
action = mode
}
activityScenario = ActivityScenario.launch(intent)
}

private fun typePasscode(digits: Array<Char>) {
Expand Down
Loading