You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

issue_test.go 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package repo
  4. import (
  5. "testing"
  6. issues_model "code.gitea.io/gitea/models/issues"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestCombineLabelComments(t *testing.T) {
  10. kases := []struct {
  11. name string
  12. beforeCombined []*issues_model.Comment
  13. afterCombined []*issues_model.Comment
  14. }{
  15. {
  16. name: "kase 1",
  17. beforeCombined: []*issues_model.Comment{
  18. {
  19. Type: issues_model.CommentTypeLabel,
  20. PosterID: 1,
  21. Content: "1",
  22. Label: &issues_model.Label{
  23. Name: "kind/bug",
  24. },
  25. CreatedUnix: 0,
  26. },
  27. {
  28. Type: issues_model.CommentTypeLabel,
  29. PosterID: 1,
  30. Content: "",
  31. Label: &issues_model.Label{
  32. Name: "kind/bug",
  33. },
  34. CreatedUnix: 0,
  35. },
  36. {
  37. Type: issues_model.CommentTypeComment,
  38. PosterID: 1,
  39. Content: "test",
  40. CreatedUnix: 0,
  41. },
  42. },
  43. afterCombined: []*issues_model.Comment{
  44. {
  45. Type: issues_model.CommentTypeLabel,
  46. PosterID: 1,
  47. Content: "1",
  48. CreatedUnix: 0,
  49. AddedLabels: []*issues_model.Label{},
  50. Label: &issues_model.Label{
  51. Name: "kind/bug",
  52. },
  53. },
  54. {
  55. Type: issues_model.CommentTypeComment,
  56. PosterID: 1,
  57. Content: "test",
  58. CreatedUnix: 0,
  59. },
  60. },
  61. },
  62. {
  63. name: "kase 2",
  64. beforeCombined: []*issues_model.Comment{
  65. {
  66. Type: issues_model.CommentTypeLabel,
  67. PosterID: 1,
  68. Content: "1",
  69. Label: &issues_model.Label{
  70. Name: "kind/bug",
  71. },
  72. CreatedUnix: 0,
  73. },
  74. {
  75. Type: issues_model.CommentTypeLabel,
  76. PosterID: 1,
  77. Content: "",
  78. Label: &issues_model.Label{
  79. Name: "kind/bug",
  80. },
  81. CreatedUnix: 70,
  82. },
  83. {
  84. Type: issues_model.CommentTypeComment,
  85. PosterID: 1,
  86. Content: "test",
  87. CreatedUnix: 0,
  88. },
  89. },
  90. afterCombined: []*issues_model.Comment{
  91. {
  92. Type: issues_model.CommentTypeLabel,
  93. PosterID: 1,
  94. Content: "1",
  95. CreatedUnix: 0,
  96. AddedLabels: []*issues_model.Label{
  97. {
  98. Name: "kind/bug",
  99. },
  100. },
  101. Label: &issues_model.Label{
  102. Name: "kind/bug",
  103. },
  104. },
  105. {
  106. Type: issues_model.CommentTypeLabel,
  107. PosterID: 1,
  108. Content: "",
  109. CreatedUnix: 70,
  110. RemovedLabels: []*issues_model.Label{
  111. {
  112. Name: "kind/bug",
  113. },
  114. },
  115. Label: &issues_model.Label{
  116. Name: "kind/bug",
  117. },
  118. },
  119. {
  120. Type: issues_model.CommentTypeComment,
  121. PosterID: 1,
  122. Content: "test",
  123. CreatedUnix: 0,
  124. },
  125. },
  126. },
  127. {
  128. name: "kase 3",
  129. beforeCombined: []*issues_model.Comment{
  130. {
  131. Type: issues_model.CommentTypeLabel,
  132. PosterID: 1,
  133. Content: "1",
  134. Label: &issues_model.Label{
  135. Name: "kind/bug",
  136. },
  137. CreatedUnix: 0,
  138. },
  139. {
  140. Type: issues_model.CommentTypeLabel,
  141. PosterID: 2,
  142. Content: "",
  143. Label: &issues_model.Label{
  144. Name: "kind/bug",
  145. },
  146. CreatedUnix: 0,
  147. },
  148. {
  149. Type: issues_model.CommentTypeComment,
  150. PosterID: 1,
  151. Content: "test",
  152. CreatedUnix: 0,
  153. },
  154. },
  155. afterCombined: []*issues_model.Comment{
  156. {
  157. Type: issues_model.CommentTypeLabel,
  158. PosterID: 1,
  159. Content: "1",
  160. CreatedUnix: 0,
  161. AddedLabels: []*issues_model.Label{
  162. {
  163. Name: "kind/bug",
  164. },
  165. },
  166. Label: &issues_model.Label{
  167. Name: "kind/bug",
  168. },
  169. },
  170. {
  171. Type: issues_model.CommentTypeLabel,
  172. PosterID: 2,
  173. Content: "",
  174. CreatedUnix: 0,
  175. RemovedLabels: []*issues_model.Label{
  176. {
  177. Name: "kind/bug",
  178. },
  179. },
  180. Label: &issues_model.Label{
  181. Name: "kind/bug",
  182. },
  183. },
  184. {
  185. Type: issues_model.CommentTypeComment,
  186. PosterID: 1,
  187. Content: "test",
  188. CreatedUnix: 0,
  189. },
  190. },
  191. },
  192. {
  193. name: "kase 4",
  194. beforeCombined: []*issues_model.Comment{
  195. {
  196. Type: issues_model.CommentTypeLabel,
  197. PosterID: 1,
  198. Content: "1",
  199. Label: &issues_model.Label{
  200. Name: "kind/bug",
  201. },
  202. CreatedUnix: 0,
  203. },
  204. {
  205. Type: issues_model.CommentTypeLabel,
  206. PosterID: 1,
  207. Content: "1",
  208. Label: &issues_model.Label{
  209. Name: "kind/backport",
  210. },
  211. CreatedUnix: 10,
  212. },
  213. },
  214. afterCombined: []*issues_model.Comment{
  215. {
  216. Type: issues_model.CommentTypeLabel,
  217. PosterID: 1,
  218. Content: "1",
  219. CreatedUnix: 10,
  220. AddedLabels: []*issues_model.Label{
  221. {
  222. Name: "kind/bug",
  223. },
  224. {
  225. Name: "kind/backport",
  226. },
  227. },
  228. Label: &issues_model.Label{
  229. Name: "kind/bug",
  230. },
  231. },
  232. },
  233. },
  234. {
  235. name: "kase 5",
  236. beforeCombined: []*issues_model.Comment{
  237. {
  238. Type: issues_model.CommentTypeLabel,
  239. PosterID: 1,
  240. Content: "1",
  241. Label: &issues_model.Label{
  242. Name: "kind/bug",
  243. },
  244. CreatedUnix: 0,
  245. },
  246. {
  247. Type: issues_model.CommentTypeComment,
  248. PosterID: 2,
  249. Content: "testtest",
  250. CreatedUnix: 0,
  251. },
  252. {
  253. Type: issues_model.CommentTypeLabel,
  254. PosterID: 1,
  255. Content: "",
  256. Label: &issues_model.Label{
  257. Name: "kind/bug",
  258. },
  259. CreatedUnix: 0,
  260. },
  261. },
  262. afterCombined: []*issues_model.Comment{
  263. {
  264. Type: issues_model.CommentTypeLabel,
  265. PosterID: 1,
  266. Content: "1",
  267. Label: &issues_model.Label{
  268. Name: "kind/bug",
  269. },
  270. AddedLabels: []*issues_model.Label{
  271. {
  272. Name: "kind/bug",
  273. },
  274. },
  275. CreatedUnix: 0,
  276. },
  277. {
  278. Type: issues_model.CommentTypeComment,
  279. PosterID: 2,
  280. Content: "testtest",
  281. CreatedUnix: 0,
  282. },
  283. {
  284. Type: issues_model.CommentTypeLabel,
  285. PosterID: 1,
  286. Content: "",
  287. RemovedLabels: []*issues_model.Label{
  288. {
  289. Name: "kind/bug",
  290. },
  291. },
  292. Label: &issues_model.Label{
  293. Name: "kind/bug",
  294. },
  295. CreatedUnix: 0,
  296. },
  297. },
  298. },
  299. {
  300. name: "kase 6",
  301. beforeCombined: []*issues_model.Comment{
  302. {
  303. Type: issues_model.CommentTypeLabel,
  304. PosterID: 1,
  305. Content: "1",
  306. Label: &issues_model.Label{
  307. Name: "kind/bug",
  308. },
  309. CreatedUnix: 0,
  310. },
  311. {
  312. Type: issues_model.CommentTypeLabel,
  313. PosterID: 1,
  314. Content: "1",
  315. Label: &issues_model.Label{
  316. Name: "reviewed/confirmed",
  317. },
  318. CreatedUnix: 0,
  319. },
  320. {
  321. Type: issues_model.CommentTypeLabel,
  322. PosterID: 1,
  323. Content: "",
  324. Label: &issues_model.Label{
  325. Name: "kind/bug",
  326. },
  327. CreatedUnix: 0,
  328. },
  329. {
  330. Type: issues_model.CommentTypeLabel,
  331. PosterID: 1,
  332. Content: "1",
  333. Label: &issues_model.Label{
  334. Name: "kind/feature",
  335. },
  336. CreatedUnix: 0,
  337. },
  338. },
  339. afterCombined: []*issues_model.Comment{
  340. {
  341. Type: issues_model.CommentTypeLabel,
  342. PosterID: 1,
  343. Content: "1",
  344. Label: &issues_model.Label{
  345. Name: "kind/bug",
  346. },
  347. AddedLabels: []*issues_model.Label{
  348. {
  349. Name: "reviewed/confirmed",
  350. },
  351. {
  352. Name: "kind/feature",
  353. },
  354. },
  355. CreatedUnix: 0,
  356. },
  357. },
  358. },
  359. }
  360. for _, kase := range kases {
  361. t.Run(kase.name, func(t *testing.T) {
  362. issue := issues_model.Issue{
  363. Comments: kase.beforeCombined,
  364. }
  365. combineLabelComments(&issue)
  366. assert.EqualValues(t, kase.afterCombined, issue.Comments)
  367. })
  368. }
  369. }