Skip to content

Commit

Permalink
Merge pull request #291 from aivanovski/feature/optimizations-for-ui-…
Browse files Browse the repository at this point in the history
…tests

Improvements for UI tests
  • Loading branch information
aivanovski authored Jan 13, 2025
2 parents 1ec7548 + 20a22ec commit 356d7ea
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import android.util.Base64
import com.github.aivanovski.keepasstreebuilder.DatabaseBuilderDsl
import com.github.aivanovski.keepasstreebuilder.Fields
import com.github.aivanovski.keepasstreebuilder.converter.kotpass.KotpassDatabaseConverter
import com.github.aivanovski.keepasstreebuilder.extensions.toByteArray
import com.github.aivanovski.keepasstreebuilder.generator.EntityFactory.newBinaryFrom
import com.github.aivanovski.keepasstreebuilder.model.Binary
import com.github.aivanovski.keepasstreebuilder.model.Database
import com.github.aivanovski.keepasstreebuilder.model.DatabaseKey
import com.github.aivanovski.keepasstreebuilder.model.EntryEntity
import com.github.aivanovski.keepasstreebuilder.model.GroupEntity
Expand Down Expand Up @@ -202,6 +202,22 @@ object FakeDatabaseContentFactory {
.toByteArray()
}

fun createAutomationDatabase(key: DatabaseKey): ByteArray {
return DatabaseBuilderDsl.newBuilder(KotpassDatabaseConverter())
.key(key)
.content(ROOT) {
entry(ENTRY_BASIC)
}
.build()
.toByteArray()
}

private fun Database<*, *>.toByteArray(): ByteArray {
return contentFactory.invoke().use { input ->
input.readBytes()
}
}

private fun newEntry(
created: Long,
modified: Long,
Expand Down Expand Up @@ -310,9 +326,9 @@ object FakeDatabaseContentFactory {
private const val DEFAULT_PASSWORD = "abc123"
private const val DEFAULT_KEY_FILE_CONTENT = "abcdefg1235678"

private val PASSWORD_KEY = DatabaseKey.PasswordKey(DEFAULT_PASSWORD)
private val FILE_KEY = DatabaseKey.BinaryKey(DEFAULT_KEY_FILE_CONTENT.toByteArray())
private val COMBINED_KEY = DatabaseKey.CompositeKey(
val PASSWORD_KEY = DatabaseKey.PasswordKey(DEFAULT_PASSWORD)
val FILE_KEY = DatabaseKey.BinaryKey(DEFAULT_KEY_FILE_CONTENT.toByteArray())
val COMBINED_KEY = DatabaseKey.CompositeKey(
password = DEFAULT_PASSWORD,
binaryData = DEFAULT_KEY_FILE_CONTENT.toByteArray()
)
Expand Down Expand Up @@ -598,4 +614,13 @@ object FakeDatabaseContentFactory {
modified = parseDate("2020-01-03").toInstant()
)
)

private val ENTRY_BASIC = newEntry(
title = "Basic entry",
username = "[email protected]",
password = "abc123",
url = "https://url.com",
created = parseDate("2020-01-01"),
modified = parseDate("2020-01-10")
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package com.ivanovsky.passnotes.data.repository.file.fake
import com.ivanovsky.passnotes.data.entity.FSAuthority
import com.ivanovsky.passnotes.data.entity.FileDescriptor
import com.ivanovsky.passnotes.data.entity.SyncStatus
import com.ivanovsky.passnotes.data.repository.file.fake.FakeDatabaseContentFactory.COMBINED_KEY
import com.ivanovsky.passnotes.data.repository.file.fake.FakeDatabaseContentFactory.FILE_KEY
import com.ivanovsky.passnotes.data.repository.file.fake.FakeDatabaseContentFactory.PASSWORD_KEY
import com.ivanovsky.passnotes.data.repository.file.fake.FakeDatabaseContentFactory.createAutomationDatabase
import com.ivanovsky.passnotes.data.repository.file.fake.FakeDatabaseContentFactory.createDatabaseWithAttachmentsData
import com.ivanovsky.passnotes.data.repository.file.fake.FakeDatabaseContentFactory.createDatabaseWithCombinedKey
import com.ivanovsky.passnotes.data.repository.file.fake.FakeDatabaseContentFactory.createDatabaseWithExpiredData
Expand All @@ -24,6 +28,7 @@ class FakeFileFactory(
return listOf(
// directories
newEntry(newDirectory("/", Time.ROOT)),
newEntry(newDirectory("/automation", Time.ROOT)),
newEntry(newDirectory("/conflicts", Time.ROOT)),
newEntry(newDirectory("/errors", Time.ROOT)),
newEntry(newDirectory("/examples", Time.ROOT)),
Expand Down Expand Up @@ -169,6 +174,26 @@ class FakeFileFactory(
syncStatus = SyncStatus.NO_CHANGES,
localContentFactory = { createDiffModifiedDatabase() },
remoteContentFactory = { createDiffModifiedDatabase() }
),

// automation
newEntry(
localFile = newFile(Path.AUTOMATION_PASSWORD_UNLOCK, Time.LOCAL),
syncStatus = SyncStatus.NO_CHANGES,
localContentFactory = { createAutomationDatabase(PASSWORD_KEY) },
remoteContentFactory = { createAutomationDatabase(PASSWORD_KEY) }
),
newEntry(
localFile = newFile(Path.AUTOMATION_KEY_FILE_UNLOCK, Time.LOCAL),
syncStatus = SyncStatus.NO_CHANGES,
localContentFactory = { createAutomationDatabase(FILE_KEY) },
remoteContentFactory = { createAutomationDatabase(FILE_KEY) }
),
newEntry(
localFile = newFile(Path.AUTOMATION_COMBINE_UNLOCK, Time.LOCAL),
syncStatus = SyncStatus.NO_CHANGES,
localContentFactory = { createAutomationDatabase(COMBINED_KEY) },
remoteContentFactory = { createAutomationDatabase(COMBINED_KEY) }
)
)
}
Expand Down Expand Up @@ -265,6 +290,11 @@ class FakeFileFactory(
// diff
val DETAILED_DIFF = "/examples/detailed-diff.kdbx"
val DETAILED_DIFF_MODIFIED = "/examples/detailed-diff-modified.kdbx"

// automation
val AUTOMATION_PASSWORD_UNLOCK = "/automation/basic.kdbx"
val AUTOMATION_KEY_FILE_UNLOCK = "/automation/basic-key-file.kdbx"
val AUTOMATION_COMBINE_UNLOCK = "/automation/basic-key-file-and-password.kdbx"
}

private object Time {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/view_screen_state.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="@string/loading_indicator"
tools:visibility="visible" />

<TextView
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<string name="url">URL</string>
<string name="unlock_button">Unlock button</string>
<string name="eye_icon">Eye icon</string>
<string name="loading_indicator">Loading indicator</string>

<!-- Lock notification -->
<string name="lock_notification_channel">Quick Lock</string>
Expand Down

0 comments on commit 356d7ea

Please sign in to comment.