Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
  • Loading branch information
tobiasKaminsky committed Aug 28, 2023
1 parent e813d02 commit cc0136e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package com.owncloud.android.ui.fragment

import androidx.test.espresso.intent.rule.IntentsTestRule
import com.nextcloud.test.TestActivity
import com.nextcloud.ui.ImageDetailFragment
import com.owncloud.android.AbstractIT
import com.owncloud.android.R
import com.owncloud.android.datamodel.OCFile
Expand All @@ -40,13 +41,16 @@ class FileDetailFragmentStaticServerIT : AbstractIT() {
@get:Rule
val testActivityRule = IntentsTestRule(TestActivity::class.java, true, false)

val file = OCFile("/")
var file = getFile("gps.jpg")
val oCFile = OCFile("/").apply {
storagePath = file.absolutePath
}

@Test
@ScreenshotTest
fun showFileDetailActivitiesFragment() {
val sut = testActivityRule.launchActivity(null)
sut.addFragment(FileDetailActivitiesFragment.newInstance(file, user))
sut.addFragment(FileDetailActivitiesFragment.newInstance(oCFile, user))

waitForIdleSync()
shortSleep()
Expand All @@ -58,7 +62,19 @@ class FileDetailFragmentStaticServerIT : AbstractIT() {
@ScreenshotTest
fun showFileDetailSharingFragment() {
val sut = testActivityRule.launchActivity(null)
sut.addFragment(FileDetailSharingFragment.newInstance(file, user))
sut.addFragment(FileDetailSharingFragment.newInstance(oCFile, user))

waitForIdleSync()
shortSleep()
shortSleep()
screenshot(sut)
}

@Test
@ScreenshotTest
fun showFileDetailDetailsFragment() {
val sut = testActivityRule.launchActivity(null)
sut.addFragment(ImageDetailFragment.newInstance(oCFile, user))

waitForIdleSync()
shortSleep()
Expand All @@ -71,7 +87,7 @@ class FileDetailFragmentStaticServerIT : AbstractIT() {
@Suppress("MagicNumber")
fun showDetailsActivities() {
val activity = testActivityRule.launchActivity(null)
val sut = FileDetailFragment.newInstance(file, user, 0)
val sut = FileDetailFragment.newInstance(oCFile, user, 0)
activity.addFragment(sut)

waitForIdleSync()
Expand Down Expand Up @@ -141,7 +157,7 @@ class FileDetailFragmentStaticServerIT : AbstractIT() {
// @ScreenshotTest
fun showDetailsActivitiesNone() {
val activity = testActivityRule.launchActivity(null)
val sut = FileDetailFragment.newInstance(file, user, 0)
val sut = FileDetailFragment.newInstance(oCFile, user, 0)
activity.addFragment(sut)

waitForIdleSync()
Expand All @@ -159,7 +175,7 @@ class FileDetailFragmentStaticServerIT : AbstractIT() {
@ScreenshotTest
fun showDetailsActivitiesError() {
val activity = testActivityRule.launchActivity(null)
val sut = FileDetailFragment.newInstance(file, user, 0)
val sut = FileDetailFragment.newInstance(oCFile, user, 0)
activity.addFragment(sut)

waitForIdleSync()
Expand All @@ -179,7 +195,7 @@ class FileDetailFragmentStaticServerIT : AbstractIT() {
@ScreenshotTest
fun showDetailsSharing() {
val sut = testActivityRule.launchActivity(null)
sut.addFragment(FileDetailFragment.newInstance(file, user, 1))
sut.addFragment(FileDetailFragment.newInstance(oCFile, user, 1))

waitForIdleSync()

Expand Down
26 changes: 10 additions & 16 deletions app/src/main/java/com/nextcloud/ui/ImageDetailFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ class ImageDetailFragment : Fragment(), Injectable {
file = arguments.getParcelable(ARG_FILE)!!
user = arguments.getParcelable(ARG_USER)!!

// TODO add onSaveInstance or remove
if (savedInstanceState != null) {
file = savedInstanceState.getParcelable(ARG_FILE)!!
user = savedInstanceState.getParcelable(ARG_USER)!!
Expand Down Expand Up @@ -131,7 +130,7 @@ class ImageDetailFragment : Fragment(), Injectable {

// detailed file information
val fileInformation = mutableListOf<String>()
if (!checkNull(metadata)) {
if (metadata.length != null && metadata.width != null && metadata.length!! > 0 && metadata.width!! > 0) {
try {
@Suppress("MagicNumber")
val pxlCount = when (val res = metadata.length!! * metadata.width!!.toLong()) {
Expand Down Expand Up @@ -208,18 +207,6 @@ class ImageDetailFragment : Fragment(), Injectable {
}
}

private fun checkNull(metadata: ImageMetadata): Boolean {
if (metadata.length == null || metadata.length <= 0) {
return true
}

if (metadata.width == null || metadata.width <= 0) {
return true
}

return false
}

@SuppressLint("ClickableViewAccessibility")
private fun initMap(latitude: Double, longitude: Double, zoom: Double = 13.0) {
// required for OpenStreetMap
Expand Down Expand Up @@ -300,7 +287,7 @@ class ImageDetailFragment : Fragment(), Injectable {
}

// determine size if not contained in exif data
if (checkNull(metadata)) {
if (width == null || length == null || width <= 0 || length <= 0) {
val res = BitmapUtils.getImageResolution(file.storagePath)
width = res[0]
length = res[1]
Expand Down Expand Up @@ -355,7 +342,14 @@ class ImageDetailFragment : Fragment(), Injectable {
ThumbnailsCacheManager.getBitmapFromDiskCache(ThumbnailsCacheManager.PREFIX_THUMBNAIL + file.remoteId)
val foreground = BitmapUtils.bitmapToCircularBitmapDrawable(resources, bitmap)
val background = ContextCompat.getDrawable(context, R.drawable.photo_pin)
val layerDrawable = LayerDrawable(arrayOf(background, foreground))

val layerDrawable = if (foreground != null) {
LayerDrawable(arrayOf(background, foreground))
} else {
val d = ContextCompat.getDrawable(context, R.drawable.file_image)
LayerDrawable(arrayOf(background, d))
}

val dp = DisplayUtils.convertDpToPixel(2f, context)
layerDrawable.apply {
setLayerSize(1, 38 * dp, 38 * dp)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/owncloud/android/utils/BitmapUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ public static String md5(String string) throws NoSuchAlgorithmException {
* @param bitmap the original bitmap
* @return the circular bitmap
*/
@Nullable
public static RoundedBitmapDrawable bitmapToCircularBitmapDrawable(Resources resources,
Bitmap bitmap,
float radius) {
Expand All @@ -370,6 +371,7 @@ public static RoundedBitmapDrawable bitmapToCircularBitmapDrawable(Resources res
return roundedBitmap;
}

@Nullable
public static RoundedBitmapDrawable bitmapToCircularBitmapDrawable(Resources resources, Bitmap bitmap) {
return bitmapToCircularBitmapDrawable(resources, bitmap, -1);
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
daggerVersion = "2.47"
markwonVersion = "4.6.2"
prismVersion = "2.0.0"
androidLibraryVersion = "gps-SNAPSHOT"
androidLibraryVersion = "master-SNAPSHOT"
mockitoVersion = "4.11.0"
mockitoKotlinVersion = "4.1.0"
mockkVersion = "1.13.3"
Expand Down

0 comments on commit cc0136e

Please sign in to comment.