table_extended.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. // initial list
  2. test('table new - initial list', function() {
  3. App.i18n.set('de-de')
  4. $('#table').append('<hr><h1>table with data</h1><div id="table-new1"></div>')
  5. var el = $('#table-new1')
  6. App.TicketPriority.refresh([
  7. {
  8. id: 1,
  9. name: '1 low',
  10. note: 'some note 1',
  11. active: true,
  12. created_at: '2014-06-10T11:17:34.000Z',
  13. },
  14. {
  15. id: 2,
  16. name: '2 normal',
  17. note: 'some note 2',
  18. active: false,
  19. created_at: '2014-06-10T10:17:34.000Z',
  20. },
  21. ], {clear: true})
  22. var table = new App.ControllerTable({
  23. el: el,
  24. overviewAttributes: ['name', 'created_at', 'active'],
  25. model: App.TicketPriority,
  26. objects: App.TicketPriority.search({sortBy:'name', order: 'ASC'}),
  27. checkbox: false,
  28. radio: false,
  29. })
  30. //equal(el.find('table').length, 0, 'row count')
  31. //table.render()
  32. equal(el.find('table > thead > tr').length, 1, 'row count')
  33. equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
  34. equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Erstellt', 'check header')
  35. equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Aktiv', 'check header')
  36. equal(el.find('tbody > tr:nth-child(1) > td').length, 3, 'check row 1')
  37. equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), '1 niedrig', 'check row 1')
  38. equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 1')
  39. equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3)').text().trim(), 'true', 'check row 1')
  40. equal(el.find('tbody > tr:nth-child(2) > td').length, 3, 'check row 2')
  41. equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '2 normal', 'check row 2')
  42. equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 2')
  43. equal(el.find('tbody > tr:nth-child(3) > td').length, 0, 'check row 3')
  44. result = table.update({sync: true, objects: App.TicketPriority.search({sortBy:'name', order: 'ASC'})})
  45. equal(result[0], 'noChanges')
  46. equal(el.find('table > thead > tr').length, 1, 'row count')
  47. equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
  48. equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Erstellt', 'check header')
  49. equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Aktiv', 'check header')
  50. equal(el.find('tbody > tr:nth-child(1) > td').length, 3, 'check row 1')
  51. equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), '1 niedrig', 'check row 1')
  52. equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 1')
  53. equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3)').text().trim(), 'true', 'check row 1')
  54. equal(el.find('tbody > tr:nth-child(2) > td').length, 3, 'check row 2')
  55. equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '2 normal', 'check row 2')
  56. equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 2')
  57. App.TicketPriority.refresh([
  58. {
  59. id: 1,
  60. name: 'Priority',
  61. note: 'some note 1',
  62. active: true,
  63. created_at: '2014-06-10T11:17:34.000Z',
  64. },
  65. ], {clear: true})
  66. result = table.update({sync: true, objects: App.TicketPriority.search({sortBy:'name', order: 'ASC'})})
  67. equal(result[0], 'fullRender.lenghtChanged')
  68. equal(result[1], 2)
  69. equal(result[2], 1)
  70. equal(el.find('table > thead > tr').length, 1, 'row count')
  71. equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
  72. equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Erstellt', 'check header')
  73. equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Aktiv', 'check header')
  74. equal(el.find('tbody > tr:nth-child(1) > td').length, 3, 'check row 1')
  75. equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), 'Priorität', 'check row 1')
  76. equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 1')
  77. equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3)').text().trim(), 'true', 'check row 1')
  78. equal(el.find('tbody > tr:nth-child(2) > td').length, 0, 'check row 2')
  79. App.TicketPriority.refresh([], {clear: true})
  80. result = table.update({sync: true, objects: App.TicketPriority.search({sortBy:'name', order: 'ASC'})})
  81. equal(result[0], 'emptyList')
  82. equal(el.find('table > thead > tr').length, 1, 'row count')
  83. equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Keine Einträge', 'check header')
  84. equal(el.find('tbody > tr:nth-child(1) > td').length, 0, 'check row 1')
  85. App.TicketPriority.refresh([
  86. {
  87. id: 1,
  88. name: '1 low',
  89. note: 'some note 1',
  90. active: true,
  91. created_at: '2014-06-10T11:17:34.000Z',
  92. },
  93. {
  94. id: 2,
  95. name: '2 normal',
  96. note: 'some note 2',
  97. active: false,
  98. created_at: '2014-06-10T10:17:34.000Z',
  99. },
  100. ], {clear: true})
  101. result = table.update({sync: true, objects: App.TicketPriority.search({sortBy:'name', order: 'ASC'})})
  102. equal(result[0], 'fullRender')
  103. equal(el.find('table > thead > tr').length, 1, 'row count')
  104. equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
  105. equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Erstellt', 'check header')
  106. equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Aktiv', 'check header')
  107. equal(el.find('tbody > tr:nth-child(1) > td').length, 3, 'check row 1')
  108. equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), '1 niedrig', 'check row 1')
  109. equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 1')
  110. equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3)').text().trim(), 'true', 'check row 1')
  111. equal(el.find('tbody > tr:nth-child(2) > td').length, 3, 'check row 2')
  112. equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '2 normal', 'check row 2')
  113. equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 2')
  114. equal(el.find('tbody > tr:nth-child(3) > td').length, 0, 'check row 3')
  115. App.TicketPriority.refresh([
  116. {
  117. id: 1,
  118. name: '1 low',
  119. note: 'some note 1',
  120. active: true,
  121. created_at: '2014-06-10T11:17:34.000Z',
  122. },
  123. {
  124. id: 2,
  125. name: '2 normal',
  126. note: 'some note 2',
  127. active: false,
  128. created_at: '2014-06-10T10:17:34.000Z',
  129. },
  130. {
  131. id: 3,
  132. name: '3 high',
  133. note: 'some note 3',
  134. active: false,
  135. created_at: '2014-06-10T10:17:38.000Z',
  136. },
  137. ], {clear: true})
  138. result = table.update({sync: true, objects: App.TicketPriority.search({sortBy:'name', order: 'ASC'})})
  139. equal(result[0], 'fullRender.lenghtChanged')
  140. equal(result[1], 2)
  141. equal(result[2], 3)
  142. equal(el.find('table > thead > tr').length, 1, 'row count')
  143. equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
  144. equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Erstellt', 'check header')
  145. equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Aktiv', 'check header')
  146. equal(el.find('tbody > tr:nth-child(1) > td').length, 3, 'check row 1')
  147. equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), '1 niedrig', 'check row 1')
  148. equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 1')
  149. equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3)').text().trim(), 'true', 'check row 1')
  150. equal(el.find('tbody > tr:nth-child(2) > td').length, 3, 'check row 2')
  151. equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '2 normal', 'check row 2')
  152. equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 2')
  153. equal(el.find('tbody > tr:nth-child(3) > td').length, 3, 'check row 3')
  154. equal(el.find('tbody > tr:nth-child(3) > td:first').text().trim(), '3 hoch', 'check row 3')
  155. equal(el.find('tbody > tr:nth-child(3) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 3')
  156. equal(el.find('tbody > tr:nth-child(4) > td').length, 0, 'check row 4')
  157. result = table.update({sync: true, orderDirection: 'DESC', orderBy: 'name'})
  158. equal(result[0], 'fullRender.contentChanged')
  159. equal(result[1], 0)
  160. equal(el.find('table > thead > tr').length, 1, 'row count')
  161. equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
  162. equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Erstellt', 'check header')
  163. equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Aktiv', 'check header')
  164. equal(el.find('tbody > tr:nth-child(1) > td').length, 3, 'check row 1')
  165. equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), '3 hoch', 'check row 1')
  166. equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 1')
  167. equal(el.find('tbody > tr:nth-child(2) > td').length, 3, 'check row 2')
  168. equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '2 normal', 'check row 2')
  169. equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 2')
  170. equal(el.find('tbody > tr:nth-child(3) > td').length, 3, 'check row 3')
  171. equal(el.find('tbody > tr:nth-child(3) > td:first').text().trim(), '1 niedrig', 'check row 3')
  172. equal(el.find('tbody > tr:nth-child(3) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 3')
  173. equal(el.find('tbody > tr:nth-child(3) > td:nth-child(3)').text().trim(), 'true', 'check row 3')
  174. equal(el.find('tbody > tr:nth-child(4) > td').length, 0, 'check row 4')
  175. result = table.update({sync: true, orderDirection: 'ASC', orderBy: 'name'})
  176. equal(result[0], 'fullRender.contentChanged')
  177. equal(result[1], 0)
  178. equal(el.find('table > thead > tr').length, 1, 'row count')
  179. equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
  180. equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Erstellt', 'check header')
  181. equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Aktiv', 'check header')
  182. equal(el.find('tbody > tr:nth-child(1) > td').length, 3, 'check row 1')
  183. equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), '1 niedrig', 'check row 1')
  184. equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 1')
  185. equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3)').text().trim(), 'true', 'check row 1')
  186. equal(el.find('tbody > tr:nth-child(2) > td').length, 3, 'check row 2')
  187. equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '2 normal', 'check row 2')
  188. equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 2')
  189. equal(el.find('tbody > tr:nth-child(3) > td').length, 3, 'check row 3')
  190. equal(el.find('tbody > tr:nth-child(3) > td:first').text().trim(), '3 hoch', 'check row 3')
  191. equal(el.find('tbody > tr:nth-child(3) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 3')
  192. equal(el.find('tbody > tr:nth-child(4) > td').length, 0, 'check row 4')
  193. App.TicketPriority.refresh([
  194. {
  195. id: 1,
  196. name: '1 low',
  197. note: 'some note 1',
  198. active: true,
  199. created_at: '2014-06-10T11:17:34.000Z',
  200. },
  201. {
  202. id: 3,
  203. name: '3 high',
  204. note: 'some note 3',
  205. active: false,
  206. created_at: '2014-06-10T10:17:38.000Z',
  207. },
  208. ], {clear: true})
  209. result = table.update({sync: true, objects: App.TicketPriority.search({sortBy:'name', order: 'ASC'})})
  210. equal(result[0], 'fullRender.contentRemoved')
  211. equal(result[1], 1)
  212. notOk(result[2])
  213. equal(el.find('table > thead > tr').length, 1, 'row count')
  214. equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
  215. equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Erstellt', 'check header')
  216. equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Aktiv', 'check header')
  217. equal(el.find('tbody > tr:nth-child(1) > td').length, 3, 'check row 1')
  218. equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), '1 niedrig', 'check row 1')
  219. equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 1')
  220. equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3)').text().trim(), 'true', 'check row 1')
  221. equal(el.find('tbody > tr:nth-child(2) > td').length, 3, 'check row 2')
  222. equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '3 hoch', 'check row 3')
  223. equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 3')
  224. equal(el.find('tbody > tr:nth-child(3) > td').length, 0, 'check row 3')
  225. result = table.update({sync: true, overviewAttributes: ['name', 'created_at']})
  226. equal(result[0], 'fullRender.overviewAttributesChanged')
  227. equal(el.find('table > thead > tr').length, 1, 'row count')
  228. equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
  229. equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Erstellt', 'check header')
  230. equal(el.find('table > thead > tr > th').length, 2, 'check header')
  231. equal(el.find('tbody > tr:nth-child(1) > td').length, 2, 'check row 1')
  232. equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), '1 niedrig', 'check row 1')
  233. equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 1')
  234. equal(el.find('tbody > tr:nth-child(2) > td').length, 2, 'check row 2')
  235. equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '3 hoch', 'check row 3')
  236. equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 3')
  237. equal(el.find('tbody > tr:nth-child(3) > td').length, 0, 'check row 3')
  238. App.TicketPriority.refresh([], {clear: true})
  239. result = table.update({sync: true, objects: App.TicketPriority.search({sortBy:'name', order: 'ASC'})})
  240. equal(result[0], 'emptyList')
  241. equal(el.find('table > thead > tr').length, 1, 'row count')
  242. equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Keine Einträge', 'check header')
  243. equal(el.find('tbody > tr:nth-child(1) > td').length, 0, 'check row 1')
  244. })