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.

278 lines
9.0 KiB

  1. /* Copyright 2016 LasLabs Inc.
  2. * License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */
  3. odoo.define_section('web_responsive', ['web_responsive'], function(test) {
  4. "use strict";
  5. // It provides a base drawer compatible interface for testing
  6. self.initInterface = function(AppDrawer) {
  7. var $el = $('<div class="drawer drawer--left">');
  8. $el.append(
  9. $('<header role="banner">')
  10. .append(
  11. $('<button class="drawer-toggle"><span class="drawer-hamburger-icon">')
  12. )
  13. .append(
  14. $('<nav class="drawer-nav"><ul class="drawer-menu"><li class="drawer-menu-item">')
  15. )
  16. .append(
  17. $('<div class="panel-title" id="appDrawerAppPanelHead">')
  18. )
  19. ).append($('<main role="main">'));
  20. self.$clickZone = $('<a class="oe_menu_leaf">');
  21. self.$secondaryMenu = $('<div><div class="oe_secondary_menus_container">');
  22. self.$dropdown = $('<div class="dropdown-scrollable">');
  23. $el.append(self.$clickZone)
  24. .append(self.$secondaryMenu)
  25. .append(self.$dropdown);
  26. var $document = $("#qunit-fixture");
  27. $document.append($el);
  28. self.drawer = new AppDrawer.AppDrawer();
  29. return $document;
  30. };
  31. self.linkGrid = function() {
  32. for(var i=0; i < 3; i++){
  33. self.drawer.$el.append(
  34. $('<div class="row">').append(
  35. $('<a class="col-md-6" id="a_' + i + '"><span class="app-drawer-icon-app /></a>' +
  36. '<a class="col-md-6" id="b_' + i + '"><span class="app-drawer-icon-app /></a>'
  37. )
  38. )
  39. );
  40. self.drawer.$appLinks = $('a.col-md-6');
  41. }
  42. };
  43. test('It should set initialized after success init',
  44. function(assert, AppDrawer) {
  45. self.initInterface(AppDrawer);
  46. assert.ok(self.drawer.initialized);
  47. }
  48. );
  49. test('It should close drawer after click on clickZone',
  50. {asserts: 1},
  51. function(assert, AppDrawer) {
  52. self.initInterface(AppDrawer);
  53. self.$clickZone.click();
  54. var d = $.Deferred();
  55. setTimeout(function() {
  56. assert.ok(self.drawer.$el.hasClass('drawer-close'));
  57. d.resolve();
  58. }, 100);
  59. return d;
  60. }
  61. );
  62. test('It should collapse open secondary menus during handleClickZones',
  63. {asserts: 1},
  64. function(assert, AppDrawer) {
  65. self.initInterface(AppDrawer);
  66. self.$clickZone.click();
  67. var d = $.Deferred();
  68. setTimeout(function() {
  69. assert.equal(self.$secondaryMenu.attr('aria-expanded'), 'false');
  70. d.resolve();
  71. }, 100);
  72. return d;
  73. }
  74. );
  75. test('It should update max-height on scrollable dropdowns',
  76. function(assert, AppDrawer) {
  77. self.initInterface(AppDrawer);
  78. self.drawer.handleWindowResize();
  79. var height = $(window).height() * self.drawer.dropdownHeightFactor;
  80. assert.equal(
  81. self.$dropdown.css('max-height'),
  82. height + 'px'
  83. );
  84. }
  85. );
  86. test('It should return keybuffer + new key',
  87. function(assert, AppDrawer) {
  88. self.initInterface(AppDrawer);
  89. self.drawer.keyBuffer = 'TES';
  90. var res = self.drawer.handleKeyBuffer(84);
  91. assert.equal(res, 'TEST');
  92. }
  93. );
  94. test('It should clear keybuffer after timeout',
  95. {asserts: 1},
  96. function(assert, AppDrawer) {
  97. self.initInterface(AppDrawer);
  98. self.drawer.keyBuffer = 'TES';
  99. self.drawer.keyBufferTime = 10;
  100. self.drawer.handleKeyBuffer(84);
  101. var d = $.Deferred();
  102. setTimeout(function() {
  103. assert.equal(self.drawer.keyBuffer, "");
  104. d.resolve();
  105. }, 100);
  106. return d;
  107. }
  108. );
  109. test('It should trigger core bus event for drawer close',
  110. ['web.core'], {asserts: 1},
  111. function(assert, AppDrawer, core) {
  112. self.initInterface(AppDrawer);
  113. self.drawer.onDrawerOpen();
  114. var d = $.Deferred();
  115. core.bus.on('drawer.closed', this, function() {
  116. assert.ok(true);
  117. d.resolve();
  118. });
  119. self.drawer.$el.trigger({type: 'drawer.closed'});
  120. return d;
  121. }
  122. );
  123. test('It should set isOpen to false when closing',
  124. {asserts: 1},
  125. function(assert, AppDrawer) {
  126. self.initInterface(AppDrawer);
  127. self.drawer.onDrawerOpen();
  128. var d = $.Deferred();
  129. setTimeout(function() {
  130. assert.equal(self.drawer.isOpen, false);
  131. d.resolve();
  132. });
  133. self.drawer.$el.trigger({type: 'drawer.closed'});
  134. return d;
  135. }
  136. );
  137. test('It should set isOpen to true when opening',
  138. {asserts: 1},
  139. function(assert, AppDrawer) {
  140. self.initInterface(AppDrawer);
  141. var d = $.Deferred();
  142. self.drawer.$el.trigger({type: 'drawer.opened'});
  143. setTimeout(function() {
  144. assert.ok(self.drawer.isOpen);
  145. d.resolve();
  146. });
  147. return d;
  148. }
  149. );
  150. test('It should trigger core bus event for drawer open',
  151. ['web.core'], {asserts: 1},
  152. function(assert, AppDrawer, core) {
  153. self.initInterface(AppDrawer);
  154. self.drawer.onDrawerOpen();
  155. var d = $.Deferred();
  156. core.bus.on('drawer.opened', this, function() {
  157. assert.ok(true);
  158. d.resolve();
  159. });
  160. self.drawer.$el.trigger({type: 'drawer.opened'});
  161. return d;
  162. }
  163. );
  164. test('It should choose link to right',
  165. function(assert, AppDrawer) {
  166. self.initInterface(AppDrawer);
  167. self.linkGrid();
  168. var $appLink = $('#a_1'),
  169. $expect = $('#a_2'),
  170. $res = self.drawer.findAdjacentAppLink(
  171. $appLink, self.drawer.RIGHT
  172. );
  173. assert.equal($res[0].id, $expect[0].id);
  174. }
  175. );
  176. test('It should choose link to left',
  177. function(assert, AppDrawer) {
  178. self.initInterface(AppDrawer);
  179. self.linkGrid();
  180. var $appLink = $('#a_2'),
  181. $expect = $('#a_1'),
  182. $res = self.drawer.findAdjacentAppLink(
  183. $appLink, self.drawer.LEFT
  184. );
  185. assert.equal($res[0].id, $expect[0].id);
  186. }
  187. );
  188. test('It should choose link above',
  189. function(assert, AppDrawer) {
  190. self.initInterface(AppDrawer);
  191. self.linkGrid();
  192. var $appLink = $('#a_1'),
  193. $expect = $('#a_0'),
  194. $res = self.drawer.findAdjacentAppLink(
  195. $appLink, self.drawer.UP
  196. );
  197. assert.equal($res[0].id, $expect[0].id);
  198. }
  199. );
  200. test('It should choose link below',
  201. function(assert, AppDrawer) {
  202. self.initInterface(AppDrawer);
  203. self.linkGrid();
  204. var $appLink = $('#a_1'),
  205. $expect = $('#a_2'),
  206. $res = self.drawer.findAdjacentAppLink(
  207. $appLink, self.drawer.DOWN
  208. );
  209. assert.equal($res[0].id, $expect[0].id);
  210. }
  211. );
  212. test('It should choose first link if next on last',
  213. function(assert, AppDrawer) {
  214. self.initInterface(AppDrawer);
  215. self.linkGrid();
  216. var $appLink = $('#b_2'),
  217. $expect = $('#a_0'),
  218. $res = self.drawer.findAdjacentAppLink(
  219. $appLink, self.drawer.RIGHT
  220. );
  221. assert.equal($res[0].id, $expect[0].id);
  222. }
  223. );
  224. test('It should choose bottom link if up on top',
  225. function(assert, AppDrawer) {
  226. self.initInterface(AppDrawer);
  227. self.linkGrid();
  228. var $appLink = $('#a_0'),
  229. $expect = $('#a_2'),
  230. $res = self.drawer.findAdjacentAppLink(
  231. $appLink, self.drawer.UP
  232. );
  233. assert.equal($res[0].id, $expect[0].id);
  234. }
  235. );
  236. test('It should choose top link if down on bottom',
  237. function(assert, AppDrawer) {
  238. self.initInterface(AppDrawer);
  239. self.linkGrid();
  240. var $appLink = $('#a_2'),
  241. $expect = $('#a_0'),
  242. $res = self.drawer.findAdjacentAppLink(
  243. $appLink, self.drawer.DOWN
  244. );
  245. assert.equal($res[0].id, $expect[0].id);
  246. }
  247. );
  248. });