model_ui.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. window.onload = function() {
  2. // model
  3. QUnit.test( "model ui basic tests", assert => {
  4. // load ref object
  5. App.Collection.loadAssets({
  6. TicketState: {
  7. 1: {
  8. name: 'new', id: 1, updated_at: "2014-11-07T23:43:08.000Z",
  9. },
  10. 2: {
  11. name: 'open', id: 2, updated_at: "2014-11-07T23:43:08.000Z",
  12. },
  13. 3: {
  14. name: 'closed <>&', id: 3, updated_at: "2014-11-07T23:43:08.000Z",
  15. },
  16. },
  17. })
  18. // create ticket
  19. var attribute1 = {
  20. name: 'date', display: 'date 1', tag: 'date', null: true
  21. };
  22. App.Ticket.configure_attributes.push( attribute1 )
  23. var attribute2 = {
  24. name: 'textarea', display: 'textarea 1', tag: 'textarea', null: true
  25. };
  26. App.Ticket.configure_attributes.push( attribute2 )
  27. var attribute3 = {
  28. name: 'link1', display: 'link 1', linktemplate: 'http://zammad.com', tag: 'input', null: true, translate: true
  29. };
  30. App.Ticket.configure_attributes.push( attribute3 )
  31. var attribute4 = {
  32. name: 'link2', display: 'link 1', linktemplate: 'http://zammad.com', tag: 'input', null: true
  33. };
  34. App.Ticket.configure_attributes.push( attribute4 )
  35. var attribute5 = {
  36. name: 'multiselect',
  37. display: 'Multi Select',
  38. tag: 'multiselect',
  39. options: [
  40. {
  41. name: 'One',
  42. value: '1',
  43. },
  44. {
  45. name: 'Two',
  46. value: '2',
  47. },
  48. {
  49. name: 'Three',
  50. value: '3',
  51. },
  52. {
  53. name: 'Four',
  54. value: '4',
  55. },
  56. {
  57. name: 'Five',
  58. value: '5',
  59. },
  60. ],
  61. linktemplate: '',
  62. null: true,
  63. relation: '',
  64. nulloption: true,
  65. maxlength: 255,
  66. multiple: true,
  67. }
  68. App.Ticket.configure_attributes.push(attribute5)
  69. var ticket = new App.Ticket()
  70. ticket.load({
  71. id: 1000,
  72. title: 'some title <>&',
  73. state_id: 2,
  74. updated_at: '2014-11-07T23:43:08.000Z',
  75. date: '2015-02-07',
  76. textarea: "some new\nline",
  77. link1: 'closed',
  78. link2: 'closed',
  79. multiselect: ['1', '2', '3']
  80. })
  81. App.i18n.set('en-us')
  82. assert.equal( App.viewPrint( ticket, 'id' ), 1000)
  83. assert.equal( App.viewPrint( ticket, 'title' ), 'some title &lt;&gt;&amp;')
  84. assert.equal( App.viewPrint( ticket, 'state' ), 'open')
  85. assert.equal( App.viewPrint( ticket, 'state_id' ), 'open')
  86. assert.equal( App.viewPrint( ticket, 'not_existing' ), '-')
  87. assert.equal( App.viewPrint( ticket, 'updated_at' ), '<time class="humanTimeFromNow " datetime="2014-11-07T23:43:08.000Z" title="11/07/2014 11:43 pm">11/07/2014</time>')
  88. assert.equal( App.viewPrint( ticket, 'date' ), '02/07/2015')
  89. assert.equal( App.viewPrint( ticket, 'textarea' ), '<div>some new</div><div>line</div>')
  90. assert.equal( App.viewPrint( ticket, 'link1' ), '<a href="http://zammad.com" target="_blank">closed</a>')
  91. assert.equal( App.viewPrint( ticket, 'link2' ), '<a href="http://zammad.com" target="_blank">closed</a>')
  92. assert.equal( App.viewPrint( ticket, 'multiselect' ), 'One, Two, Three', 'multiselect test 1')
  93. let stub = sinon.stub(App.Config, 'get')
  94. stub.withArgs('timezone_default').returns('Example/Timezone')
  95. let attr = App.Ticket.configure_attributes.find(e => { return e.name == 'updated_at' })
  96. attr.include_timezone = true
  97. assert.equal( App.viewPrint( ticket, 'updated_at' ), '<time class="humanTimeFromNow " datetime="2014-11-07T23:43:08.000Z" title="11/07/2014 11:43 pm Example/Timezone" timezone="Example/Timezone">11/07/2014</time>')
  98. attr.include_timezone = false
  99. stub.restore()
  100. App.i18n.set('de-de')
  101. assert.equal( App.viewPrint( ticket, 'id' ), 1000)
  102. assert.equal( App.viewPrint( ticket, 'title' ), 'some title &lt;&gt;&amp;')
  103. assert.equal( App.viewPrint( ticket, 'state' ), 'offen')
  104. assert.equal( App.viewPrint( ticket, 'state_id' ), 'offen')
  105. assert.equal( App.viewPrint( ticket, 'not_existing' ), '-')
  106. assert.equal( App.viewPrint( ticket, 'updated_at' ), '<time class="humanTimeFromNow " datetime="2014-11-07T23:43:08.000Z" title="07.11.2014 23:43">07.11.2014</time>')
  107. assert.equal( App.viewPrint( ticket, 'date' ), '07.02.2015')
  108. assert.equal( App.viewPrint( ticket, 'textarea' ), '<div>some new</div><div>line</div>')
  109. assert.equal( App.viewPrint( ticket, 'link1' ), '<a href="http://zammad.com" target="_blank">geschlossen</a>')
  110. assert.equal( App.viewPrint( ticket, 'link2' ), '<a href="http://zammad.com" target="_blank">closed</a>')
  111. assert.equal( App.viewPrint( ticket, 'multiselect' ), 'One, Two, Three', 'multiselect test 2')
  112. App.i18n.set('en-us')
  113. ticket.state_id = 3
  114. assert.equal( App.viewPrint( ticket, 'state' ), 'closed &lt;&gt;&amp;')
  115. assert.equal( App.viewPrint( ticket, 'state_id' ), 'closed &lt;&gt;&amp;')
  116. App.i18n.set('de')
  117. assert.equal( App.viewPrint( ticket, 'state' ), 'closed &lt;&gt;&amp;')
  118. assert.equal( App.viewPrint( ticket, 'state_id' ), 'closed &lt;&gt;&amp;')
  119. // multiselect single value in array
  120. ticket.load({
  121. multiselect: ['4']
  122. })
  123. assert.equal( App.viewPrint( ticket, 'multiselect' ), 'Four', 'multiselect single value in array')
  124. // multiselect single value in string
  125. ticket.load({
  126. multiselect: '4'
  127. })
  128. assert.equal( App.viewPrint( ticket, 'multiselect' ), 'Four', 'multiselect single value in string')
  129. // multiselect multiple value
  130. ticket.load({
  131. multiselect: ['3', '4', '5']
  132. })
  133. assert.equal( App.viewPrint( ticket, 'multiselect' ), 'Three, Four, Five', 'multiselect multiple value')
  134. // multiselect no value
  135. ticket.load({
  136. multiselect: null
  137. })
  138. assert.equal( App.viewPrint( ticket, 'multiselect' ), '-', 'multiselect no value')
  139. // normal string
  140. data = {
  141. a: 1,
  142. b: 'abc',
  143. c: {
  144. displayName: function() { return "my displayName <>&" }
  145. },
  146. }
  147. assert.equal( App.viewPrint( data, 'a' ), 1)
  148. assert.equal( App.viewPrint( data, 'b' ), 'abc')
  149. assert.equal( App.viewPrint( data, 'c' ), 'my displayName &lt;&gt;&amp;')
  150. });
  151. QUnit.test("Object 'active' neither handled nor translated when displayed #4529", assert => {
  152. App.User.configure_attributes.push({ name: 'active', display: __('Active'), tag: 'active' })
  153. App.User.refresh([
  154. {
  155. login: "nicole.braun@zammad.org",
  156. firstname: "Nicole",
  157. lastname: "Braun",
  158. email: "nicole.braun@zammad.org",
  159. web: "",
  160. phone: "",
  161. fax: "",
  162. mobile: "",
  163. street: "",
  164. zip: "",
  165. city: "",
  166. country: "",
  167. organization_id: 1,
  168. department: "",
  169. note: "",
  170. role_ids: [],
  171. group_ids: {},
  172. active: true,
  173. updated_at: "2023-08-23T08:59:15.437Z",
  174. organization_ids: [],
  175. address: "",
  176. vip: false,
  177. id: 2
  178. }
  179. ])
  180. App.i18n.set('de-de')
  181. user = App.User.find(2)
  182. assert.equal( App.viewPrint(user, 'active'), 'aktiv')
  183. user.active = false
  184. assert.equal(App.viewPrint(user, 'active'), 'nicht aktiv')
  185. user.active = null
  186. assert.equal( App.viewPrint(user, 'active'), '-')
  187. })
  188. }