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 26 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 @@ -23,23 +23,23 @@
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
Expand All @@ -59,13 +59,10 @@ 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 intent: Intent
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 +71,7 @@ class PassCodeActivityTest {

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

stopKoin()
Expand Down Expand Up @@ -130,7 +128,7 @@ class PassCodeActivityTest {

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

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

@Test
Expand Down Expand Up @@ -159,9 +157,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 @@ -199,7 +199,7 @@ class PassCodeActivityTest {
}

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

@Test
Expand All @@ -216,7 +216,7 @@ class PassCodeActivityTest {
}

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

@Test
Expand All @@ -240,7 +240,7 @@ class PassCodeActivityTest {

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

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

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

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

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

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

private fun typePasscode(digits: Array<Char>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* ownCloud Android client application
*
* @author Jesus Recio (@jesmrec)
* Copyright (C) 2020 ownCloud GmbH.
* @author Juan Carlos Garrote Gascón (@JuancaG05)
*
* Copyright (C) 2021 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
Expand All @@ -19,30 +21,56 @@

package com.owncloud.android.settings.security

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.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.platform.app.InstrumentationRegistry
import androidx.test.rule.ActivityTestRule
import com.owncloud.android.R
import com.owncloud.android.ui.activity.PatternLockActivity
import com.owncloud.android.presentation.ui.security.PatternActivity
import com.owncloud.android.presentation.viewmodels.security.PatternViewModel
import com.owncloud.android.testutil.security.OC_PATTERN
import io.mockk.mockk
import org.junit.After
import org.junit.Rule
import org.junit.Before
import org.junit.Test
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.core.context.startKoin
import org.koin.core.context.stopKoin
import org.koin.dsl.module

class PatternActivityTest {

private lateinit var activityScenario: ActivityScenario<PatternActivity>

class OCSettingsPatternLockTest {
private lateinit var intent: Intent
private lateinit var context: Context

@Rule
@JvmField
val activityRule = ActivityTestRule(PatternLockActivity::class.java, true, false)
private val intent = Intent()
private val context = InstrumentationRegistry.getInstrumentation().targetContext
private lateinit var patternViewModel: PatternViewModel

private val patternToSave = "1234"
@Before
fun setUp() {
context = ApplicationProvider.getApplicationContext()
patternViewModel = mockk(relaxUnitFun = true)

stopKoin()

startKoin {
context
modules(
module(override = true) {
viewModel {
patternViewModel
}
}
)
}
}

@After
fun tearDown() {
Expand All @@ -53,7 +81,7 @@ class OCSettingsPatternLockTest {
@Test
fun patternLockView() {
//Open Activity in pattern creation mode
openPatternActivity(PatternLockActivity.ACTION_REQUEST_WITH_RESULT)
openPatternActivity(PatternActivity.ACTION_REQUEST_WITH_RESULT)

onView(withText(R.string.pattern_configure_pattern)).check(matches(isDisplayed()))
onView(withText(R.string.pattern_configure_your_pattern_explanation)).check(matches(isDisplayed()))
Expand All @@ -67,21 +95,25 @@ class OCSettingsPatternLockTest {
storePattern()

//Open Activity in pattern deletion mode
openPatternActivity(PatternLockActivity.ACTION_CHECK_WITH_RESULT)
openPatternActivity(PatternActivity.ACTION_CHECK_WITH_RESULT)

onView(withText(R.string.pattern_remove_pattern)).check(matches(isDisplayed()))
onView(withText(R.string.pattern_no_longer_required)).check(matches(isDisplayed()))
}

private fun storePattern() {
val appPrefs = PreferenceManager.getDefaultSharedPreferences(context).edit()
appPrefs.putString(PatternLockActivity.KEY_PATTERN, patternToSave)
appPrefs.putBoolean(PatternLockActivity.PREFERENCE_SET_PATTERN, true)
appPrefs.apply()
appPrefs.apply {
putString(PatternActivity.PREFERENCE_PATTERN, OC_PATTERN)
putBoolean(PatternActivity.PREFERENCE_SET_PATTERN, true)
apply()
}
}

private fun openPatternActivity(mode: String) {
intent.action = mode
activityRule.launchActivity(intent)
intent = Intent(context, PatternActivity::class.java).apply {
action = mode
}
abelgardep marked this conversation as resolved.
Show resolved Hide resolved
activityScenario = ActivityScenario.launch(intent)
}
}
Loading