contactsmenuSpec.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /* global expect, sinon, _, spyOn, Promise */
  2. /**
  3. * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
  4. *
  5. * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
  6. *
  7. * @license AGPL-3.0-or-later
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. describe('Contacts menu', function() {
  24. var $triggerEl,
  25. $menuEl,
  26. menu;
  27. /**
  28. * @private
  29. * @returns {Promise}
  30. */
  31. function openMenu() {
  32. return menu._toggleVisibility(true);
  33. }
  34. beforeEach(function(done) {
  35. $triggerEl = $('<div class="menutoggle">');
  36. $menuEl = $('<div class="menu">');
  37. menu = new OC.ContactsMenu({
  38. el: $menuEl,
  39. trigger: $triggerEl
  40. });
  41. done();
  42. });
  43. it('shows a loading message while data is being fetched', function() {
  44. fakeServer.respondWith('GET', OC.generateUrl('/contactsmenu/contacts'), [
  45. 200,
  46. {},
  47. ''
  48. ]);
  49. openMenu();
  50. expect($menuEl.html()).toContain('Loading your contacts …');
  51. });
  52. it('shows an error message when loading the contacts data fails', function(done) {
  53. spyOn(console, 'error');
  54. fakeServer.respondWith('GET', OC.generateUrl('/contactsmenu/contacts'), [
  55. 500,
  56. {},
  57. ''
  58. ]);
  59. var opening = openMenu();
  60. expect($menuEl.html()).toContain('Loading your contacts …');
  61. fakeServer.respond();
  62. opening.then(function() {
  63. expect($menuEl.html()).toContain('Could not load your contacts');
  64. expect(console.error).toHaveBeenCalled();
  65. done();
  66. }, function(e) {
  67. done.fail(e);
  68. });
  69. });
  70. it('loads data successfully', function(done) {
  71. spyOn(menu, '_getContacts').and.returnValue(Promise.resolve({
  72. contacts: [
  73. {
  74. id: null,
  75. fullName: 'Acosta Lancaster',
  76. topAction: {
  77. title: 'Mail',
  78. icon: 'icon-mail',
  79. hyperlink: 'mailto:deboraoliver%40centrexin.com'
  80. },
  81. actions: [
  82. {
  83. title: 'Mail',
  84. icon: 'icon-mail',
  85. hyperlink: 'mailto:mathisholland%40virxo.com'
  86. },
  87. {
  88. title: 'Details',
  89. icon: 'icon-info',
  90. hyperlink: 'https:\/\/localhost\/index.php\/apps\/contacts'
  91. }
  92. ],
  93. lastMessage: ''
  94. },
  95. {
  96. id: null,
  97. fullName: 'Adeline Snider',
  98. topAction: {
  99. title: 'Mail',
  100. icon: 'icon-mail',
  101. hyperlink: 'mailto:ceciliasoto%40essensia.com'
  102. },
  103. actions: [
  104. {
  105. title: 'Mail',
  106. icon: 'icon-mail',
  107. hyperlink: 'mailto:pearliesellers%40inventure.com'
  108. },
  109. {
  110. title: 'Details',
  111. icon: 'icon-info',
  112. hyperlink: 'https://localhost\/index.php\/apps\/contacts'
  113. }
  114. ],
  115. lastMessage: 'cu'
  116. }
  117. ],
  118. contactsAppEnabled: true
  119. }));
  120. openMenu().then(function() {
  121. expect(menu._getContacts).toHaveBeenCalled();
  122. expect($menuEl.html()).toContain('Acosta Lancaster');
  123. expect($menuEl.html()).toContain('Adeline Snider');
  124. expect($menuEl.html()).toContain('Show all contacts …');
  125. done();
  126. }, function(e) {
  127. done.fail(e);
  128. });
  129. });
  130. it('doesn\'t show a link to the contacts app if it\'s disabled', function(done) {
  131. spyOn(menu, '_getContacts').and.returnValue(Promise.resolve({
  132. contacts: [
  133. {
  134. id: null,
  135. fullName: 'Acosta Lancaster',
  136. topAction: {
  137. title: 'Mail',
  138. icon: 'icon-mail',
  139. hyperlink: 'mailto:deboraoliver%40centrexin.com'
  140. },
  141. actions: [
  142. {
  143. title: 'Mail',
  144. icon: 'icon-mail',
  145. hyperlink: 'mailto:mathisholland%40virxo.com'
  146. },
  147. {
  148. title: 'Details',
  149. icon: 'icon-info',
  150. hyperlink: 'https:\/\/localhost\/index.php\/apps\/contacts'
  151. }
  152. ],
  153. lastMessage: ''
  154. }
  155. ],
  156. contactsAppEnabled: false
  157. }));
  158. openMenu().then(function() {
  159. expect(menu._getContacts).toHaveBeenCalled();
  160. expect($menuEl.html()).not.toContain('Show all contacts …');
  161. done();
  162. }, function(e) {
  163. done.fail(e);
  164. });
  165. });
  166. it('shows only one entry\'s action menu at a time', function(done) {
  167. spyOn(menu, '_getContacts').and.returnValue(Promise.resolve({
  168. contacts: [
  169. {
  170. id: null,
  171. fullName: 'Acosta Lancaster',
  172. topAction: {
  173. title: 'Mail',
  174. icon: 'icon-mail',
  175. hyperlink: 'mailto:deboraoliver%40centrexin.com'
  176. },
  177. actions: [
  178. {
  179. title: 'Info',
  180. icon: 'icon-info',
  181. hyperlink: 'https:\/\/localhost\/index.php\/apps\/contacts'
  182. },
  183. {
  184. title: 'Details',
  185. icon: 'icon-info',
  186. hyperlink: 'https:\/\/localhost\/index.php\/apps\/contacts'
  187. }
  188. ],
  189. lastMessage: ''
  190. },
  191. {
  192. id: null,
  193. fullName: 'Adeline Snider',
  194. topAction: {
  195. title: 'Mail',
  196. icon: 'icon-mail',
  197. hyperlink: 'mailto:ceciliasoto%40essensia.com'
  198. },
  199. actions: [
  200. {
  201. title: 'Info',
  202. icon: 'icon-info',
  203. hyperlink: 'https://localhost\/index.php\/apps\/contacts'
  204. },
  205. {
  206. title: 'Details',
  207. icon: 'icon-info',
  208. hyperlink: 'https://localhost\/index.php\/apps\/contacts'
  209. }
  210. ],
  211. lastMessage: 'cu'
  212. }
  213. ],
  214. contactsAppEnabled: true
  215. }));
  216. openMenu().then(function() {
  217. expect(menu._getContacts).toHaveBeenCalled();
  218. expect($menuEl.html()).toContain('Adeline Snider');
  219. expect($menuEl.html()).toContain('Show all contacts …');
  220. // Both menus are closed at the beginning
  221. expect($menuEl.find('.contact').eq(0).find('.menu').is(':visible')).toBe(false);
  222. expect($menuEl.find('.contact').eq(1).find('.menu').is(':visible')).toBe(false);
  223. // Open the first one
  224. $menuEl.find('.contact').eq(0).find('.other-actions').click();
  225. expect($menuEl.find('.contact').eq(0).find('.menu').css('display')).toBe('');
  226. expect($menuEl.find('.contact').eq(1).find('.menu').css('display')).toBe('none');
  227. // Open the second one
  228. $menuEl.find('.contact').eq(1).find('.other-actions').click();
  229. expect($menuEl.find('.contact').eq(0).find('.menu').css('display')).toBe('none');
  230. expect($menuEl.find('.contact').eq(1).find('.menu').css('display')).toBe('');
  231. // Close the second one
  232. $menuEl.find('.contact').eq(1).find('.other-actions').click();
  233. expect($menuEl.find('.contact').eq(0).find('.menu').css('display')).toBe('none');
  234. expect($menuEl.find('.contact').eq(1).find('.menu').css('display')).toBe('none');
  235. done();
  236. }, function(e) {
  237. done.fail(e);
  238. });
  239. });
  240. });