Skip to content

Commit

Permalink
add loading tests to every operation on public shares
Browse files Browse the repository at this point in the history
  • Loading branch information
jesmrec authored and davigonz committed Jun 3, 2019
1 parent 4aa9439 commit c4becd4
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import android.os.Parcelable
import androidx.lifecycle.MutableLiveData
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
import androidx.test.espresso.assertion.ViewAssertions.matches
Expand Down Expand Up @@ -260,6 +261,39 @@ class CreatePublicShareTest {
onView(withText(newPublicShare3.name)).check(matches(isDisplayed()))
}

@Test
fun loadingCreateShares(){

loadCapabilitiesSuccessfully()
loadSharesSuccessfully(arrayListOf())

val newPublicShare = publicShares[0]

`when`(
ocShareViewModel.insertPublicShareForFile(
1,
newPublicShare.name!!,
"",
-1,
false
)
).thenReturn(sharesLiveData)

// 1. Open dialog to create new public share
onView(withId(R.id.addPublicLinkButton)).perform(click())

// 2. Save share
onView(withId(R.id.saveButton)).perform(click())

sharesLiveData.postValue(
Resource.loading(
arrayListOf(newPublicShare)
)
)

onView(withText(R.string.common_loading)).check(matches(isDisplayed()))
}

private fun getOCFileForTesting(name: String = "default") = OCFile("/Photos").apply {
availableOfflineStatus = OCFile.AvailableOfflineStatus.NOT_AVAILABLE_OFFLINE
fileName = name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import com.owncloud.android.capabilities.db.OCCapability
import com.owncloud.android.capabilities.viewmodel.OCCapabilityViewModel
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.lib.common.accounts.AccountUtils
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.resources.status.CapabilityBooleanType
import com.owncloud.android.lib.resources.status.OwnCloudVersion
import com.owncloud.android.shares.db.OCShare
Expand Down Expand Up @@ -237,6 +238,24 @@ class DeletePublicShareTest {

}

@Test
fun loadingDeleteShares(){
loadCapabilitiesSuccessfully()

val existingPublicShare = publicShares[0]
loadSharesSuccessfully(arrayListOf(existingPublicShare))

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

sharesLiveData.postValue(
Resource.loading(
publicShares
)
)

onView(withText(R.string.common_loading)).check(matches(isDisplayed()))
}

private fun getOCFileForTesting(name: String = "default"): OCFile {
val file = OCFile("/Photos/image.jpg")
file.availableOfflineStatus = OCFile.AvailableOfflineStatus.NOT_AVAILABLE_OFFLINE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,40 @@ class EditPublicShareTest {
onView(withId(R.id.shareViaLinkExpirationSwitch)).check(matches(isNotChecked()))
}

@Test
fun loadingEditShares(){
loadCapabilitiesSuccessfully()

val existingPublicShare = publicShares[0]
loadSharesSuccessfully(arrayListOf(existingPublicShare))

val updatedPublicShare = publicShares[1]

`when`(
ocShareViewModel.updatePublicShareForFile(
1,
updatedPublicShare.name!!,
"",
-1,
1,
false
)
).thenReturn(sharesLiveData)

//Edit name is performed
onView(withId(R.id.editPublicLinkButton)).perform(click())
onView(withId(R.id.shareViaLinkNameValue)).perform(replaceText(updatedPublicShare.name))
onView(withId(R.id.saveButton)).perform(click())

sharesLiveData.postValue(
Resource.loading(
arrayListOf(updatedPublicShare)
)
)

onView(withText(R.string.common_loading)).check(matches(isDisplayed()))
}

private fun getOCFileForTesting(name: String = "default") = OCFile("/Photos").apply {
availableOfflineStatus = OCFile.AvailableOfflineStatus.NOT_AVAILABLE_OFFLINE
fileName = name
Expand Down

0 comments on commit c4becd4

Please sign in to comment.