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

Re-enable shared search and add ui test for list shares #5300

Merged
merged 5 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 15 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,21 @@ steps:

services:
- name: server
image: nextcloudci/server:server-3
image: nextcloudci/server:server-17 # also change in updateScreenshots.sh
commands:
- /usr/local/bin/initnc.sh
- su www-data -c "OC_PASS=user1 php /var/www/html/occ user:add --password-from-env --display-name='User One' user1"
- su www-data -c "OC_PASS=user2 php /var/www/html/occ user:add --password-from-env --display-name='User Two' user2"
- su www-data -c "OC_PASS=user3 php /var/www/html/occ user:add --password-from-env --display-name='User Three' user3"
- su www-data -c "php /var/www/html/occ user:setting user2 files quota 1G"
- su www-data -c "php /var/www/html/occ group:add users"
- su www-data -c "php /var/www/html/occ group:adduser users user1"
- su www-data -c "php /var/www/html/occ group:adduser users user2"
- su www-data -c "git clone -b master https://github.com/nextcloud/activity.git /var/www/html/apps/activity/"
- su www-data -c "php /var/www/html/occ app:enable activity"
- su www-data -c "git clone -b master https://github.com/nextcloud/text.git /var/www/html/apps/text/"
- su www-data -c "php /var/www/html/occ app:enable text"
- /usr/local/bin/run.sh

trigger:
branch:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion scripts/analysis/findbugs-results.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
387
386
16 changes: 13 additions & 3 deletions scripts/updateScreenshots.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ emulator -avd uiComparison -no-snapshot -gpu swiftshader_indirect -no-window -no
PID=$(echo $!)

## server
docker run --name=uiComparison nextcloudci/server 1>/dev/null &
docker run --name=uiComparison nextcloudci/server:server-17 1>/dev/null &
sleep 5
IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' uiComparison)

Expand All @@ -28,9 +28,19 @@ fi
cp gradle.properties gradle.properties_
sed -i s"/server/$IP/" gradle.properties
scripts/wait_for_emulator.sh
scripts/wait_for_server.sh ${IP}

## update all screenshots
# setup test server
docker exec uiComparison /bin/sh -c "/usr/local/bin/initnc.sh"
docker exec uiComparison /bin/sh -c "su www-data -c \"OC_PASS=user1 php /var/www/html/occ user:add --password-from-env --display-name='User One' user1\""
docker exec uiComparison /bin/sh -c "su www-data -c \"OC_PASS=user2 php /var/www/html/occ user:add --password-from-env --display-name='User Two' user2\""
docker exec uiComparison /bin/sh -c "su www-data -c \"OC_PASS=user3 php /var/www/html/occ user:add --password-from-env --display-name='User Three' user3\""
docker exec uiComparison /bin/sh -c "su www-data -c \"php /var/www/html/occ user:setting user2 files quota 1G\""
docker exec uiComparison /bin/sh -c "su www-data -c \"php /var/www/html/occ group:add users\""
docker exec uiComparison /bin/sh -c "su www-data -c \"php /var/www/html/occ group:adduser users user1\""
docker exec uiComparison /bin/sh -c "su www-data -c \"php /var/www/html/occ group:adduser users user2\""
docker exec uiComparison /bin/sh -c "/usr/local/bin/run.sh"

## update/create all screenshots
./gradlew executeScreenshotTests -Precord

## update screenshots in a class
Expand Down
52 changes: 36 additions & 16 deletions scripts/uploadReport.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#!/usr/bin/env bash

