form_timer.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. test("form elements check", function() {
  2. $('#forms').append('<hr><h1>form elements check</h1><form id="form1"></form>')
  3. var el = $('#form1')
  4. var defaults = {
  5. }
  6. new App.ControllerForm({
  7. el: el,
  8. model: {
  9. configure_attributes: [
  10. { name: 'input1', display: 'Input1', tag: 'input', type: 'text', limit: 100, null: true, default: defaults['input1'] },
  11. { name: 'timer_params', display: 'Timer', tag: 'timer', null: false, default: defaults['timer_params'] },
  12. ]
  13. },
  14. autofocus: true
  15. });
  16. equal('Run every Monday at 00:00', el.find('.js-timerResult').val())
  17. var params = App.ControllerForm.params(el)
  18. var test_params = {
  19. input1: '',
  20. timer_params: {
  21. days: {
  22. 'Mon': true,
  23. 'Tue': false,
  24. 'Wed': false,
  25. 'Thu': false,
  26. 'Fri': false,
  27. 'Sat': false,
  28. 'Sun': false,
  29. },
  30. hours: {
  31. 0: true,
  32. 1: false,
  33. 2: false,
  34. 3: false,
  35. 4: false,
  36. 5: false,
  37. 6: false,
  38. 7: false,
  39. 8: false,
  40. 9: false,
  41. 10: false,
  42. 11: false,
  43. 12: false,
  44. 13: false,
  45. 14: false,
  46. 15: false,
  47. 16: false,
  48. 17: false,
  49. 18: false,
  50. 19: false,
  51. 20: false,
  52. 21: false,
  53. 22: false,
  54. 23: false,
  55. },
  56. minutes: {
  57. 0: true,
  58. 10: false,
  59. 20: false,
  60. 30: false,
  61. 40: false,
  62. 50: false,
  63. },
  64. },
  65. }
  66. deepEqual(params, test_params, 'form param check')
  67. $('#forms').append('<hr><h1>form elements check</h1><form id="form2"></form>')
  68. var el = $('#form2')
  69. var defaults = {
  70. input1: '123abc',
  71. timer_params: {
  72. days: {
  73. 'Mon': true,
  74. 'Fri': true,
  75. },
  76. hours: {
  77. 0: true,
  78. 10: true,
  79. 16: true,
  80. },
  81. minutes: {
  82. 0: true,
  83. 10: true,
  84. 50: true,
  85. },
  86. },
  87. }
  88. new App.ControllerForm({
  89. el: el,
  90. model: {
  91. configure_attributes: [
  92. { name: 'input1', display: 'Input1', tag: 'input', type: 'text', limit: 100, null: true, default: defaults['input1'] },
  93. { name: 'timer_params', display: 'Timer', tag: 'timer', null: false, default: defaults['timer_params'] },
  94. ]
  95. },
  96. autofocus: true
  97. });
  98. equal('Run every Monday and Friday at 00:00, 00:10, 00:50, 10:00, 10:10, 10:50, 16:00, 16:10 and 16:50', el.find('.js-timerResult').val())
  99. var params = App.ControllerForm.params(el)
  100. var test_params = {
  101. input1: '123abc',
  102. timer_params: {
  103. days: {
  104. 'Mon': true,
  105. 'Tue': false,
  106. 'Wed': false,
  107. 'Thu': false,
  108. 'Fri': true,
  109. 'Sat': false,
  110. 'Sun': false,
  111. },
  112. hours: {
  113. 0: true,
  114. 1: false,
  115. 2: false,
  116. 3: false,
  117. 4: false,
  118. 5: false,
  119. 6: false,
  120. 7: false,
  121. 8: false,
  122. 9: false,
  123. 10: true,
  124. 11: false,
  125. 12: false,
  126. 13: false,
  127. 14: false,
  128. 15: false,
  129. 16: true,
  130. 17: false,
  131. 18: false,
  132. 19: false,
  133. 20: false,
  134. 21: false,
  135. 22: false,
  136. 23: false,
  137. },
  138. minutes: {
  139. 0: true,
  140. 10: true,
  141. 20: false,
  142. 30: false,
  143. 40: false,
  144. 50: true,
  145. },
  146. },
  147. }
  148. deepEqual(params, test_params, 'form param check')
  149. $('#form2 .js-day [data-value="Sat"]').click()
  150. $('#form2 .js-hour [data-value="16"]').click()
  151. $('#form2 .js-minute [data-value="10"]').click()
  152. equal('Run every Monday, Friday and Saturday at 00:00, 00:50, 10:00 and 10:50', el.find('.js-timerResult').val())
  153. var params = App.ControllerForm.params(el)
  154. var test_params = {
  155. input1: '123abc',
  156. timer_params: {
  157. days: {
  158. 'Mon': true,
  159. 'Tue': false,
  160. 'Wed': false,
  161. 'Thu': false,
  162. 'Fri': true,
  163. 'Sat': true,
  164. 'Sun': false,
  165. },
  166. hours: {
  167. 0: true,
  168. 1: false,
  169. 2: false,
  170. 3: false,
  171. 4: false,
  172. 5: false,
  173. 6: false,
  174. 7: false,
  175. 8: false,
  176. 9: false,
  177. 10: true,
  178. 11: false,
  179. 12: false,
  180. 13: false,
  181. 14: false,
  182. 15: false,
  183. 16: false,
  184. 17: false,
  185. 18: false,
  186. 19: false,
  187. 20: false,
  188. 21: false,
  189. 22: false,
  190. 23: false,
  191. },
  192. minutes: {
  193. 0: true,
  194. 10: false,
  195. 20: false,
  196. 30: false,
  197. 40: false,
  198. 50: true,
  199. },
  200. },
  201. }
  202. deepEqual(params, test_params, 'form param check')
  203. });