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.

appsSpec.js 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /**
  2. * ownCloud
  3. *
  4. * @author Vincent Petry
  5. * @copyright 2015 Vincent Petry <pvince81@owncloud.com>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  9. * License as published by the Free Software Foundation; either
  10. * version 3 of the License, or any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public
  18. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. describe('OC.Settings.Apps tests', function() {
  22. var Apps;
  23. beforeEach(function() {
  24. var $el = $('<div id="apps-list"></div>' +
  25. '<div id="apps-list-empty" class="hidden"></div>' +
  26. '<div id="app-template">' +
  27. // dummy template for testing
  28. '<div id="app-{{id}}" data-id="{{id}}" class="section">{{name}}</div>' +
  29. '</div>'
  30. );
  31. $('#testArea').append($el);
  32. Apps = OC.Settings.Apps;
  33. });
  34. afterEach(function() {
  35. Apps.State.apps = null;
  36. Apps.State.currentCategory = null;
  37. });
  38. describe('Filtering apps', function() {
  39. var oldApps;
  40. function loadApps(appList) {
  41. Apps.State.apps = appList;
  42. _.each(appList, function(appSpec) {
  43. Apps.renderApp(appSpec);
  44. });
  45. }
  46. function getResultsFromDom() {
  47. var results = [];
  48. $('#apps-list .section:not(.hidden)').each(function() {
  49. results.push($(this).attr('data-id'));
  50. });
  51. return results;
  52. }
  53. beforeEach(function() {
  54. loadApps([
  55. {id: 'appone', name: 'App One', description: 'The first app', author: 'author1', level: 200},
  56. {id: 'apptwo', name: 'App Two', description: 'The second app', author: 'author2', level: 100},
  57. {id: 'appthree', name: 'App Three', description: 'Third app', author: 'author3', level: 0},
  58. {id: 'somestuff', name: 'Some Stuff', description: 'whatever', author: 'author4', level: 0}
  59. ]);
  60. });
  61. it('returns no results when query does not match anything', function() {
  62. expect(getResultsFromDom().length).toEqual(4);
  63. expect($('#apps-list:not(.hidden)').length).toEqual(1);
  64. expect($('#apps-list-empty:not(.hidden)').length).toEqual(0);
  65. Apps.filter('absurdity');
  66. expect(getResultsFromDom().length).toEqual(0);
  67. expect($('#apps-list:not(.hidden)').length).toEqual(0);
  68. expect($('#apps-list-empty:not(.hidden)').length).toEqual(1);
  69. Apps.filter('');
  70. expect(getResultsFromDom().length).toEqual(4);
  71. expect($('#apps-list:not(.hidden)').length).toEqual(1);
  72. expect($('#apps-list-empty:not(.hidden)').length).toEqual(0);
  73. expect(getResultsFromDom().length).toEqual(4);
  74. });
  75. it('returns relevant results when query matches name', function() {
  76. expect($('#apps-list:not(.hidden)').length).toEqual(1);
  77. expect($('#apps-list-empty:not(.hidden)').length).toEqual(0);
  78. var results;
  79. Apps.filter('app');
  80. results = getResultsFromDom();
  81. expect(results.length).toEqual(3);
  82. expect(results[0]).toEqual('appone');
  83. expect(results[1]).toEqual('apptwo');
  84. expect(results[2]).toEqual('appthree');
  85. expect($('#apps-list:not(.hidden)').length).toEqual(1);
  86. expect($('#apps-list-empty:not(.hidden)').length).toEqual(0);
  87. });
  88. it('returns relevant result when query matches name', function() {
  89. var results;
  90. Apps.filter('TWO');
  91. results = getResultsFromDom();
  92. expect(results.length).toEqual(1);
  93. expect(results[0]).toEqual('apptwo');
  94. });
  95. it('returns relevant result when query matches description', function() {
  96. var results;
  97. Apps.filter('ever');
  98. results = getResultsFromDom();
  99. expect(results.length).toEqual(1);
  100. expect(results[0]).toEqual('somestuff');
  101. });
  102. it('returns relevant results when query matches author name', function() {
  103. var results;
  104. Apps.filter('author');
  105. results = getResultsFromDom();
  106. expect(results.length).toEqual(4);
  107. expect(results[0]).toEqual('appone');
  108. expect(results[1]).toEqual('apptwo');
  109. expect(results[2]).toEqual('appthree');
  110. expect(results[3]).toEqual('somestuff');
  111. });
  112. it('returns relevant result when query matches author name', function() {
  113. var results;
  114. Apps.filter('thor3');
  115. results = getResultsFromDom();
  116. expect(results.length).toEqual(1);
  117. expect(results[0]).toEqual('appthree');
  118. });
  119. it('returns relevant result when query matches level name', function() {
  120. var results;
  121. Apps.filter('Offic');
  122. results = getResultsFromDom();
  123. expect(results.length).toEqual(1);
  124. expect(results[0]).toEqual('appone');
  125. });
  126. it('returns relevant result when query matches level name', function() {
  127. var results;
  128. Apps.filter('Appro');
  129. results = getResultsFromDom();
  130. expect(results.length).toEqual(1);
  131. expect(results[0]).toEqual('apptwo');
  132. });
  133. it('returns relevant result when query matches level name', function() {
  134. var results;
  135. Apps.filter('Exper');
  136. results = getResultsFromDom();
  137. expect(results.length).toEqual(2);
  138. expect(results[0]).toEqual('appthree');
  139. expect(results[1]).toEqual('somestuff');
  140. });
  141. });
  142. describe('loading categories', function() {
  143. var suite = this;
  144. beforeEach( function(){
  145. suite.server = sinon.fakeServer.create();
  146. });
  147. afterEach( function(){
  148. suite.server.restore();
  149. });
  150. function getResultsFromDom() {
  151. var results = [];
  152. $('#apps-list .section:not(.hidden)').each(function() {
  153. results.push($(this).attr('data-id'));
  154. });
  155. return results;
  156. }
  157. it('sorts all applications using the level', function() {
  158. Apps.loadCategory('TestId');
  159. suite.server.requests[0].respond(
  160. 200,
  161. {
  162. 'Content-Type': 'application/json'
  163. },
  164. JSON.stringify({
  165. apps: [
  166. {
  167. id: 'foo',
  168. name: 'Foo app',
  169. level: 0,
  170. author: 'foo'
  171. },
  172. {
  173. id: 'alpha',
  174. name: 'Alpha app',
  175. level: 300,
  176. author: ['alpha', 'beta']
  177. },
  178. {
  179. id: 'nolevel',
  180. name: 'No level',
  181. author: 'bar'
  182. },
  183. {
  184. id: 'zork',
  185. name: 'Some famous adventure game',
  186. level: 200,
  187. author: 'baz'
  188. },
  189. {
  190. id: 'delta',
  191. name: 'Mathematical symbol',
  192. level: 200,
  193. author: 'foobar'
  194. }
  195. ]
  196. })
  197. );
  198. var results = getResultsFromDom();
  199. expect(results.length).toEqual(5);
  200. expect(results).toEqual(['alpha', 'delta', 'zork', 'foo', 'nolevel']);
  201. expect(OC.Settings.Apps.State.apps).toEqual({
  202. 'foo': {
  203. id: 'foo',
  204. name: 'Foo app',
  205. level: 0,
  206. author: 'foo'
  207. },
  208. 'alpha': {
  209. id: 'alpha',
  210. name: 'Alpha app',
  211. level: 300,
  212. author: ['alpha', 'beta']
  213. },
  214. 'nolevel': {
  215. id: 'nolevel',
  216. name: 'No level',
  217. author: 'bar'
  218. },
  219. 'zork': {
  220. id: 'zork',
  221. name: 'Some famous adventure game',
  222. level: 200,
  223. author: 'baz',
  224. },
  225. 'delta': {
  226. id: 'delta',
  227. name: 'Mathematical symbol',
  228. level: 200,
  229. author: 'foobar'
  230. }
  231. });
  232. });
  233. });
  234. });