PreviewTextFileFragmentTest.java 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. *
  3. * Nextcloud Android client application
  4. *
  5. * @author Tobias Kaminsky
  6. * Copyright (C) 2020 Tobias Kaminsky
  7. * Copyright (C) 2020 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.owncloud.android.ui.preview;
  23. import android.Manifest;
  24. import com.facebook.testing.screenshot.Screenshot;
  25. import com.owncloud.android.AbstractIT;
  26. import com.owncloud.android.datamodel.OCFile;
  27. import com.owncloud.android.ui.activity.FileDisplayActivity;
  28. import com.owncloud.android.utils.FileStorageUtils;
  29. import com.owncloud.android.utils.MimeTypeUtil;
  30. import org.junit.Rule;
  31. import org.junit.Test;
  32. import java.io.File;
  33. import java.io.IOException;
  34. import androidx.test.espresso.intent.rule.IntentsTestRule;
  35. import androidx.test.rule.GrantPermissionRule;
  36. public class PreviewTextFileFragmentTest extends AbstractIT {
  37. @Rule public IntentsTestRule<FileDisplayActivity> activityRule = new IntentsTestRule<>(FileDisplayActivity.class,
  38. true,
  39. false);
  40. @Rule
  41. public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
  42. Manifest.permission.WRITE_EXTERNAL_STORAGE);
  43. @Test
  44. public void displaySimpleTextFile() throws InterruptedException {
  45. FileDisplayActivity sut = activityRule.launchActivity(null);
  46. shortSleep();
  47. File file = new File(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt");
  48. OCFile test = new OCFile("/text.md");
  49. test.setMimeType(MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN);
  50. test.setStoragePath(file.getAbsolutePath());
  51. sut.startTextPreview(test, false);
  52. shortSleep();
  53. Screenshot.snapActivity(sut).record();
  54. }
  55. @Test
  56. public void displayJavaSnippetFile() throws IOException, InterruptedException {
  57. FileDisplayActivity sut = activityRule.launchActivity(null);
  58. shortSleep();
  59. File file = getFile("java.md");
  60. OCFile test = new OCFile("/java.md");
  61. test.setMimeType(MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN);
  62. test.setStoragePath(file.getAbsolutePath());
  63. sut.startTextPreview(test, false);
  64. shortSleep();
  65. Screenshot.snapActivity(sut).record();
  66. }
  67. }