utils.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. import assert from 'assert';
  2. import { getPageTitle, getTitle, getModerationActions } from 'misago/components/threads/utils';
  3. import misago from 'misago/index';
  4. describe("Threads List Title Utils", function() {
  5. beforeEach(function() {
  6. // set default title
  7. misago._context = {
  8. CATEGORIES_ON_INDEX: false,
  9. SETTINGS: {
  10. forum_index_title: "",
  11. forum_name: "Test forum"
  12. }
  13. };
  14. });
  15. it("getPageTitle returns valid obj for title service", function() {
  16. assert.deepEqual(getPageTitle({
  17. list: {
  18. longName: "",
  19. path: ''
  20. },
  21. category: {
  22. name: "Test category"
  23. }
  24. }), {
  25. title: "Test category"
  26. }, "nonspecial category's name is returned");
  27. assert.deepEqual(getPageTitle({
  28. list: {
  29. longName: "New threads",
  30. path: 'new/'
  31. },
  32. category: {
  33. name: "Test category"
  34. }
  35. }), {
  36. title: "New threads",
  37. parent: "Test category"
  38. }, "list name under category name is returned");
  39. assert.equal(getPageTitle({
  40. list: {
  41. longName: "Threads",
  42. path: ''
  43. },
  44. category: {
  45. name: "Root",
  46. special_role: true
  47. }
  48. }), null, "null is returned for special category");
  49. assert.deepEqual(getPageTitle({
  50. list: {
  51. longName: "New threads",
  52. path: 'new/'
  53. },
  54. category: {
  55. name: "Root",
  56. special_role: true
  57. }
  58. }), {
  59. title: "New threads"
  60. }, "list name is returned for special category");
  61. misago._context.CATEGORIES_ON_INDEX = true;
  62. assert.deepEqual(getPageTitle({
  63. list: {
  64. longName: "",
  65. path: ''
  66. },
  67. category: {
  68. name: "Root",
  69. special_role: true
  70. }
  71. }), {
  72. title: "Threads"
  73. }, "fallback title is returned for special category");
  74. assert.deepEqual(getPageTitle({
  75. list: {
  76. longName: "New threads",
  77. path: 'new/'
  78. },
  79. category: {
  80. name: "Root",
  81. special_role: true
  82. }
  83. }), {
  84. title: "New threads",
  85. parent: "Threads"
  86. }, "list title under fallback is returned for special category");
  87. });
  88. it("getTitle returns valid title for header", function() {
  89. assert.equal(getTitle({
  90. category: {
  91. name: "Test category"
  92. }
  93. }), "Test category", "nonspecial category's name is returned as title");
  94. assert.equal(getTitle({
  95. category: {
  96. name: "Root",
  97. special_role: true
  98. }
  99. }), "Test forum", "forum name was used for title instead of category's");
  100. misago._context.SETTINGS.forum_index_title = "Forum index";
  101. assert.equal(getTitle({
  102. category: {
  103. name: "Root",
  104. special_role: true
  105. }
  106. }), "Forum index", "index title was used for title instead of category's");
  107. misago._context.CATEGORIES_ON_INDEX = true;
  108. assert.equal(getTitle({
  109. category: {
  110. name: "Root",
  111. special_role: true
  112. }
  113. }), "Threads", "fallback title was used for forum threads list");
  114. });
  115. });
  116. describe("Threads List Moderation Actions Util", function() {
  117. it("shows no moderation for no threads", function() {
  118. const moderationActions = getModerationActions([]);
  119. assert.ok(!moderationActions.allow, "moderation is unavaiable");
  120. });
  121. it("shows no moderation for unmoderable threads", function() {
  122. const moderationActions = getModerationActions([
  123. {
  124. acl: {
  125. can_approve: false,
  126. can_close: false,
  127. can_hide: false,
  128. can_merge: false,
  129. can_move: false,
  130. can_pin: false
  131. },
  132. is_unapproved: false
  133. }
  134. ]);
  135. assert.ok(!moderationActions.allow, "moderation is unavaiable");
  136. });
  137. it("shows moderation for unapproved approvable thread", function() {
  138. const moderationActions = getModerationActions([
  139. {
  140. acl: {
  141. can_approve: true,
  142. can_close: false,
  143. can_hide: false,
  144. can_merge: false,
  145. can_move: false,
  146. can_pin: false
  147. },
  148. is_unapproved: true
  149. }
  150. ]);
  151. assert.ok(moderationActions.allow, "moderation is allowed");
  152. assert.ok(moderationActions.can_approve, "approve action is available");
  153. });
  154. it("shows no moderation for approved approvable thread", function() {
  155. const moderationActions = getModerationActions([
  156. {
  157. acl: {
  158. can_approve: true,
  159. can_close: false,
  160. can_hide: false,
  161. can_merge: false,
  162. can_move: false,
  163. can_pin: false
  164. },
  165. is_unapproved: false
  166. }
  167. ]);
  168. assert.ok(!moderationActions.allow, "moderation is unavaiable");
  169. assert.ok(!moderationActions.can_approve, "approve action is unavaiable");
  170. });
  171. it("shows moderation for closing thread", function() {
  172. const moderationActions = getModerationActions([
  173. {
  174. acl: {
  175. can_approve: false,
  176. can_close: true,
  177. can_hide: false,
  178. can_merge: false,
  179. can_move: false,
  180. can_pin: false
  181. },
  182. is_unapproved: false
  183. }
  184. ]);
  185. assert.ok(moderationActions.allow, "moderation is allowed");
  186. assert.ok(moderationActions.can_close, "close action is available");
  187. });
  188. it("shows moderation for hiding thread", function() {
  189. const moderationActions = getModerationActions([
  190. {
  191. acl: {
  192. can_approve: false,
  193. can_close: false,
  194. can_hide: 1,
  195. can_merge: false,
  196. can_move: false,
  197. can_pin: false
  198. },
  199. is_unapproved: false
  200. }
  201. ]);
  202. assert.ok(moderationActions.allow, "moderation is allowed");
  203. assert.equal(moderationActions.can_hide, 1, "delete action is available");
  204. });
  205. it("shows moderation for deleting thread", function() {
  206. const moderationActions = getModerationActions([
  207. {
  208. acl: {
  209. can_approve: false,
  210. can_close: false,
  211. can_hide: 2,
  212. can_merge: false,
  213. can_move: false,
  214. can_pin: false
  215. },
  216. is_unapproved: false
  217. }
  218. ]);
  219. assert.ok(moderationActions.allow, "moderation is allowed");
  220. assert.equal(moderationActions.can_hide, 2, "delete action is available");
  221. });
  222. it("shows moderation for mergin thread", function() {
  223. const moderationActions = getModerationActions([
  224. {
  225. acl: {
  226. can_approve: false,
  227. can_close: false,
  228. can_hide: false,
  229. can_merge: true,
  230. can_move: false,
  231. can_pin: false
  232. },
  233. is_unapproved: false
  234. }
  235. ]);
  236. assert.ok(moderationActions.allow, "moderation is allowed");
  237. assert.ok(moderationActions.can_merge, "merge action is available");
  238. });
  239. it("shows moderation for moving thread", function() {
  240. const moderationActions = getModerationActions([
  241. {
  242. acl: {
  243. can_approve: false,
  244. can_close: false,
  245. can_hide: false,
  246. can_merge: false,
  247. can_move: true,
  248. can_pin: false
  249. },
  250. is_unapproved: false
  251. }
  252. ]);
  253. assert.ok(moderationActions.allow, "moderation is allowed");
  254. assert.ok(moderationActions.can_move, "move action is available");
  255. });
  256. it("shows moderation for pinning thread", function() {
  257. const moderationActions = getModerationActions([
  258. {
  259. acl: {
  260. can_approve: false,
  261. can_close: false,
  262. can_hide: false,
  263. can_merge: false,
  264. can_move: false,
  265. can_pin: 1
  266. },
  267. is_unapproved: false
  268. }
  269. ]);
  270. assert.ok(moderationActions.allow, "moderation is allowed");
  271. assert.equal(moderationActions.can_pin, 1, "pin action is available");
  272. });
  273. it("shows moderation for pinning thread globally", function() {
  274. const moderationActions = getModerationActions([
  275. {
  276. acl: {
  277. can_approve: false,
  278. can_close: false,
  279. can_hide: false,
  280. can_merge: false,
  281. can_move: false,
  282. can_pin: 2
  283. },
  284. is_unapproved: false
  285. }
  286. ]);
  287. assert.ok(moderationActions.allow, "moderation is allowed");
  288. assert.equal(moderationActions.can_pin, 2, "pin action is available");
  289. });
  290. it("shows moderation kitchensink", function() {
  291. const moderationActions = getModerationActions([
  292. {
  293. acl: {
  294. can_approve: true,
  295. can_close: true,
  296. can_hide: 2,
  297. can_merge: true,
  298. can_move: true,
  299. can_pin: 2
  300. },
  301. is_unapproved: true
  302. }
  303. ]);
  304. assert.deepEqual(moderationActions, {
  305. allow: true,
  306. can_approve: true,
  307. can_close: true,
  308. can_hide: 2,
  309. can_merge: true,
  310. can_move: true,
  311. can_pin: 2
  312. }, "moderation is allowed");
  313. });
  314. });