AvatarIT.kt 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * Nextcloud Android client application
  3. *
  4. * @author Tobias Kaminsky
  5. * Copyright (C) 2020 Tobias Kaminsky
  6. * Copyright (C) 2020 Nextcloud GmbH
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. package com.owncloud.android.ui.fragment
  22. import android.graphics.BitmapFactory
  23. import androidx.test.espresso.intent.rule.IntentsTestRule
  24. import androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread
  25. import com.nextcloud.client.TestActivity
  26. import com.owncloud.android.AbstractIT
  27. import com.owncloud.android.R
  28. import com.owncloud.android.lib.resources.users.StatusType
  29. import com.owncloud.android.ui.TextDrawable
  30. import com.owncloud.android.utils.BitmapUtils
  31. import com.owncloud.android.utils.DisplayUtils
  32. import com.owncloud.android.utils.ScreenshotTest
  33. import org.junit.Rule
  34. import org.junit.Test
  35. class AvatarIT : AbstractIT() {
  36. @get:Rule
  37. val testActivityRule = IntentsTestRule(TestActivity::class.java, true, false)
  38. @Test
  39. @ScreenshotTest
  40. fun showAvatars() {
  41. val avatarRadius = targetContext.resources.getDimension(R.dimen.list_item_avatar_icon_radius)
  42. val width = DisplayUtils.convertDpToPixel(2 * avatarRadius, targetContext)
  43. val sut = testActivityRule.launchActivity(null)
  44. val fragment = AvatarTestFragment()
  45. sut.addFragment(fragment)
  46. runOnUiThread {
  47. fragment.addAvatar("Admin", avatarRadius, width, targetContext)
  48. fragment.addAvatar("Test Server Admin", avatarRadius, width, targetContext)
  49. fragment.addAvatar("Cormier Paulette", avatarRadius, width, targetContext)
  50. fragment.addAvatar("winston brent", avatarRadius, width, targetContext)
  51. fragment.addAvatar("Baker James Lorena", avatarRadius, width, targetContext)
  52. fragment.addAvatar("Baker James Lorena", avatarRadius, width, targetContext)
  53. fragment.addAvatar("email@server.com", avatarRadius, width, targetContext)
  54. }
  55. shortSleep()
  56. waitForIdleSync()
  57. screenshot(sut)
  58. }
  59. @Test
  60. @ScreenshotTest
  61. fun showAvatarsWithStatus() {
  62. val avatarRadius = targetContext.resources.getDimension(R.dimen.list_item_avatar_icon_radius)
  63. val width = DisplayUtils.convertDpToPixel(2 * avatarRadius, targetContext)
  64. val sut = testActivityRule.launchActivity(null)
  65. val fragment = AvatarTestFragment()
  66. val paulette = BitmapFactory.decodeFile(getFile("paulette.jpg").absolutePath)
  67. val christine = BitmapFactory.decodeFile(getFile("christine.jpg").absolutePath)
  68. val textBitmap = BitmapUtils.drawableToBitmap(TextDrawable.createNamedAvatar("Admin", avatarRadius))
  69. sut.addFragment(fragment)
  70. runOnUiThread {
  71. fragment.addBitmap(
  72. BitmapUtils.createAvatarWithStatus(paulette, StatusType.ONLINE, "😘", targetContext),
  73. width * 2,
  74. 1,
  75. targetContext
  76. )
  77. fragment.addBitmap(
  78. BitmapUtils.createAvatarWithStatus(christine, StatusType.ONLINE, "☁️", targetContext),
  79. width * 2,
  80. 1,
  81. targetContext
  82. )
  83. fragment.addBitmap(
  84. BitmapUtils.createAvatarWithStatus(christine, StatusType.ONLINE, "🌴️", targetContext),
  85. width * 2,
  86. 1,
  87. targetContext
  88. )
  89. fragment.addBitmap(
  90. BitmapUtils.createAvatarWithStatus(christine, StatusType.ONLINE, "", targetContext),
  91. width * 2,
  92. 1,
  93. targetContext
  94. )
  95. fragment.addBitmap(
  96. BitmapUtils.createAvatarWithStatus(paulette, StatusType.DND, "", targetContext),
  97. width * 2,
  98. 1,
  99. targetContext
  100. )
  101. fragment.addBitmap(
  102. BitmapUtils.createAvatarWithStatus(christine, StatusType.AWAY, "", targetContext),
  103. width * 2,
  104. 1,
  105. targetContext
  106. )
  107. fragment.addBitmap(
  108. BitmapUtils.createAvatarWithStatus(paulette, StatusType.OFFLINE, "", targetContext),
  109. width * 2,
  110. 1,
  111. targetContext
  112. )
  113. fragment.addBitmap(
  114. BitmapUtils.createAvatarWithStatus(textBitmap, StatusType.ONLINE, "😘", targetContext),
  115. width,
  116. 2,
  117. targetContext
  118. )
  119. fragment.addBitmap(
  120. BitmapUtils.createAvatarWithStatus(textBitmap, StatusType.ONLINE, "☁️", targetContext),
  121. width,
  122. 2,
  123. targetContext
  124. )
  125. fragment.addBitmap(
  126. BitmapUtils.createAvatarWithStatus(textBitmap, StatusType.ONLINE, "🌴️", targetContext),
  127. width,
  128. 2,
  129. targetContext
  130. )
  131. fragment.addBitmap(
  132. BitmapUtils.createAvatarWithStatus(textBitmap, StatusType.ONLINE, "", targetContext),
  133. width,
  134. 2,
  135. targetContext
  136. )
  137. fragment.addBitmap(
  138. BitmapUtils.createAvatarWithStatus(textBitmap, StatusType.DND, "", targetContext),
  139. width,
  140. 2,
  141. targetContext
  142. )
  143. fragment.addBitmap(
  144. BitmapUtils.createAvatarWithStatus(textBitmap, StatusType.AWAY, "", targetContext),
  145. width,
  146. 2,
  147. targetContext
  148. )
  149. fragment.addBitmap(
  150. BitmapUtils.createAvatarWithStatus(textBitmap, StatusType.OFFLINE, "", targetContext),
  151. width,
  152. 2,
  153. targetContext
  154. )
  155. }
  156. shortSleep()
  157. waitForIdleSync()
  158. screenshot(sut)
  159. }
  160. }