model.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. window.onload = function() {
  2. // TicketPriority search
  3. QUnit.test( "TicketPriority search tests", assert => {
  4. App.TicketPriority.refresh( [
  5. {
  6. id: 1,
  7. name: '1 low',
  8. note: 'some note 1',
  9. active: true,
  10. created_at: '2014-06-10T11:17:34.000Z',
  11. },
  12. {
  13. id: 2,
  14. name: '2 normal',
  15. note: 'some note 2',
  16. active: false,
  17. created_at: '2014-06-10T10:17:33.000Z',
  18. },
  19. {
  20. id: 3,
  21. name: '3 high',
  22. note: 'some note 3',
  23. active: true,
  24. created_at: '2014-06-10T10:17:44.000Z',
  25. },
  26. {
  27. id: 4,
  28. name: '4 very high',
  29. note: 'some note 4',
  30. active: true,
  31. created_at: '2014-06-10T10:17:54.000Z',
  32. },
  33. ] )
  34. priorities = App.TicketPriority.search({sortBy:'created_at', order: 'ASC'})
  35. assert.equal('2 normal', priorities[0].name, 'check 1 entry')
  36. assert.equal('3 high', priorities[1].name, 'check 2 entry')
  37. assert.equal('4 very high', priorities[2].name, 'check 3 entry')
  38. assert.equal('1 low', priorities[3].name, 'check 4 entry')
  39. assert.equal(undefined, priorities[4], 'check 5 entry')
  40. priorities = App.TicketPriority.search({sortBy:'created_at', order: 'DESC'})
  41. assert.equal('1 low', priorities[0].name, 'check 4 entry')
  42. assert.equal('4 very high', priorities[1].name, 'check 3 entry')
  43. assert.equal('3 high', priorities[2].name, 'check 2 entry')
  44. assert.equal('2 normal', priorities[3].name, 'check 1 entry')
  45. assert.equal(undefined, priorities[4], 'check 5 entry')
  46. priorities = App.TicketPriority.search({filter: { name: '4 very high' }, sortBy:'name', order: 'ASC'})
  47. assert.equal('4 very high', priorities[0].name, 'check name filter')
  48. assert.equal(undefined, priorities[1], 'check name filter is undefined')
  49. });
  50. // PublicLink search
  51. QUnit.test( "PublicLink search tests", assert => {
  52. App.PublicLink.refresh( [
  53. {
  54. id: 1,
  55. link: 'https://zammad.org',
  56. title: 'Zammad Community',
  57. description: 'Zammad is a very cool application',
  58. screen: ['login'],
  59. prio: 1,
  60. },
  61. {
  62. id: 2,
  63. link: 'https://zammad.com',
  64. title: 'Zammad <3',
  65. description: 'Zammad is a very cool application',
  66. screen: ['login', 'password_reset', 'signup'],
  67. prio: 2,
  68. },
  69. {
  70. id: 3,
  71. link: 'https://zammad.biz',
  72. title: 'Zammad BIZ',
  73. description: 'Zammad is a very cool application',
  74. screen: ['login', 'signup'],
  75. prio: 3,
  76. },
  77. ] )
  78. public_links = App.PublicLink.search({filter: { screen: ['login'] }, sortBy:'prio', order: 'ASC'})
  79. assert.equal('Zammad Community', public_links[0].title, 'check link 1 ASC')
  80. assert.equal('Zammad <3', public_links[1].title, 'check link 2 ASC')
  81. assert.equal('Zammad BIZ', public_links[2].title, 'check link 3 ASC')
  82. public_links = App.PublicLink.search({filter: { screen: ['login'] }, sortBy:'prio', order: 'DESC'})
  83. assert.equal('Zammad BIZ', public_links[0].title, 'check link 1 DESC')
  84. assert.equal('Zammad <3', public_links[1].title, 'check link 2 DESC')
  85. assert.equal('Zammad Community', public_links[2].title, 'check link 3 DESC')
  86. public_links = App.PublicLink.search({filter: { screen: ['signup', 'password_reset'] }, sortBy:'prio', order: 'ASC'})
  87. assert.equal('Zammad <3', public_links[0].title, 'check signup link 1 ASC')
  88. assert.equal('Zammad BIZ', public_links[1].title, 'check signup link 2 ASC')
  89. assert.equal(undefined, public_links[2], 'check signup links')
  90. public_links = App.PublicLink.search({filter: { screen: ['password_reset'] }, sortBy:'prio', order: 'ASC'})
  91. assert.equal('Zammad <3', public_links[0].title, 'check password_reset link 1 ASC')
  92. assert.equal(undefined, public_links[1], 'check password_reset links')
  93. });
  94. // model
  95. QUnit.test( "model loadAssets tests - 1", assert => {
  96. window.refreshCounter1 = 0
  97. var callback1 = function(state, triggerType) {
  98. window.refreshCounter1 = window.refreshCounter1 + 1
  99. assert.equal(state.id, 9999, 'id check')
  100. if (window.refreshCounter1 == 1) {
  101. assert.equal('full', triggerType, 'trigger type check')
  102. }
  103. else {
  104. assert.equal('refresh', triggerType, 'trigger type check')
  105. }
  106. if ( window.refreshCounter1 == 1 ) {
  107. App.Collection.loadAssets({
  108. TicketState: {
  109. 9999: {
  110. name: 'some some name', id: 9999, updated_at: "2014-11-07T23:43:08.000Z"
  111. }
  112. }
  113. })
  114. }
  115. if ( window.refreshCounter1 == 2 ) {
  116. App.Collection.loadAssets({
  117. TicketState: {
  118. 9999: {
  119. name: 'some some name', id: 9999, updated_at: "2014-11-07T23:43:08.000Z"
  120. }
  121. }
  122. })
  123. }
  124. }
  125. App.Collection.loadAssets({
  126. TicketState: {
  127. 9999: {
  128. name: 'some some name', id: 9999, updated_at: "2014-11-06T23:43:08.000Z"
  129. }
  130. }
  131. })
  132. // do not force, but bild on every change/loadAssets
  133. App.TicketState.full(9999, callback1, false, true)
  134. });
  135. App.Delay.set( function() {
  136. QUnit.test( "model loadAssets tests - 1 / check refresh counter", assert => {
  137. assert.equal(window.refreshCounter1, 2, 'check refresh counter')
  138. });
  139. },
  140. 1000
  141. );
  142. QUnit.test( "model loadAssets tests - 2", assert => {
  143. window.refreshCounter2 = 0
  144. var callback2 = function(state, triggerType) {
  145. window.refreshCounter2 = window.refreshCounter2 + 1
  146. assert.equal(state.id, 10000, 'id check')
  147. if (window.refreshCounter2 == 1) {
  148. assert.equal('full', triggerType, 'trigger type check')
  149. }
  150. else {
  151. assert.equal('refresh', triggerType, 'trigger type check')
  152. }
  153. if ( window.refreshCounter2 == 1 ) {
  154. App.Collection.loadAssets({
  155. TicketState: {
  156. 10000: {
  157. name: 'some some name', id: 10000, updated_at: "2014-11-07T23:43:08.000Z"
  158. }
  159. }
  160. })
  161. }
  162. if ( window.refreshCounter2 == 2 ) {
  163. App.Collection.loadAssets({
  164. TicketState: {
  165. 10000: {
  166. name: 'some some name', id: 10000, updated_at: "2014-11-05T23:43:08.000Z"
  167. }
  168. }
  169. })
  170. }
  171. }
  172. App.Collection.loadAssets({
  173. TicketState: {
  174. 10000: {
  175. name: 'some some name', id: 10000, updated_at: "2014-11-06T23:43:08.000Z"
  176. }
  177. }
  178. })
  179. // do not force, but bild on every change/loadAssets
  180. App.TicketState.full(10000, callback2, false, true)
  181. });
  182. App.Delay.set( function() {
  183. QUnit.test( "model loadAssets tests - 2 / check refresh counter", assert => {
  184. assert.equal(window.refreshCounter2, 2, 'check refresh counter')
  185. });
  186. },
  187. 1200
  188. );
  189. QUnit.test( "model loadAssets tests - 3", assert => {
  190. window.refreshCounter3 = 0
  191. var callback3 = function(state, triggerType) {
  192. window.refreshCounter3 = window.refreshCounter3 + 1
  193. assert.equal(state.id, 10001, 'id check')
  194. if (window.refreshCounter3 == 1) {
  195. assert.equal('full', triggerType, 'trigger type check')
  196. }
  197. else {
  198. assert.equal('refresh', triggerType, 'trigger type check')
  199. }
  200. if ( window.refreshCounter3 == 1 ) {
  201. App.Collection.loadAssets({
  202. TicketState: {
  203. 10001: {
  204. name: 'some some name', id: 10001, updated_at: "2014-11-07T23:43:08.000Z"
  205. }
  206. }
  207. })
  208. }
  209. if ( window.refreshCounter3 == 2 ) {
  210. App.Collection.loadAssets({
  211. TicketState: {
  212. 10001: {
  213. name: 'some some name', id: 10001, updated_at: "2014-11-08T23:43:08.000Z"
  214. }
  215. }
  216. })
  217. }
  218. }
  219. App.Collection.loadAssets({
  220. TicketState: {
  221. 10001: {
  222. name: 'some some name', id: 10001, updated_at: "2014-11-06T23:43:08.000Z"
  223. }
  224. }
  225. })
  226. // do not force, but bild on every change/loadAssets
  227. App.TicketState.full(10001, callback3, false, true)
  228. });
  229. App.Delay.set( function() {
  230. QUnit.test( "model loadAssets tests - 3 / check refresh counter", assert => {
  231. assert.equal(window.refreshCounter3, 3, 'check refresh counter')
  232. });
  233. },
  234. 1400
  235. );
  236. QUnit.test("updateAttributes will change existing attributes and add new ones", assert => {
  237. App.Ticket.resetAttributes();
  238. var attributesBefore = _.clone(App.Ticket.configure_attributes);
  239. var updateAttribute = _.clone(attributesBefore[0]);
  240. updateAttribute['new_option_1239393'] = 1;
  241. App.Ticket.updateAttributes([
  242. updateAttribute,
  243. {
  244. name: 'new_attribute_1010101',
  245. display: 'New Attribute',
  246. tag: 'input',
  247. readonly: 1,
  248. },
  249. ]);
  250. var attributesAfterUpdate = _.clone(App.Ticket.configure_attributes);
  251. assert.equal(attributesAfterUpdate.length, attributesBefore.length + 1, 'new attributes list contains 1 more elements')
  252. assert.equal(attributesAfterUpdate[0]['new_option_1239393'], 1, 'first element of the new attributes is number')
  253. assert.equal(attributesAfterUpdate[0]['name'], 'number', 'first element of the new attributes got updated with the new option')
  254. assert.equal(attributesAfterUpdate[1]['name'], 'new_attribute_1010101', 'new attributes list contains the new element')
  255. App.Ticket.resetAttributes();
  256. var attributesAfterReset = _.clone(App.Ticket.configure_attributes);
  257. assert.equal(attributesAfterReset.length, attributesBefore.length, 'new attributes list has the same elements after reset')
  258. assert.equal(attributesAfterReset[0]['new_option_1239393'], undefined, 'first element of the new attributes has no attribute new_option_1239393')
  259. });
  260. }