upload() {
cd $1

find . -type d -exec curl -u $USER:$PASS -X MKCOL $URL/$REMOTE_FOLDER/$(echo {} | sed s#\./##) \;
find . -type f -exec curl -u $USER:$PASS -X PUT $URL/$REMOTE_FOLDER/$(echo {} | sed s#\./##) --upload-file {} \;

echo "Uploaded failing tests to https://www.kaminsky.me/nc-dev/android-integrationTests/$REMOTE_FOLDER"

curl -u $GITHUB_USER:$GITHUB_PASSWORD -X POST https://github.com/gitapi/repos/nextcloud/android/issues/$PR/comments \
-d "{ \"body\" : \"$TYPE test failed: https://www.kaminsky.me/nc-dev/android-integrationTests/$REMOTE_FOLDER \" }"

exit 1
}

#1: LOG_USERNAME
#2: LOG_PASSWORD
#3: DRONE_BUILD_NUMBER
Expand All @@ -13,6 +27,9 @@ ID=$3
USER=$1
PASS=$2
TYPE=$4
PR=$5
GITHUB_USER=$6
GITHUB_PASSWORD=$7
REMOTE_FOLDER=$ID-$TYPE

set -e
Expand All @@ -22,27 +39,30 @@ if [ $TYPE = "IT" ]; then
elif [ $TYPE = "Unit" ]; then
FOLDER=build/reports/tests/testGplayDebugUnitTest
else
FOLDER=build/reports/shot/verification/
FOLDER=build/reports/shot/verification
fi

if [ ! -e $FOLDER ]; then
if [ -e $FOLDER ]; then
upload $FOLDER
else
echo "$TYPE test failed, but no output was generated. Maybe a preliminary stage failed."

curl -u $6:$7 \
-X POST https://github.com/gitapi/repos/nextcloud/android/issues/$5/comments \
curl -u $GITHUB_USER:$GITHUB_PASSWORD \
-X POST https://github.com/gitapi/repos/nextcloud/android/issues/$PR/comments \
-d "{ \"body\" : \"$TYPE test failed, but no output was generated. Maybe a preliminary stage failed. \" }"

exit 1
fi

cd $FOLDER
if [ -e build/reports/androidTests/connected/flavors/GPLAY ] ; then
TYPE="IT"
upload "build/reports/androidTests/connected/flavors/GPLAY"
fi

find . -type d -exec curl -u $USER:$PASS -X MKCOL $URL/$REMOTE_FOLDER/$(echo {} | sed s#\./##) \;
find . -type f -exec curl -u $USER:$PASS -X PUT $URL/$REMOTE_FOLDER/$(echo {} | sed s#\./##) --upload-file {} \;
if [ -e build/reports/tests/testGplayDebugUnitTest ] ; then
TYPE="Unit"
upload "build/reports/tests/testGplayDebugUnitTest"
fi

echo "Uploaded failing tests to https://www.kaminsky.me/nc-dev/android-integrationTests/$REMOTE_FOLDER"

curl -u $6:$7 -X POST https://github.com/gitapi/repos/nextcloud/android/issues/$5/comments \
-d "{ \"body\" : \"$TYPE test failed: https://www.kaminsky.me/nc-dev/android-integrationTests/$REMOTE_FOLDER \" }"

exit 1
if [ -e build/reports/shot/verification ] ; then
TYPE="Screenshot"
upload "build/reports/shot/verification"
fi
fi
2 changes: 1 addition & 1 deletion scripts/wait_for_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ until [[ $status = "false" ]]; do

if [[ "$status" =~ "false" || "$status" = "" ]]; then
let "counter += 1"
if [[ $counter -gt 2 ]]; then
if [[ $counter -gt 10 ]]; then
echo "Failed to wait for server"
exit 1
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,17 @@
import com.facebook.testing.screenshot.Screenshot;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.R;
import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation;
import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;
import com.owncloud.android.lib.resources.files.SearchRemoteOperation;
import com.owncloud.android.lib.resources.shares.CreateShareRemoteOperation;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.events.SearchEvent;

import org.greenrobot.eventbus.EventBus;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

Expand All @@ -40,6 +49,8 @@
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
import static junit.framework.TestCase.assertTrue;


public class FileDisplayActivityIT extends AbstractIT {
Expand Down Expand Up @@ -69,6 +80,53 @@ public void drawer() {
Screenshot.snapActivity(sut).record();
}

@Test
public void showShares() {
assertTrue(new ExistenceCheckRemoteOperation("/shareToAdmin/", true).execute(client).isSuccess());
assertTrue(new CreateFolderRemoteOperation("/shareToAdmin/", true).execute(client).isSuccess());
assertTrue(new CreateFolderRemoteOperation("/shareToGroup/", true).execute(client).isSuccess());
assertTrue(new CreateFolderRemoteOperation("/shareViaLink/", true).execute(client).isSuccess());
assertTrue(new CreateFolderRemoteOperation("/noShare/", true).execute(client).isSuccess());

// share folder to user "admin"
assertTrue(new CreateShareRemoteOperation("/shareToAdmin/",
ShareType.USER,
"admin",
false,
"",
OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER)
.execute(client).isSuccess());

// share folder via public link
assertTrue(new CreateShareRemoteOperation("/shareViaLink/",
ShareType.PUBLIC_LINK,
"",
true,
"",
OCShare.READ_PERMISSION_FLAG)
.execute(client).isSuccess());

// share folder to group
Assert.assertTrue(new CreateShareRemoteOperation("/shareToGroup/",
ShareType.GROUP,
"users",
false,
"",
OCShare.DEFAULT_PERMISSION)
.execute(client).isSuccess());

Activity sut = activityRule.launchActivity(null);

getInstrumentation().waitForIdleSync();

EventBus.getDefault().post(new SearchEvent("",
SearchRemoteOperation.SearchType.SHARED_FILTER));

getInstrumentation().waitForIdleSync();

Screenshot.snapActivity(sut).record();
}

@Test
public void showAccounts() {
Activity sut = activityRule.launchActivity(null);
Expand Down
22 changes: 22 additions & 0 deletions src/androidTest/java/com/owncloud/android/AbstractIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation;
import com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation;
import com.owncloud.android.lib.resources.files.model.RemoteFile;
import com.owncloud.android.utils.FileStorageUtils;

import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
Expand All @@ -39,6 +44,7 @@
import static androidx.test.InstrumentationRegistry.getInstrumentation;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static org.junit.Assert.assertTrue;


/**
Expand Down Expand Up @@ -97,6 +103,22 @@ public static void beforeAll() {
}
}

@After
public void after() {
RemoteOperationResult result = new ReadFolderRemoteOperation("/").execute(client);
assertTrue(result.getLogMessage(), result.isSuccess());

for (Object object : result.getData()) {
RemoteFile remoteFile = (RemoteFile) object;

if (!remoteFile.getRemotePath().equals("/")) {
assertTrue(new RemoveFileRemoteOperation(remoteFile.getRemotePath())
.execute(client).isSuccess());
}
}
}


FileDataStorageManager getStorageManager() {
return new FileDataStorageManager(account, targetContext.getContentResolver());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ private void selectNavigationItem(final MenuItem menuItem) {
UserInfoActivity.openAccountRemovalConfirmationDialog(getAccount(), getSupportFragmentManager());
break;
case R.id.nav_shared:
handleSearchEvents(new SearchEvent("", SearchRemoteOperation.SearchType.SHARED_SEARCH),
handleSearchEvents(new SearchEvent("", SearchRemoteOperation.SearchType.SHARED_FILTER),
menuItem.getItemId());
break;
case R.id.nav_recently_modified:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
protected SearchType currentSearchType;
protected boolean searchFragment;
protected SearchEvent searchEvent;
protected AsyncTask remoteOperationAsyncTask;
protected AsyncTask<Void, Void, Boolean> remoteOperationAsyncTask;
protected String mLimitToMimeType;

@Inject DeviceInfo deviceInfo;
Expand Down Expand Up @@ -388,6 +388,10 @@ protected void prepareCurrentSearch(SearchEvent event) {
currentSearchType = SearchType.RECENTLY_MODIFIED_SEARCH;
break;

case SHARED_FILTER:
currentSearchType = SearchType.SHARED_FILTER;
break;

default:
// do nothing
break;
Expand Down Expand Up @@ -1587,7 +1591,7 @@ protected void onPostExecute(Boolean bool) {
}
};

remoteOperationAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, true);
remoteOperationAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

@Subscribe(threadMode = ThreadMode.BACKGROUND)
Expand Down Expand Up @@ -1700,7 +1704,8 @@ private boolean isSearchEventSet(SearchEvent event) {
return event != null &&
event.getSearchType() != null &&
(!TextUtils.isEmpty(event.getSearchQuery()) ||
event.searchType == SearchRemoteOperation.SearchType.SHARED_SEARCH);
event.searchType == SearchRemoteOperation.SearchType.SHARED_SEARCH ||
event.searchType == SearchRemoteOperation.SearchType.SHARED_FILTER);
}

private void syncAndCheckFiles(Collection<OCFile> files) {
Expand Down