FileDisplayActivityIT.java 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. *
  3. * Nextcloud Android client application
  4. *
  5. * @author Tobias Kaminsky
  6. * Copyright (C) 2019 Tobias Kaminsky
  7. * Copyright (C) 2019 Nextcloud GmbH
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. package com.nextcloud.client;
  23. import android.Manifest;
  24. import android.app.Activity;
  25. import com.owncloud.android.AbstractOnServerIT;
  26. import com.owncloud.android.R;
  27. import com.owncloud.android.datamodel.OCFile;
  28. import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation;
  29. import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;
  30. import com.owncloud.android.lib.resources.files.SearchRemoteOperation;
  31. import com.owncloud.android.lib.resources.shares.CreateShareRemoteOperation;
  32. import com.owncloud.android.lib.resources.shares.OCShare;
  33. import com.owncloud.android.lib.resources.shares.ShareType;
  34. import com.owncloud.android.operations.CreateFolderOperation;
  35. import com.owncloud.android.ui.activity.FileDisplayActivity;
  36. import com.owncloud.android.ui.events.SearchEvent;
  37. import org.greenrobot.eventbus.EventBus;
  38. import org.junit.Assert;
  39. import org.junit.Rule;
  40. import org.junit.Test;
  41. import androidx.test.espresso.contrib.DrawerActions;
  42. import androidx.test.espresso.contrib.NavigationViewActions;
  43. import androidx.test.espresso.intent.rule.IntentsTestRule;
  44. import androidx.test.rule.GrantPermissionRule;
  45. import static androidx.test.espresso.Espresso.onView;
  46. import static androidx.test.espresso.matcher.ViewMatchers.withId;
  47. import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
  48. import static junit.framework.TestCase.assertEquals;
  49. import static junit.framework.TestCase.assertTrue;
  50. public class FileDisplayActivityIT extends AbstractOnServerIT {
  51. @Rule public IntentsTestRule<FileDisplayActivity> activityRule = new IntentsTestRule<>(FileDisplayActivity.class,
  52. true,
  53. false);
  54. @Rule
  55. public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
  56. Manifest.permission.WRITE_EXTERNAL_STORAGE);
  57. @Test
  58. // @ScreenshotTest // todo run without real server
  59. public void showShares() {
  60. assertTrue(new ExistenceCheckRemoteOperation("/shareToAdmin/", true).execute(client).isSuccess());
  61. assertTrue(new CreateFolderRemoteOperation("/shareToAdmin/", true).execute(client).isSuccess());
  62. assertTrue(new CreateFolderRemoteOperation("/shareToGroup/", true).execute(client).isSuccess());
  63. assertTrue(new CreateFolderRemoteOperation("/shareViaLink/", true).execute(client).isSuccess());
  64. assertTrue(new CreateFolderRemoteOperation("/noShare/", true).execute(client).isSuccess());
  65. // assertTrue(new CreateFolderRemoteOperation("/shareToCircle/", true).execute(client).isSuccess());
  66. // share folder to user "admin"
  67. assertTrue(new CreateShareRemoteOperation("/shareToAdmin/",
  68. ShareType.USER,
  69. "admin",
  70. false,
  71. "",
  72. OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER)
  73. .execute(client).isSuccess());
  74. // share folder via public link
  75. assertTrue(new CreateShareRemoteOperation("/shareViaLink/",
  76. ShareType.PUBLIC_LINK,
  77. "",
  78. true,
  79. "",
  80. OCShare.READ_PERMISSION_FLAG)
  81. .execute(client).isSuccess());
  82. // share folder to group
  83. Assert.assertTrue(new CreateShareRemoteOperation("/shareToGroup/",
  84. ShareType.GROUP,
  85. "users",
  86. false,
  87. "",
  88. OCShare.DEFAULT_PERMISSION)
  89. .execute(client).isSuccess());
  90. // share folder to circle
  91. // get share
  92. // RemoteOperationResult searchResult = new GetShareesRemoteOperation("publicCircle", 1, 50).execute(client);
  93. // assertTrue(searchResult.getLogMessage(), searchResult.isSuccess());
  94. //
  95. // JSONObject resultJson = (JSONObject) searchResult.getData().get(0);
  96. // String circleId = resultJson.getJSONObject("value").getString("shareWith");
  97. //
  98. // assertTrue(new CreateShareRemoteOperation("/shareToCircle/",
  99. // ShareType.CIRCLE,
  100. // circleId,
  101. // false,
  102. // "",
  103. // OCShare.DEFAULT_PERMISSION)
  104. // .execute(client).isSuccess());
  105. Activity sut = activityRule.launchActivity(null);
  106. getInstrumentation().waitForIdleSync();
  107. EventBus.getDefault().post(new SearchEvent("", SearchRemoteOperation.SearchType.SHARED_FILTER));
  108. shortSleep();
  109. shortSleep();
  110. screenshot(sut);
  111. }
  112. @Test
  113. public void allFiles() {
  114. FileDisplayActivity sut = activityRule.launchActivity(null);
  115. // given test folder
  116. assertTrue(new CreateFolderOperation("/test/", user, targetContext)
  117. .execute(client, getStorageManager())
  118. .isSuccess());
  119. // navigate into it
  120. OCFile test = getStorageManager().getFileByPath("/test/");
  121. sut.setFile(test);
  122. sut.startSyncFolderOperation(test, false);
  123. assertEquals(getStorageManager().getFileByPath("/test/"), sut.getCurrentDir());
  124. // open drawer
  125. onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
  126. // click "all files"
  127. onView(withId(R.id.nav_view))
  128. .perform(NavigationViewActions.navigateTo(R.id.nav_all_files));
  129. // then should be in root again
  130. shortSleep();
  131. assertEquals(getStorageManager().getFileByPath("/"), sut.getCurrentDir());
  132. }
  133. }