Skip to content

Commit

Permalink
Merge pull request #13517 from nextcloud/bugfix/ss-test-after-offline…
Browse files Browse the repository at this point in the history
…-folder-creation

Fix ScreenShot Tests After Offline Folder Creation Operations
  • Loading branch information
tobiasKaminsky authored Sep 11, 2024
2 parents 8b590bc + 5ef15aa commit ff6220f
Show file tree
Hide file tree
Showing 85 changed files with 116 additions and 132 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2020 Tobias Kaminsky <[email protected]>
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH
* SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
* SPDX-FileCopyrightText: 2024 Alper Ozturk <[email protected]>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
package com.nextcloud.client.jobs

import android.Manifest
import androidx.test.rule.GrantPermissionRule
import androidx.work.WorkManager
import com.nextcloud.client.core.ClockImpl
import com.nextcloud.client.preferences.AppPreferences
import com.nextcloud.client.preferences.AppPreferencesImpl
import com.nextcloud.test.RetryTestRule
import com.owncloud.android.AbstractIT
Expand All @@ -20,24 +20,25 @@ import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.operations.DownloadFileOperation
import ezvcard.Ezvcard
import ezvcard.VCard
import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertTrue
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Assert.fail
import org.junit.Rule
import org.junit.Test
import java.io.BufferedInputStream
import java.io.File
import java.io.FileInputStream

class ContactsBackupIT : AbstractOnServerIT() {
val workmanager = WorkManager.getInstance(targetContext)
val preferences = AppPreferencesImpl.fromContext(targetContext)
private val backgroundJobManager = BackgroundJobManagerImpl(workmanager, ClockImpl(), preferences)
private val workManager = WorkManager.getInstance(targetContext)
private val preferences: AppPreferences = AppPreferencesImpl.fromContext(targetContext)
private val backgroundJobManager = BackgroundJobManagerImpl(workManager, ClockImpl(), preferences)

@get:Rule
val writeContactsRule = GrantPermissionRule.grant(Manifest.permission.WRITE_CONTACTS)
val writeContactsRule: GrantPermissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_CONTACTS)

@get:Rule
val readContactsRule = GrantPermissionRule.grant(Manifest.permission.READ_CONTACTS)
val readContactsRule: GrantPermissionRule = GrantPermissionRule.grant(Manifest.permission.READ_CONTACTS)

