model_ui.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. window.onload = function() {
  2. // model
  3. test( "model ui basic tests", function() {
  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 ticket = new App.Ticket()
  28. ticket.load({
  29. id: 1000,
  30. title: 'some title <>&',
  31. state_id: 2,
  32. updated_at: '2014-11-07T23:43:08.000Z',
  33. date: '2015-02-07',
  34. textarea: "some new\nline"
  35. })
  36. App.i18n.set('en-us')
  37. equal( App.viewPrint( ticket, 'id' ), 1000)
  38. equal( App.viewPrint( ticket, 'title' ), 'some title &lt;&gt;&amp;')
  39. equal( App.viewPrint( ticket, 'state' ), 'open')
  40. equal( App.viewPrint( ticket, 'state_id' ), 'open')
  41. equal( App.viewPrint( ticket, 'not_existing' ), '-')
  42. equal( App.viewPrint( ticket, 'updated_at' ), '<time class="humanTimeFromNow " data-time="2014-11-07T23:43:08.000Z" title="11/07/2014 23:43">11/07/2014</time>')
  43. equal( App.viewPrint( ticket, 'date' ), '02/07/2015')
  44. equal( App.viewPrint( ticket, 'textarea' ), '<div>some new</div><div>line</div>')
  45. App.i18n.set('de-de')
  46. equal( App.viewPrint( ticket, 'id' ), 1000)
  47. equal( App.viewPrint( ticket, 'title' ), 'some title &lt;&gt;&amp;')
  48. equal( App.viewPrint( ticket, 'state' ), 'offen')
  49. equal( App.viewPrint( ticket, 'state_id' ), 'offen')
  50. equal( App.viewPrint( ticket, 'not_existing' ), '-')
  51. equal( App.viewPrint( ticket, 'updated_at' ), '<time class="humanTimeFromNow " data-time="2014-11-07T23:43:08.000Z" title="07.11.2014 23:43">07.11.2014</time>')
  52. equal( App.viewPrint( ticket, 'date' ), '07.02.2015')
  53. equal( App.viewPrint( ticket, 'textarea' ), '<div>some new</div><div>line</div>')
  54. App.i18n.set('en-us')
  55. ticket.state_id = 3
  56. equal( App.viewPrint( ticket, 'state' ), 'closed &lt;&gt;&amp;')
  57. equal( App.viewPrint( ticket, 'state_id' ), 'closed &lt;&gt;&amp;')
  58. App.i18n.set('de')
  59. equal( App.viewPrint( ticket, 'state' ), 'closed &lt;&gt;&amp;')
  60. equal( App.viewPrint( ticket, 'state_id' ), 'closed &lt;&gt;&amp;')
  61. // normal string
  62. data = {
  63. a: 1,
  64. b: 'abc',
  65. c: {
  66. displayName: function() { return "my displayName <>&" }
  67. },
  68. }
  69. equal( App.viewPrint( data, 'a' ), 1)
  70. equal( App.viewPrint( data, 'b' ), 'abc')
  71. equal( App.viewPrint( data, 'c' ), 'my displayName &lt;&gt;&amp;')
  72. });
  73. }