utils.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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_move: false,
  129. can_pin: false
  130. },
  131. is_unapproved: false
  132. }
  133. ]);
  134. assert.ok(!moderationActions.allow, "moderation is unavaiable");
  135. });
  136. it("shows moderation for unapproved approvable thread", function() {
  137. const moderationActions = getModerationActions([
  138. {
  139. acl: {
  140. can_approve: true,
  141. can_close: false,
  142. can_hide: false,
  143. can_move: false,
  144. can_pin: false
  145. },
  146. is_unapproved: true
  147. }
  148. ]);
  149. assert.ok(moderationActions.allow, "moderation is allowed");
  150. assert.ok(moderationActions.can_approve, "approve action is available");
  151. });
  152. it("shows no moderation for approved approvable thread", function() {
  153. const moderationActions = getModerationActions([
  154. {
  155. acl: {
  156. can_approve: true,
  157. can_close: false,
  158. can_hide: false,
  159. can_move: false,
  160. can_pin: false
  161. },
  162. is_unapproved: false
  163. }
  164. ]);
  165. assert.ok(!moderationActions.allow, "moderation is unavaiable");
  166. assert.ok(!moderationActions.can_approve, "approve action is unavaiable");
  167. });
  168. it("shows moderation for closing thread", function() {
  169. const moderationActions = getModerationActions([
  170. {
  171. acl: {
  172. can_approve: false,
  173. can_close: true,
  174. can_hide: false,
  175. can_move: false,
  176. can_pin: false
  177. },
  178. is_unapproved: false
  179. }
  180. ]);
  181. assert.ok(moderationActions.allow, "moderation is allowed");
  182. assert.ok(moderationActions.can_close, "close action is available");
  183. });
  184. it("shows moderation for hiding thread", function() {
  185. const moderationActions = getModerationActions([
  186. {
  187. acl: {
  188. can_approve: false,
  189. can_close: false,
  190. can_hide: 1,
  191. can_move: false,
  192. can_pin: false
  193. },
  194. is_unapproved: false
  195. }
  196. ]);
  197. assert.ok(moderationActions.allow, "moderation is allowed");
  198. assert.equal(moderationActions.can_hide, 1, "delete action is available");
  199. });
  200. it("shows moderation for deleting thread", function() {
  201. const moderationActions = getModerationActions([
  202. {
  203. acl: {
  204. can_approve: false,
  205. can_close: false,
  206. can_hide: 2,
  207. can_move: false,
  208. can_pin: false
  209. },
  210. is_unapproved: false
  211. }
  212. ]);
  213. assert.ok(moderationActions.allow, "moderation is allowed");
  214. assert.equal(moderationActions.can_hide, 2, "delete action is available");
  215. });
  216. it("shows moderation for moving thread", function() {
  217. const moderationActions = getModerationActions([
  218. {
  219. acl: {
  220. can_approve: false,
  221. can_close: false,
  222. can_hide: false,
  223. can_move: true,
  224. can_pin: false
  225. },
  226. is_unapproved: false
  227. }
  228. ]);
  229. assert.ok(moderationActions.allow, "moderation is allowed");
  230. assert.ok(moderationActions.can_move, "move action is available");
  231. });
  232. it("shows moderation for pinning thread", function() {
  233. const moderationActions = getModerationActions([
  234. {
  235. acl: {
  236. can_approve: false,
  237. can_close: false,
  238. can_hide: false,
  239. can_move: false,
  240. can_pin: 1
  241. },
  242. is_unapproved: false
  243. }
  244. ]);
  245. assert.ok(moderationActions.allow, "moderation is allowed");
  246. assert.equal(moderationActions.can_pin, 1, "pin action is available");
  247. });
  248. it("shows moderation for pinning thread globally", function() {
  249. const moderationActions = getModerationActions([
  250. {
  251. acl: {
  252. can_approve: false,
  253. can_close: false,
  254. can_hide: false,
  255. can_move: false,
  256. can_pin: 2
  257. },
  258. is_unapproved: false
  259. }
  260. ]);
  261. assert.ok(moderationActions.allow, "moderation is allowed");
  262. assert.equal(moderationActions.can_pin, 2, "pin action is available");
  263. });
  264. it("shows moderation kitchensink", function() {
  265. const moderationActions = getModerationActions([
  266. {
  267. acl: {
  268. can_approve: true,
  269. can_close: true,
  270. can_hide: 2,
  271. can_move: true,
  272. can_pin: 2
  273. },
  274. is_unapproved: true
  275. }
  276. ]);
  277. assert.deepEqual(moderationActions, {
  278. allow: true,
  279. can_approve: true,
  280. can_close: true,
  281. can_hide: 2,
  282. can_move: true,
  283. can_pin: 2
  284. }, "moderation is allowed");
  285. });
  286. });