@get:Rule
val retryTestRule = RetryTestRule() // flaky test
Expand All @@ -46,38 +47,54 @@ class ContactsBackupIT : AbstractOnServerIT() {

@Test
fun importExport() {
val intArray = IntArray(1)
intArray[0] = 0
val intArray = intArrayOf(0)

// import file to local contacts
backgroundJobManager.startImmediateContactsImport(null, null, getFile(vcard).absolutePath, intArray)

shortSleep()
longSleep()

// export contact
backgroundJobManager.startImmediateContactsBackup(user)

longSleep()

val backupFolder: String = targetContext.resources.getString(R.string.contacts_backup_folder) +
val folderPath: String = targetContext.resources.getString(R.string.contacts_backup_folder) +
OCFile.PATH_SEPARATOR

refreshFolder("/")
longSleep()
longSleep()

refreshFolder(backupFolder)
refreshFolder(folderPath)
longSleep()
longSleep()

val backupOCFile = storageManager.getFolderContent(
storageManager.getFileByDecryptedRemotePath(backupFolder),
false
)[0]
if (folderPath.isEmpty()) {
fail("folderPath cannot be empty")
}

val folder = fileDataStorageManager.getFileByDecryptedRemotePath(folderPath)
if (folder == null) {
fail("folder cannot be null")
}

assertTrue(DownloadFileOperation(user, backupOCFile, AbstractIT.targetContext).execute(client).isSuccess)
val ocFile = storageManager.getFolderContent(folder, false).firstOrNull()
if (ocFile == null) {
fail("ocFile cannot be null")
}

if (ocFile?.storagePath == null) {
fail("ocFile.storagePath cannot be null")
}

assertTrue(DownloadFileOperation(user, ocFile, AbstractIT.targetContext).execute(client).isSuccess)

val file = ocFile?.storagePath?.let { File(it) }
if (file == null) {
fail("file cannot be null")
}

val backupFile = File(backupOCFile.storagePath)
val vcardInputStream = BufferedInputStream(FileInputStream(getFile(vcard)))
val backupFileInputStream = BufferedInputStream(FileInputStream(backupFile))
val backupFileInputStream = BufferedInputStream(FileInputStream(file))

// verify same
val originalCards: ArrayList<VCard> = ArrayList()
Expand All @@ -87,6 +104,17 @@ class ContactsBackupIT : AbstractOnServerIT() {
backupCards.addAll(Ezvcard.parse(backupFileInputStream).all())

assertEquals(originalCards.size, backupCards.size)
assertEquals(originalCards[0].formattedName.toString(), backupCards[0].formattedName.toString())

val originalCardFormattedName = originalCards.firstOrNull()?.formattedName
if (originalCardFormattedName == null) {
fail("originalCardFormattedName cannot be null")
}

val backupCardFormattedName = backupCards.firstOrNull()?.formattedName
if (backupCardFormattedName == null) {
fail("backupCardFormattedName cannot be null")
}

assertEquals(originalCardFormattedName.toString(), backupCardFormattedName.toString())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public void screenshotTextFiles() {
ConflictsResolveActivity sut = activityRule.launchActivity(intent);

ConflictsResolveDialog dialog = ConflictsResolveDialog.newInstance(targetContext,
existingFile,
newFile,
existingFile,
UserAccountManagerImpl
.fromContext(targetContext)
.getUser()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ public void createRichWorkspace() {

DeviceInfo info = new DeviceInfo();
OCFile ocFile = new OCFile("/test.md");
ocFile.setRemoteId("00000001");

Intent intent = new Intent(targetContext, FileDisplayActivity.class);
FileDisplayActivity fda = activityRule.launchActivity(intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
val sut = testActivityRule.launchActivity(null)

OCFile("/1.png").apply {
remoteId = "00000001"
mimeType = "image/png"
fileLength = 1024000
modificationTimestamp = 1188206955000
Expand All @@ -43,6 +44,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
}

OCFile("/image.png").apply {
remoteId = "00000002"
mimeType = "image/png"
isPreviewAvailable = false
fileLength = 3072000
Expand All @@ -53,6 +55,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
}

OCFile("/live photo.png").apply {
remoteId = "00000003"
mimeType = "image/png"
isPreviewAvailable = false
fileLength = 3072000
Expand All @@ -63,6 +66,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
}

OCFile("/video.mp4").apply {
remoteId = "00000004"
mimeType = "video/mp4"
isPreviewAvailable = false
fileLength = 12092000
Expand Down Expand Up @@ -96,6 +100,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
val fragment = OCFileListFragment()

OCFile("/sharedToUser.jpg").apply {
remoteId = "00000001"
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
isSharedWithSharee = true
sharees = listOf(ShareeUser("Admin", "Server Admin", ShareType.USER))
Expand All @@ -104,6 +109,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
}

OCFile("/sharedToGroup.jpg").apply {
remoteId = "00000002"
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
isSharedWithSharee = true
sharees = listOf(ShareeUser("group", "Group", ShareType.GROUP))
Expand All @@ -112,6 +118,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
}

OCFile("/sharedToEmail.jpg").apply {
remoteId = "00000003"
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
isSharedWithSharee = true
sharees = listOf(ShareeUser("[email protected]", "[email protected]", ShareType.EMAIL))
Expand All @@ -120,13 +127,15 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
}

OCFile("/publicLink.jpg").apply {
remoteId = "00000004"
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
isSharedViaLink = true
modificationTimestamp = 1000
sut.storageManager.saveFile(this)
}

OCFile("/sharedToFederatedUser.jpg").apply {
remoteId = "00000005"
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
isSharedWithSharee = true
sharees = listOf(
Expand All @@ -137,6 +146,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
}

OCFile("/sharedToPersonalCircle.jpg").apply {
remoteId = "00000006"
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
isSharedWithSharee = true
sharees = listOf(ShareeUser("circle", "Circle (Personal circle)", ShareType.CIRCLE))
Expand Down Expand Up @@ -170,6 +180,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
// }

OCFile("/sharedToUserRoom.jpg").apply {
remoteId = "00000007"
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
isSharedWithSharee = true
sharees = listOf(ShareeUser("Conversation", "Admin", ShareType.ROOM))
Expand All @@ -178,6 +189,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
}

OCFile("/sharedToGroupRoom.jpg").apply {
remoteId = "00000008"
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
isSharedWithSharee = true
sharees = listOf(ShareeUser("Conversation", "Meeting", ShareType.ROOM))
Expand All @@ -186,6 +198,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
}

OCFile("/sharedToUsers.jpg").apply {
remoteId = "00000009"
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
isSharedWithSharee = true
sharees = listOf(
Expand All @@ -198,6 +211,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
}

OCFile("/notShared.jpg").apply {
remoteId = "000000010"
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
modificationTimestamp = 1000
sut.storageManager.saveFile(this)
Expand Down Expand Up @@ -232,13 +246,15 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
val fragment = OCFileListFragment()

OCFile("/normal/").apply {
remoteId = "00000001"
mimeType = MimeType.DIRECTORY
modificationTimestamp = 1624003571000
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
sut.storageManager.saveFile(this)
}

OCFile("/sharedViaLink/").apply {
remoteId = "00000002"
mimeType = MimeType.DIRECTORY
isSharedViaLink = true
modificationTimestamp = 1619003571000
Expand All @@ -247,6 +263,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
}

OCFile("/share/").apply {
remoteId = "00000003"
mimeType = MimeType.DIRECTORY
isSharedWithSharee = true
modificationTimestamp = 1619303571000
Expand All @@ -255,6 +272,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
}

OCFile("/groupFolder/").apply {
remoteId = "00000004"
mimeType = MimeType.DIRECTORY
modificationTimestamp = 1615003571000
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
Expand All @@ -263,6 +281,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
}

OCFile("/encrypted/").apply {
remoteId = "00000005"
mimeType = MimeType.DIRECTORY
isEncrypted = true
decryptedRemotePath = "/encrypted/"
Expand All @@ -272,6 +291,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
}

OCFile("/locked/").apply {
remoteId = "00000006"
mimeType = MimeType.DIRECTORY
isLocked = true
decryptedRemotePath = "/locked/"
Expand Down Expand Up @@ -310,12 +330,15 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
folder.setFolder()
sut.storageManager.saveFile(folder)

val imageFile = OCFile("/test/image.png")
imageFile.mimeType = "image/png"
imageFile.fileLength = 1024000
imageFile.modificationTimestamp = 1188206955000
imageFile.parentId = sut.storageManager.getFileByEncryptedRemotePath("/test/").fileId
imageFile.storagePath = getFile("java.md").absolutePath
val imageFile = OCFile("/test/image.png").apply {
remoteId = "00000001"
mimeType = "image/png"
fileLength = 1024000
modificationTimestamp = 1188206955000
parentId = sut.storageManager.getFileByEncryptedRemotePath("/test/").fileId
storagePath = getFile("java.md").absolutePath
}

sut.storageManager.saveFile(imageFile)

sut.addFragment(fragment)
Expand All @@ -334,8 +357,11 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
val activity = testActivityRule.launchActivity(null)
val sut = OCFileListFragment()

val folder = OCFile("/test/")
folder.setFolder()
val folder = OCFile("/test/").apply {
remoteId = "000001"
setFolder()
}

activity.storageManager.saveFile(folder)

activity.addFragment(sut)
Expand All @@ -357,7 +383,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {

testFolder.richWorkspace = "1"
activity.storageManager.saveFile(testFolder)
sut.adapter.setCurrentDirectory(testFolder)
sut.adapter.currentDirectory = testFolder
Assert.assertTrue(sut.adapter.shouldShowHeader())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.nextcloud.client.jobs.transfer.TransferManager
import com.owncloud.android.R
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.db.OCUpload
import java.util.Locale

class EtmFileTransferFragment : EtmBaseFragment() {

Expand Down Expand Up @@ -96,7 +97,7 @@ class EtmFileTransferFragment : EtmBaseFragment() {
vh.state.text = transfer.state.toString()
if (transfer.progress >= 0) {
vh.progressEnabled = true
vh.progress.text = transfer.progress.toString()
vh.progress.text = String.format(Locale.getDefault(), "%d", transfer.progress)
} else {
vh.progressEnabled = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ public boolean isDownloading() {
}

public boolean isRootDirectory() {
return decryptedRemotePath.equals(ROOT_PATH);
return ROOT_PATH.equals(decryptedRemotePath);
}

public boolean isOfflineOperation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ public class UploadFilesActivity extends DrawerActivity implements LocalFileList
private UploadFilesLayoutBinding binding;
private boolean isWithinEncryptedFolder = false;


@VisibleForTesting
public LocalFileListFragment getFileListFragment() {
return mFileListFragment;
}
Expand Down
Loading

0 comments on commit ff6220f

Please sign in to comment.