modtools.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. /*global mock, converse, _ */
  2. const $iq = converse.env.$iq;
  3. const $pres = converse.env.$pres;
  4. const sizzle = converse.env.sizzle;
  5. const Strophe = converse.env.Strophe;
  6. const u = converse.env.utils;
  7. async function openModtools (_converse, view) {
  8. const textarea = await u.waitUntil(() => view.querySelector('.chat-textarea'));
  9. textarea.value = '/modtools';
  10. const enter = { 'target': textarea, 'preventDefault': function preventDefault () {}, 'keyCode': 13 };
  11. const bottom_panel = view.querySelector('converse-muc-bottom-panel');
  12. bottom_panel.onKeyDown(enter);
  13. const modal = await u.waitUntil(() => _converse.api.modal.get('converse-modtools-modal'));
  14. await u.waitUntil(() => u.isVisible(modal.el), 1000);
  15. return modal;
  16. }
  17. describe("The groupchat moderator tool", function () {
  18. it("allows you to set affiliations and roles",
  19. mock.initConverse([], {}, async function (done, _converse) {
  20. const muc_jid = 'lounge@montague.lit';
  21. let members = [
  22. {'jid': 'hag66@shakespeare.lit', 'nick': 'witch', 'affiliation': 'member'},
  23. {'jid': 'gower@shakespeare.lit', 'nick': 'gower', 'affiliation': 'member'},
  24. {'jid': 'wiccarocks@shakespeare.lit', 'nick': 'wiccan', 'affiliation': 'admin'},
  25. {'jid': 'crone1@shakespeare.lit', 'nick': 'thirdwitch', 'affiliation': 'owner'},
  26. {'jid': 'romeo@montague.lit', 'nick': 'romeo', 'affiliation': 'owner'},
  27. ];
  28. await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo', [], members);
  29. const view = _converse.chatboxviews.get(muc_jid);
  30. await u.waitUntil(() => (view.model.occupants.length === 5), 1000);
  31. const modal = await openModtools(_converse, view);
  32. let tab = modal.el.querySelector('#affiliations-tab');
  33. // Clear so that we don't match older stanzas
  34. _converse.connection.IQ_stanzas = [];
  35. tab.click();
  36. let select = modal.el.querySelector('.select-affiliation');
  37. expect(select.value).toBe('owner');
  38. select.value = 'admin';
  39. let button = modal.el.querySelector('.btn-primary[name="users_with_affiliation"]');
  40. button.click();
  41. await u.waitUntil(() => !modal.loading_users_with_affiliation);
  42. let user_els = modal.el.querySelectorAll('.list-group--users > li');
  43. expect(user_els.length).toBe(1);
  44. expect(user_els[0].querySelector('.list-group-item.active').textContent.trim()).toBe('JID: wiccarocks@shakespeare.lit');
  45. expect(user_els[0].querySelector('.list-group-item:nth-child(2n)').textContent.trim()).toBe('Nickname: wiccan');
  46. expect(user_els[0].querySelector('.list-group-item:nth-child(3n) div').textContent.trim()).toBe('Affiliation: admin');
  47. _converse.connection.IQ_stanzas = [];
  48. select.value = 'owner';
  49. button.click();
  50. await u.waitUntil(() => !modal.loading_users_with_affiliation);
  51. user_els = modal.el.querySelectorAll('.list-group--users > li');
  52. expect(user_els.length).toBe(2);
  53. expect(user_els[0].querySelector('.list-group-item.active').textContent.trim()).toBe('JID: romeo@montague.lit');
  54. expect(user_els[0].querySelector('.list-group-item:nth-child(2n)').textContent.trim()).toBe('Nickname: romeo');
  55. expect(user_els[0].querySelector('.list-group-item:nth-child(3n) div').textContent.trim()).toBe('Affiliation: owner');
  56. expect(user_els[1].querySelector('.list-group-item.active').textContent.trim()).toBe('JID: crone1@shakespeare.lit');
  57. expect(user_els[1].querySelector('.list-group-item:nth-child(2n)').textContent.trim()).toBe('Nickname: thirdwitch');
  58. expect(user_els[1].querySelector('.list-group-item:nth-child(3n) div').textContent.trim()).toBe('Affiliation: owner');
  59. const toggle = user_els[1].querySelector('.list-group-item:nth-child(3n) .toggle-form');
  60. const form = user_els[1].querySelector('.list-group-item:nth-child(3n) .affiliation-form');
  61. expect(u.hasClass('hidden', form)).toBeTruthy();
  62. toggle.click();
  63. expect(u.hasClass('hidden', form)).toBeFalsy();
  64. select = form.querySelector('.select-affiliation');
  65. expect(select.value).toBe('owner');
  66. select.value = 'admin';
  67. const input = form.querySelector('input[name="reason"]');
  68. input.value = "You're an admin now";
  69. const submit = form.querySelector('.btn-primary');
  70. submit.click();
  71. spyOn(_converse.ChatRoomOccupants.prototype, 'fetchMembers').and.callThrough();
  72. const sent_IQ = _converse.connection.IQ_stanzas.pop();
  73. expect(Strophe.serialize(sent_IQ)).toBe(
  74. `<iq id="${sent_IQ.getAttribute('id')}" to="lounge@montague.lit" type="set" xmlns="jabber:client">`+
  75. `<query xmlns="http://jabber.org/protocol/muc#admin">`+
  76. `<item affiliation="admin" jid="crone1@shakespeare.lit">`+
  77. `<reason>You&apos;re an admin now</reason>`+
  78. `</item>`+
  79. `</query>`+
  80. `</iq>`);
  81. _converse.connection.IQ_stanzas = [];
  82. const stanza = $iq({
  83. 'type': 'result',
  84. 'id': sent_IQ.getAttribute('id'),
  85. 'from': view.model.get('jid'),
  86. 'to': _converse.connection.jid
  87. });
  88. _converse.connection._dataRecv(mock.createRequest(stanza));
  89. await u.waitUntil(() => view.model.occupants.fetchMembers.calls.count());
  90. members = [
  91. {'jid': 'hag66@shakespeare.lit', 'nick': 'witch', 'affiliation': 'member'},
  92. {'jid': 'gower@shakespeare.lit', 'nick': 'gower', 'affiliation': 'member'},
  93. {'jid': 'wiccarocks@shakespeare.lit', 'nick': 'wiccan', 'affiliation': 'admin'},
  94. {'jid': 'crone1@shakespeare.lit', 'nick': 'thirdwitch', 'affiliation': 'admin'},
  95. {'jid': 'romeo@montague.lit', 'nick': 'romeo', 'affiliation': 'owner'},
  96. ];
  97. await mock.returnMemberLists(_converse, muc_jid, members);
  98. await u.waitUntil(() => view.model.occupants.pluck('affiliation').filter(o => o === 'owner').length === 1);
  99. const alert = modal.el.querySelector('.alert-primary');
  100. expect(alert.textContent.trim()).toBe('Affiliation changed');
  101. user_els = modal.el.querySelectorAll('.list-group--users > li');
  102. expect(user_els.length).toBe(1);
  103. expect(user_els[0].querySelector('.list-group-item.active').textContent.trim()).toBe('JID: romeo@montague.lit');
  104. expect(user_els[0].querySelector('.list-group-item:nth-child(2n)').textContent.trim()).toBe('Nickname: romeo');
  105. expect(user_els[0].querySelector('.list-group-item:nth-child(3n) div').textContent.trim()).toBe('Affiliation: owner');
  106. tab = modal.el.querySelector('#roles-tab');
  107. tab.click();
  108. select = modal.el.querySelector('.select-role');
  109. expect(u.isVisible(select)).toBe(true);
  110. expect(select.value).toBe('moderator');
  111. button = modal.el.querySelector('.btn-primary[name="users_with_role"]');
  112. button.click();
  113. const roles_panel = modal.el.querySelector('#roles-tabpanel');
  114. await u.waitUntil(() => roles_panel.querySelectorAll('.list-group--users > li').length === 1);
  115. select.value = 'participant';
  116. button.click();
  117. await u.waitUntil(() => !modal.loading_users_with_affiliation);
  118. user_els = roles_panel.querySelectorAll('.list-group--users > li')
  119. expect(user_els.length).toBe(1);
  120. expect(user_els[0].textContent.trim()).toBe('No users with that role found.');
  121. done();
  122. }));
  123. it("allows you to filter affiliation search results",
  124. mock.initConverse([], {}, async function (done, _converse) {
  125. const muc_jid = 'lounge@montague.lit';
  126. const members = [
  127. {'jid': 'hag66@shakespeare.lit', 'nick': 'witch', 'affiliation': 'member'},
  128. {'jid': 'gower@shakespeare.lit', 'nick': 'gower', 'affiliation': 'member'},
  129. {'jid': 'wiccarocks@shakespeare.lit', 'nick': 'wiccan', 'affiliation': 'member'},
  130. {'jid': 'crone1@shakespeare.lit', 'nick': 'thirdwitch', 'affiliation': 'member'},
  131. {'jid': 'romeo@montague.lit', 'nick': 'romeo', 'affiliation': 'member'},
  132. {'jid': 'juliet@capulet.lit', 'nick': 'juliet', 'affiliation': 'member'},
  133. ];
  134. await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo', [], members);
  135. const view = _converse.chatboxviews.get(muc_jid);
  136. await u.waitUntil(() => (view.model.occupants.length === 6), 1000);
  137. // Clear so that we don't match older stanzas
  138. _converse.connection.IQ_stanzas = [];
  139. const modal = await openModtools(_converse, view);
  140. const select = modal.el.querySelector('.select-affiliation');
  141. expect(select.value).toBe('owner');
  142. select.value = 'member';
  143. const button = modal.el.querySelector('.btn-primary[name="users_with_affiliation"]');
  144. button.click();
  145. await u.waitUntil(() => !modal.loading_users_with_affiliation);
  146. const user_els = modal.el.querySelectorAll('.list-group--users > li');
  147. expect(user_els.length).toBe(6);
  148. const nicks = Array.from(modal.el.querySelectorAll('.list-group--users > li')).map(el => el.getAttribute('data-nick'));
  149. expect(nicks.join(' ')).toBe('gower juliet romeo thirdwitch wiccan witch');
  150. const filter = modal.el.querySelector('[name="filter"]');
  151. expect(filter).not.toBe(null);
  152. filter.value = 'romeo';
  153. u.triggerEvent(filter, "keyup", "KeyboardEvent");
  154. await u.waitUntil(() => ( modal.el.querySelectorAll('.list-group--users > li').length === 1));
  155. filter.value = 'r';
  156. u.triggerEvent(filter, "keyup", "KeyboardEvent");
  157. await u.waitUntil(() => ( modal.el.querySelectorAll('.list-group--users > li').length === 3));
  158. filter.value = 'gower';
  159. u.triggerEvent(filter, "keyup", "KeyboardEvent");
  160. await u.waitUntil(() => ( modal.el.querySelectorAll('.list-group--users > li').length === 1));
  161. filter.value = 'RoMeO';
  162. u.triggerEvent(filter, "keyup", "KeyboardEvent");
  163. await u.waitUntil(() => ( modal.el.querySelectorAll('.list-group--users > li').length === 1));
  164. done();
  165. }));
  166. it("allows you to filter role search results",
  167. mock.initConverse([], {}, async function (done, _converse) {
  168. const muc_jid = 'lounge@montague.lit';
  169. await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo', []);
  170. const view = _converse.chatboxviews.get(muc_jid);
  171. _converse.connection._dataRecv(mock.createRequest(
  172. $pres({to: _converse.jid, from: `${muc_jid}/nomorenicks`})
  173. .c('x', {xmlns: Strophe.NS.MUC_USER})
  174. .c('item', {
  175. 'affiliation': 'none',
  176. 'jid': `nomorenicks@montague.lit`,
  177. 'role': 'participant'
  178. })
  179. ));
  180. _converse.connection._dataRecv(mock.createRequest(
  181. $pres({to: _converse.jid, from: `${muc_jid}/newb`})
  182. .c('x', {xmlns: Strophe.NS.MUC_USER})
  183. .c('item', {
  184. 'affiliation': 'none',
  185. 'jid': `newb@montague.lit`,
  186. 'role': 'participant'
  187. })
  188. ));
  189. _converse.connection._dataRecv(mock.createRequest(
  190. $pres({to: _converse.jid, from: `${muc_jid}/some1`})
  191. .c('x', {xmlns: Strophe.NS.MUC_USER})
  192. .c('item', {
  193. 'affiliation': 'none',
  194. 'jid': `some1@montague.lit`,
  195. 'role': 'participant'
  196. })
  197. ));
  198. _converse.connection._dataRecv(mock.createRequest(
  199. $pres({to: _converse.jid, from: `${muc_jid}/oldhag`})
  200. .c('x', {xmlns: Strophe.NS.MUC_USER})
  201. .c('item', {
  202. 'affiliation': 'none',
  203. 'jid': `oldhag@montague.lit`,
  204. 'role': 'participant'
  205. })
  206. ));
  207. _converse.connection._dataRecv(mock.createRequest(
  208. $pres({to: _converse.jid, from: `${muc_jid}/crone`})
  209. .c('x', {xmlns: Strophe.NS.MUC_USER})
  210. .c('item', {
  211. 'affiliation': 'none',
  212. 'jid': `crone@montague.lit`,
  213. 'role': 'participant'
  214. })
  215. ));
  216. _converse.connection._dataRecv(mock.createRequest(
  217. $pres({to: _converse.jid, from: `${muc_jid}/tux`})
  218. .c('x', {xmlns: Strophe.NS.MUC_USER})
  219. .c('item', {
  220. 'affiliation': 'none',
  221. 'jid': `tux@montague.lit`,
  222. 'role': 'participant'
  223. })
  224. ));
  225. await u.waitUntil(() => (view.model.occupants.length === 7), 1000);
  226. const textarea = await u.waitUntil(() => view.querySelector('.chat-textarea'));
  227. textarea.value = '/modtools';
  228. const enter = { 'target': textarea, 'preventDefault': function preventDefault () {}, 'keyCode': 13 };
  229. const bottom_panel = view.querySelector('converse-muc-bottom-panel');
  230. bottom_panel.onKeyDown(enter);
  231. const modal = await u.waitUntil(() => _converse.api.modal.get('converse-modtools-modal'));
  232. await u.waitUntil(() => u.isVisible(modal.el), 1000);
  233. const tab = modal.el.querySelector('#roles-tab');
  234. tab.click();
  235. // Clear so that we don't match older stanzas
  236. _converse.connection.IQ_stanzas = [];
  237. const select = modal.el.querySelector('.select-role');
  238. expect(select.value).toBe('moderator');
  239. select.value = 'participant';
  240. const button = modal.el.querySelector('.btn-primary[name="users_with_role"]');
  241. button.click();
  242. await u.waitUntil(() => !modal.loading_users_with_role);
  243. const user_els = modal.el.querySelectorAll('.list-group--users > li');
  244. expect(user_els.length).toBe(6);
  245. const nicks = Array.from(modal.el.querySelectorAll('.list-group--users > li')).map(el => el.getAttribute('data-nick'));
  246. expect(nicks.join(' ')).toBe('crone newb nomorenicks oldhag some1 tux');
  247. const filter = modal.el.querySelector('[name="filter"]');
  248. expect(filter).not.toBe(null);
  249. filter.value = 'tux';
  250. u.triggerEvent(filter, "keyup", "KeyboardEvent");
  251. await u.waitUntil(() => ( modal.el.querySelectorAll('.list-group--users > li').length === 1));
  252. filter.value = 'r';
  253. u.triggerEvent(filter, "keyup", "KeyboardEvent");
  254. await u.waitUntil(() => ( modal.el.querySelectorAll('.list-group--users > li').length === 2));
  255. filter.value = 'crone';
  256. u.triggerEvent(filter, "keyup", "KeyboardEvent");
  257. await u.waitUntil(() => ( modal.el.querySelectorAll('.list-group--users > li').length === 1));
  258. done();
  259. }));
  260. it("shows an error message if a particular affiliation list may not be retrieved",
  261. mock.initConverse([], {}, async function (done, _converse) {
  262. const muc_jid = 'lounge@montague.lit';
  263. const members = [
  264. {'jid': 'hag66@shakespeare.lit', 'nick': 'witch', 'affiliation': 'member'},
  265. {'jid': 'gower@shakespeare.lit', 'nick': 'gower', 'affiliation': 'member'},
  266. {'jid': 'wiccarocks@shakespeare.lit', 'nick': 'wiccan', 'affiliation': 'admin'},
  267. {'jid': 'crone1@shakespeare.lit', 'nick': 'thirdwitch', 'affiliation': 'owner'},
  268. {'jid': 'romeo@montague.lit', 'nick': 'romeo', 'affiliation': 'owner'},
  269. ];
  270. await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo', [], members);
  271. const view = _converse.chatboxviews.get(muc_jid);
  272. await u.waitUntil(() => (view.model.occupants.length === 5));
  273. const modal = await openModtools(_converse, view);
  274. const tab = modal.el.querySelector('#affiliations-tab');
  275. // Clear so that we don't match older stanzas
  276. _converse.connection.IQ_stanzas = [];
  277. const IQ_stanzas = _converse.connection.IQ_stanzas;
  278. tab.click();
  279. const select = modal.el.querySelector('.select-affiliation');
  280. select.value = 'outcast';
  281. const button = modal.el.querySelector('.btn-primary[name="users_with_affiliation"]');
  282. button.click();
  283. const iq_query = await u.waitUntil(() => _.filter(
  284. IQ_stanzas,
  285. s => sizzle(`iq[to="${muc_jid}"] query[xmlns="${Strophe.NS.MUC_ADMIN}"] item[affiliation="outcast"]`, s).length
  286. ).pop());
  287. const error = u.toStanza(
  288. `<iq from="${muc_jid}"
  289. id="${iq_query.getAttribute('id')}"
  290. type="error"
  291. to="${_converse.jid}">
  292. <error type="auth">
  293. <forbidden xmlns="${Strophe.NS.STANZAS}"/>
  294. </error>
  295. </iq>`);
  296. _converse.connection._dataRecv(mock.createRequest(error));
  297. await u.waitUntil(() => !modal.loading_users_with_affiliation);
  298. const user_els = modal.el.querySelectorAll('.list-group--users > li');
  299. expect(user_els.length).toBe(1);
  300. expect(user_els[0].textContent.trim()).toBe('Error: not allowed to fetch outcast list for MUC lounge@montague.lit');
  301. done();
  302. }));
  303. it("shows an error message if a particular affiliation may not be set",
  304. mock.initConverse([], {}, async function (done, _converse) {
  305. const muc_jid = 'lounge@montague.lit';
  306. const members = [
  307. {'jid': 'gower@shakespeare.lit', 'nick': 'gower', 'affiliation': 'member'},
  308. {'jid': 'romeo@montague.lit', 'nick': 'romeo', 'affiliation': 'owner'},
  309. ];
  310. await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo', [], members);
  311. const view = _converse.chatboxviews.get(muc_jid);
  312. await u.waitUntil(() => (view.model.occupants.length === 2));
  313. const modal = await openModtools(_converse, view);
  314. // Clear so that we don't match older stanzas
  315. _converse.connection.IQ_stanzas = [];
  316. const tab = modal.el.querySelector('#affiliations-tab');
  317. tab.click();
  318. const select = modal.el.querySelector('.select-affiliation');
  319. select.value = 'member';
  320. const button = modal.el.querySelector('.btn-primary[name="users_with_affiliation"]');
  321. button.click();
  322. await u.waitUntil(() => !modal.loading_users_with_affiliation);
  323. const user_els = modal.el.querySelectorAll('.list-group--users > li');
  324. expect(user_els.length).toBe(1);
  325. const toggle = user_els[0].querySelector('.list-group-item:nth-child(3n) .toggle-form');
  326. const form = user_els[0].querySelector('.list-group-item:nth-child(3n) .affiliation-form');
  327. expect(u.hasClass('hidden', form)).toBeTruthy();
  328. toggle.click();
  329. expect(u.hasClass('hidden', form)).toBeFalsy();
  330. const change_affiliation_dropdown = form.querySelector('.select-affiliation');
  331. expect(change_affiliation_dropdown.value).toBe('member');
  332. change_affiliation_dropdown.value = 'admin';
  333. const input = form.querySelector('input[name="reason"]');
  334. input.value = "You're an admin now";
  335. const submit = form.querySelector('.btn-primary');
  336. submit.click();
  337. const sent_IQ = _converse.connection.IQ_stanzas.pop();
  338. expect(Strophe.serialize(sent_IQ)).toBe(
  339. `<iq id="${sent_IQ.getAttribute('id')}" to="lounge@montague.lit" type="set" xmlns="jabber:client">`+
  340. `<query xmlns="http://jabber.org/protocol/muc#admin">`+
  341. `<item affiliation="admin" jid="gower@shakespeare.lit">`+
  342. `<reason>You&apos;re an admin now</reason>`+
  343. `</item>`+
  344. `</query>`+
  345. `</iq>`);
  346. const error = u.toStanza(
  347. `<iq from="${muc_jid}"
  348. id="${sent_IQ.getAttribute('id')}"
  349. type="error"
  350. to="${_converse.jid}">
  351. <error type="cancel">
  352. <not-allowed xmlns="${Strophe.NS.STANZAS}"/>
  353. </error>
  354. </iq>`);
  355. _converse.connection._dataRecv(mock.createRequest(error));
  356. done();
  357. }));
  358. it("doesn't allow admins to make more admins",
  359. mock.initConverse([], {}, async function (done, _converse) {
  360. const muc_jid = 'lounge@montague.lit';
  361. const members = [
  362. {'jid': 'hag66@shakespeare.lit', 'nick': 'witch', 'affiliation': 'member'},
  363. {'jid': 'gower@shakespeare.lit', 'nick': 'gower', 'affiliation': 'member'},
  364. {'jid': 'romeo@montague.lit', 'nick': 'romeo', 'affiliation': 'admin'},
  365. ];
  366. await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo', [], members);
  367. const view = _converse.chatboxviews.get(muc_jid);
  368. await u.waitUntil(() => (view.model.occupants.length === 3));
  369. const modal = await openModtools(_converse, view);
  370. const tab = modal.el.querySelector('#affiliations-tab');
  371. // Clear so that we don't match older stanzas
  372. _converse.connection.IQ_stanzas = [];
  373. tab.click();
  374. const show_affiliation_dropdown = modal.el.querySelector('.select-affiliation');
  375. show_affiliation_dropdown.value = 'member';
  376. const button = modal.el.querySelector('.btn-primary[name="users_with_affiliation"]');
  377. button.click();
  378. await u.waitUntil(() => !modal.loading_users_with_affiliation);
  379. const user_els = modal.el.querySelectorAll('.list-group--users > li');
  380. expect(user_els.length).toBe(2);
  381. let change_affiliation_dropdown = user_els[0].querySelector('.select-affiliation');
  382. expect(Array.from(change_affiliation_dropdown.options).map(o => o.value)).toEqual(['member', 'outcast', 'none']);
  383. change_affiliation_dropdown = user_els[1].querySelector('.select-affiliation');
  384. expect(Array.from(change_affiliation_dropdown.options).map(o => o.value)).toEqual(['member', 'outcast', 'none']);
  385. done();
  386. }));
  387. it("lets the assignable affiliations and roles be configured via modtools_disable_assign",
  388. mock.initConverse([], {}, async function (done, _converse) {
  389. const muc_jid = 'lounge@montague.lit';
  390. const members = [{'jid': 'romeo@montague.lit', 'nick': 'romeo', 'affiliation': 'owner'}];
  391. await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo', [], members);
  392. const view = _converse.chatboxviews.get(muc_jid);
  393. const textarea = await u.waitUntil(() => view.querySelector('.chat-textarea'));
  394. textarea.value = '/modtools';
  395. const enter = { 'target': textarea, 'preventDefault': function preventDefault () {}, 'keyCode': 13 };
  396. const bottom_panel = view.querySelector('converse-muc-bottom-panel');
  397. bottom_panel.onKeyDown(enter);
  398. const modal = await u.waitUntil(() => _converse.api.modal.get('converse-modtools-modal'));
  399. const occupant = view.model.occupants.findWhere({'jid': _converse.bare_jid});
  400. expect(modal.getAssignableAffiliations(occupant)).toEqual(['owner', 'admin', 'member', 'outcast', 'none']);
  401. _converse.api.settings.set('modtools_disable_assign', ['owner']);
  402. expect(modal.getAssignableAffiliations(occupant)).toEqual(['admin', 'member', 'outcast', 'none']);
  403. _converse.api.settings.set('modtools_disable_assign', ['owner', 'admin']);
  404. expect(modal.getAssignableAffiliations(occupant)).toEqual(['member', 'outcast', 'none']);
  405. _converse.api.settings.set('modtools_disable_assign', ['owner', 'admin', 'outcast']);
  406. expect(modal.getAssignableAffiliations(occupant)).toEqual(['member', 'none']);
  407. expect(modal.getAssignableRoles(occupant)).toEqual(['moderator', 'participant', 'visitor']);
  408. _converse.api.settings.set('modtools_disable_assign', ['admin', 'moderator']);
  409. expect(modal.getAssignableRoles(occupant)).toEqual(['participant', 'visitor']);
  410. done();
  411. }));
  412. });