FileDetailFragmentStaticServerIT.kt 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. * Copyright (C) 2020 Chris Narkiewicz <hello@ezaquarii.com>
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. package com.owncloud.android.ui.fragment
  24. import androidx.test.espresso.intent.rule.IntentsTestRule
  25. import com.nextcloud.client.TestActivity
  26. import com.owncloud.android.AbstractIT
  27. import com.owncloud.android.R
  28. import com.owncloud.android.datamodel.OCFile
  29. import com.owncloud.android.lib.resources.activities.model.Activity
  30. import com.owncloud.android.lib.resources.activities.model.RichElement
  31. import com.owncloud.android.lib.resources.activities.model.RichObject
  32. import com.owncloud.android.lib.resources.activities.models.PreviewObject
  33. import com.owncloud.android.utils.ScreenshotTest
  34. import org.junit.Rule
  35. import org.junit.Test
  36. import java.util.GregorianCalendar
  37. class FileDetailFragmentStaticServerIT : AbstractIT() {
  38. @get:Rule
  39. val testActivityRule = IntentsTestRule(TestActivity::class.java, true, false)
  40. val file = OCFile("/", "00000001")
  41. @Test
  42. @ScreenshotTest
  43. fun showFileDetailActivitiesFragment() {
  44. val sut = testActivityRule.launchActivity(null)
  45. sut.addFragment(FileDetailActivitiesFragment.newInstance(file, user))
  46. waitForIdleSync()
  47. shortSleep()
  48. shortSleep()
  49. screenshot(sut)
  50. }
  51. @Test
  52. @ScreenshotTest
  53. fun showFileDetailSharingFragment() {
  54. val sut = testActivityRule.launchActivity(null)
  55. sut.addFragment(FileDetailSharingFragment.newInstance(file, user))
  56. waitForIdleSync()
  57. shortSleep()
  58. shortSleep()
  59. screenshot(sut)
  60. }
  61. @Test
  62. @ScreenshotTest
  63. @Suppress("MagicNumber")
  64. fun showDetailsActivities() {
  65. val activity = testActivityRule.launchActivity(null)
  66. val sut = FileDetailFragment.newInstance(file, user, 0)
  67. activity.addFragment(sut)
  68. waitForIdleSync()
  69. val date = GregorianCalendar()
  70. date.set(2005, 4, 17, 10, 35, 30) // random date
  71. val richObjectList: ArrayList<RichObject> = ArrayList()
  72. richObjectList.add(RichObject("file", "abc", "text.txt", "/text.txt", "link", "tag"))
  73. richObjectList.add(RichObject("file", "1", "text.txt", "/text.txt", "link", "tag"))
  74. val previewObjectList1: ArrayList<PreviewObject> = ArrayList()
  75. previewObjectList1.add(PreviewObject(1, "source", "link", true, "text/plain", "view", "text.txt"))
  76. val richObjectList2: ArrayList<RichObject> = ArrayList()
  77. richObjectList2.add(RichObject("user", "admin", "Admin", "", "", ""))
  78. val activities = mutableListOf(
  79. Activity(
  80. 1,
  81. date.time,
  82. date.time,
  83. "files",
  84. "file_changed",
  85. "user1",
  86. "user1",
  87. "You changed text.txt",
  88. "",
  89. "icon",
  90. "link",
  91. "files",
  92. "1",
  93. "/text.txt",
  94. previewObjectList1,
  95. RichElement("", richObjectList)
  96. ),
  97. Activity(
  98. 2,
  99. date.time,
  100. date.time,
  101. "comments",
  102. "comments",
  103. "user1",
  104. "user1",
  105. "admin commented",
  106. "test2",
  107. "icon",
  108. "link",
  109. "files",
  110. "1",
  111. "/text.txt",
  112. null,
  113. null
  114. )
  115. )
  116. activity.runOnUiThread {
  117. sut.fileDetailActivitiesFragment.populateList(activities as List<Any>?, true)
  118. }
  119. shortSleep()
  120. shortSleep()
  121. screenshot(activity)
  122. }
  123. @Test
  124. @ScreenshotTest
  125. fun showDetailsActivitiesNone() {
  126. val activity = testActivityRule.launchActivity(null)
  127. val sut = FileDetailFragment.newInstance(file, user, 0)
  128. activity.addFragment(sut)
  129. waitForIdleSync()
  130. activity.runOnUiThread {
  131. sut.fileDetailActivitiesFragment.populateList(emptyList(), true)
  132. }
  133. shortSleep()
  134. shortSleep()
  135. screenshot(activity)
  136. }
  137. @Test
  138. @ScreenshotTest
  139. fun showDetailsActivitiesError() {
  140. val activity = testActivityRule.launchActivity(null)
  141. val sut = FileDetailFragment.newInstance(file, user, 0)
  142. activity.addFragment(sut)
  143. waitForIdleSync()
  144. activity.runOnUiThread {
  145. sut
  146. .fileDetailActivitiesFragment
  147. .setErrorContent(targetContext.resources.getString(R.string.file_detail_activity_error))
  148. }
  149. shortSleep()
  150. shortSleep()
  151. screenshot(activity)
  152. }
  153. @Test
  154. @ScreenshotTest
  155. fun showDetailsSharing() {
  156. val sut = testActivityRule.launchActivity(null)
  157. sut.addFragment(FileDetailFragment.newInstance(file, user, 1))
  158. waitForIdleSync()
  159. shortSleep()
  160. shortSleep()
  161. screenshot(sut)
  162. }
  163. }