model.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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. ], { clear: true } )
  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. // Search results sorting with accents
  51. QUnit.test( "Search results sorting with accents", assert => {
  52. App.TicketPriority.refresh( [
  53. {
  54. id: 2,
  55. name: 'B priority',
  56. note: 'some note 2',
  57. active: false,
  58. created_at: '2014-06-10T10:17:33.000Z',
  59. },
  60. {
  61. id: 1,
  62. name: 'Ą priority',
  63. note: 'some note 1',
  64. active: true,
  65. created_at: '2014-06-10T11:17:34.000Z',
  66. },
  67. {
  68. id: 3,
  69. name: 'C priority',
  70. note: 'some note 3',
  71. active: true,
  72. created_at: '2014-06-10T10:17:44.000Z',
  73. },
  74. ], { clear: true } )
  75. priorities = App.TicketPriority.search({sortBy:'name', order: 'ASC'})
  76. assert.equal('Ą priority', priorities[0].name, 'check 1 entry')
  77. assert.equal('B priority', priorities[1].name, 'check 2 entry')
  78. assert.equal('C priority', priorities[2].name, 'check 3 entry')
  79. priorities = App.TicketPriority.search({sortBy:'name', order: 'DESC'})
  80. assert.equal('C priority', priorities[0].name, 'check 1 entry')
  81. assert.equal('B priority', priorities[1].name, 'check 2 entry')
  82. assert.equal('Ą priority', priorities[2].name, 'check 3 entry')
  83. });
  84. // PublicLink search
  85. QUnit.test( "PublicLink search tests", assert => {
  86. App.PublicLink.refresh( [
  87. {
  88. id: 1,
  89. link: 'https://zammad.org',
  90. title: 'Zammad Community',
  91. description: 'Zammad is a very cool application',
  92. screen: ['login'],
  93. prio: 1,
  94. },
  95. {
  96. id: 2,
  97. link: 'https://zammad.com',
  98. title: 'Zammad <3',
  99. description: 'Zammad is a very cool application',
  100. screen: ['login', 'password_reset', 'signup'],
  101. prio: 2,
  102. },
  103. {
  104. id: 3,
  105. link: 'https://zammad.biz',
  106. title: 'Zammad BIZ',
  107. description: 'Zammad is a very cool application',
  108. screen: ['login', 'signup'],
  109. prio: 3,
  110. },
  111. ] )
  112. public_links = App.PublicLink.search({filter: { screen: ['login'] }, sortBy:'prio', order: 'ASC'})
  113. assert.equal('Zammad Community', public_links[0].title, 'check link 1 ASC')
  114. assert.equal('Zammad <3', public_links[1].title, 'check link 2 ASC')
  115. assert.equal('Zammad BIZ', public_links[2].title, 'check link 3 ASC')
  116. public_links = App.PublicLink.search({filter: { screen: ['login'] }, sortBy:'prio', order: 'DESC'})
  117. assert.equal('Zammad BIZ', public_links[0].title, 'check link 1 DESC')
  118. assert.equal('Zammad <3', public_links[1].title, 'check link 2 DESC')
  119. assert.equal('Zammad Community', public_links[2].title, 'check link 3 DESC')
  120. public_links = App.PublicLink.search({filter: { screen: ['signup', 'password_reset'] }, sortBy:'prio', order: 'ASC'})
  121. assert.equal('Zammad <3', public_links[0].title, 'check signup link 1 ASC')
  122. assert.equal('Zammad BIZ', public_links[1].title, 'check signup link 2 ASC')
  123. assert.equal(undefined, public_links[2], 'check signup links')
  124. public_links = App.PublicLink.search({filter: { screen: ['password_reset'] }, sortBy:'prio', order: 'ASC'})
  125. assert.equal('Zammad <3', public_links[0].title, 'check password_reset link 1 ASC')
  126. assert.equal(undefined, public_links[1], 'check password_reset links')
  127. });
  128. // model
  129. QUnit.test( "model loadAssets tests - 1", assert => {
  130. window.refreshCounter1 = 0
  131. var callback1 = function(state, triggerType) {
  132. window.refreshCounter1 = window.refreshCounter1 + 1
  133. assert.equal(state.id, 9999, 'id check')
  134. if (window.refreshCounter1 == 1) {
  135. assert.equal('full', triggerType, 'trigger type check')
  136. }
  137. else {
  138. assert.equal('refresh', triggerType, 'trigger type check')
  139. }
  140. if ( window.refreshCounter1 == 1 ) {
  141. App.Collection.loadAssets({
  142. TicketState: {
  143. 9999: {
  144. name: 'some some name', id: 9999, updated_at: "2014-11-07T23:43:08.000Z"
  145. }
  146. }
  147. })
  148. }
  149. if ( window.refreshCounter1 == 2 ) {
  150. App.Collection.loadAssets({
  151. TicketState: {
  152. 9999: {
  153. name: 'some some name', id: 9999, updated_at: "2014-11-07T23:43:08.000Z"
  154. }
  155. }
  156. })
  157. }
  158. }
  159. App.Collection.loadAssets({
  160. TicketState: {
  161. 9999: {
  162. name: 'some some name', id: 9999, updated_at: "2014-11-06T23:43:08.000Z"
  163. }
  164. }
  165. })
  166. // do not force, but bild on every change/loadAssets
  167. App.TicketState.full(9999, callback1, false, true)
  168. });
  169. App.Delay.set( function() {
  170. QUnit.test( "model loadAssets tests - 1 / check refresh counter", assert => {
  171. assert.equal(window.refreshCounter1, 2, 'check refresh counter')
  172. });
  173. },
  174. 1000
  175. );
  176. QUnit.test( "model loadAssets tests - 2", assert => {
  177. window.refreshCounter2 = 0
  178. var callback2 = function(state, triggerType) {
  179. window.refreshCounter2 = window.refreshCounter2 + 1
  180. assert.equal(state.id, 10000, 'id check')
  181. if (window.refreshCounter2 == 1) {
  182. assert.equal('full', triggerType, 'trigger type check')
  183. }
  184. else {
  185. assert.equal('refresh', triggerType, 'trigger type check')
  186. }
  187. if ( window.refreshCounter2 == 1 ) {
  188. App.Collection.loadAssets({
  189. TicketState: {
  190. 10000: {
  191. name: 'some some name', id: 10000, updated_at: "2014-11-07T23:43:08.000Z"
  192. }
  193. }
  194. })
  195. }
  196. if ( window.refreshCounter2 == 2 ) {
  197. App.Collection.loadAssets({
  198. TicketState: {
  199. 10000: {
  200. name: 'some some name', id: 10000, updated_at: "2014-11-05T23:43:08.000Z"
  201. }
  202. }
  203. })
  204. }
  205. }
  206. App.Collection.loadAssets({
  207. TicketState: {
  208. 10000: {
  209. name: 'some some name', id: 10000, updated_at: "2014-11-06T23:43:08.000Z"
  210. }
  211. }
  212. })
  213. // do not force, but bild on every change/loadAssets
  214. App.TicketState.full(10000, callback2, false, true)
  215. });
  216. App.Delay.set( function() {
  217. QUnit.test( "model loadAssets tests - 2 / check refresh counter", assert => {
  218. assert.equal(window.refreshCounter2, 2, 'check refresh counter')
  219. });
  220. },
  221. 1200
  222. );
  223. QUnit.test( "model loadAssets tests - 3", assert => {
  224. window.refreshCounter3 = 0
  225. var callback3 = function(state, triggerType) {
  226. window.refreshCounter3 = window.refreshCounter3 + 1
  227. assert.equal(state.id, 10001, 'id check')
  228. if (window.refreshCounter3 == 1) {
  229. assert.equal('full', triggerType, 'trigger type check')
  230. }
  231. else {
  232. assert.equal('refresh', triggerType, 'trigger type check')
  233. }
  234. if ( window.refreshCounter3 == 1 ) {
  235. App.Collection.loadAssets({
  236. TicketState: {
  237. 10001: {
  238. name: 'some some name', id: 10001, updated_at: "2014-11-07T23:43:08.000Z"
  239. }
  240. }
  241. })
  242. }
  243. if ( window.refreshCounter3 == 2 ) {
  244. App.Collection.loadAssets({
  245. TicketState: {
  246. 10001: {
  247. name: 'some some name', id: 10001, updated_at: "2014-11-08T23:43:08.000Z"
  248. }
  249. }
  250. })
  251. }
  252. }
  253. App.Collection.loadAssets({
  254. TicketState: {
  255. 10001: {
  256. name: 'some some name', id: 10001, updated_at: "2014-11-06T23:43:08.000Z"
  257. }
  258. }
  259. })
  260. // do not force, but bild on every change/loadAssets
  261. App.TicketState.full(10001, callback3, false, true)
  262. });
  263. App.Delay.set( function() {
  264. QUnit.test( "model loadAssets tests - 3 / check refresh counter", assert => {
  265. assert.equal(window.refreshCounter3, 3, 'check refresh counter')
  266. });
  267. },
  268. 1400
  269. );
  270. QUnit.test("updateAttributes will change existing attributes and add new ones", assert => {
  271. App.Ticket.resetAttributes();
  272. var attributesBefore = _.clone(App.Ticket.configure_attributes);
  273. var updateAttribute = _.clone(attributesBefore[0]);
  274. updateAttribute['new_option_1239393'] = 1;
  275. App.Ticket.updateAttributes([
  276. updateAttribute,
  277. {
  278. name: 'new_attribute_1010101',
  279. display: 'New Attribute',
  280. tag: 'input',
  281. readonly: 1,
  282. },
  283. ]);
  284. var attributesAfterUpdate = _.clone(App.Ticket.configure_attributes);
  285. assert.equal(attributesAfterUpdate.length, attributesBefore.length + 1, 'new attributes list contains 1 more elements')
  286. assert.equal(attributesAfterUpdate[0]['new_option_1239393'], 1, 'first element of the new attributes is number')
  287. assert.equal(attributesAfterUpdate[0]['name'], 'number', 'first element of the new attributes got updated with the new option')
  288. assert.equal(attributesAfterUpdate[1]['name'], 'new_attribute_1010101', 'new attributes list contains the new element')
  289. App.Ticket.resetAttributes();
  290. var attributesAfterReset = _.clone(App.Ticket.configure_attributes);
  291. assert.equal(attributesAfterReset.length, attributesBefore.length, 'new attributes list has the same elements after reset')
  292. assert.equal(attributesAfterReset[0]['new_option_1239393'], undefined, 'first element of the new attributes has no attribute new_option_1239393')
  293. });
  294. }