Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

179 lines
6.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. Ext.test.session.addTest( 'Ext', {
  8. name: 'Template',
  9. planned: 22,
  10. setUp: function() {
  11. this.es = [];
  12. },
  13. tearDown: function() {
  14. Ext.each( this.es, function( el ) {
  15. if ( el instanceof Ext.Element ) {
  16. el.remove();
  17. } else {
  18. Ext.removeNode( el );
  19. }
  20. });
  21. this.es.length = 0;
  22. },
  23. // 3
  24. test_from: function() {
  25. var id = Ext.id();
  26. var el = Ext.getBody().createChild({
  27. tag: 'textarea',
  28. cls: 'x-hidden',
  29. id: id,
  30. html: '{0} {1}'
  31. });
  32. this.es.push( el );
  33. var tpl1 = Ext.Template.from( el, { complied: true } );
  34. var tpl2 = Ext.Template.from( el.dom, { complied: true } );
  35. var tpl3 = Ext.Template.from( id, { complied: true } );
  36. Y.Assert.areEqual( 'Hello World', tpl1.apply( [ 'Hello', 'World' ] ), 'Test template compiled from textarea value (using Ext.element)' );
  37. Y.Assert.areEqual( 'Hello World', tpl2.apply( [ 'Hello', 'World' ] ), 'Test template compiled from textarea value (using Html element)' );
  38. Y.Assert.areEqual( 'Hello World', tpl3.apply( [ 'Hello', 'World' ] ), 'Test template compiled from textarea value (using element id)' );
  39. },
  40. // 5
  41. test_append: function() {
  42. var container = Ext.getBody().createChild({
  43. tag: 'div',
  44. cls: 'x-hidden'
  45. });
  46. this.es.push( container );
  47. var div = container.createChild({
  48. tag: 'div',
  49. html: 'foobar'
  50. });
  51. var tpl = new Ext.Template( '<div>{0} {1}</div>', {
  52. compiled: true,
  53. disableFormats: true
  54. });
  55. var newel = tpl.append( container, [ 'Hello', 'World' ] );
  56. Y.Assert.areEqual( 'Hello World', newel.innerHTML, 'Test if the new element\'s innerHTML matches the template' );
  57. Y.Assert.areSame( newel, div.dom.nextSibling, 'Test if nextSibling is the created element' );
  58. Y.Assert.areSame( newel, container.dom.lastChild, 'Test if container\'s lastChild is the created element' );
  59. Y.Assert.areEqual( 'Hello World', div.dom.nextSibling.innerHTML, 'Test if nextSibling\'s innerHTML is from the template' );
  60. Y.Assert.areEqual( 'Hello World', container.dom.lastChild.innerHTML, 'Test if the container\'s firstChild innerHTML is from the template' );
  61. },
  62. // 3
  63. test_apply: function() {
  64. var tpl1 = new Ext.Template( '{0}{hello} {1}{world}. How are you {2}{name}?', {
  65. compiled: true,
  66. disableFormats: true
  67. });
  68. var tpl2 = new Ext.Template( '{hello} {world}. How are you {name:ellipsis(8)}?', {
  69. compiled: true
  70. });
  71. Y.Assert.areEqual( 'Hello World. How are you TestyMcTester?', tpl1.apply( [ 'Hello', 'World', 'TestyMcTester' ] ), 'Test apply with an array, no formats' );
  72. Y.Assert.areEqual( 'Hello World. How are you TestyMcTester?', tpl1.apply( { hello: 'Hello', world: 'World', name: 'TestyMcTester' } ), 'Test apply with an object, no formats' );
  73. Y.Assert.areEqual( 'Hello World. How are you Testy...?', tpl2.apply( { hello: 'Hello', world: 'World', name: 'TestyMcTester' } ), 'Test apply with an object, with formats' );
  74. },
  75. // apply is an alias for applyTemplate
  76. // 3
  77. test_insertAfter: function() {
  78. var container = Ext.getBody().createChild({
  79. tag: 'div',
  80. cls: 'x-hidden'
  81. });
  82. this.es.push( container );
  83. var div = container.createChild({
  84. tag: 'div',
  85. html: 'foobar'
  86. });
  87. var tpl = new Ext.Template( '<div>{0} {1}</div>', {
  88. compiled: true,
  89. disableFormats: true
  90. });
  91. var newel = tpl.insertAfter( div, [ 'Hello', 'World' ] );
  92. Y.Assert.areEqual( 'Hello World', newel.innerHTML, 'Test if the new element\'s innerHTML matches the template' );
  93. Y.Assert.areSame( newel, div.dom.nextSibling, 'Test if nextSibling is the created element' );
  94. Y.Assert.areEqual( 'Hello World', div.dom.nextSibling.innerHTML, 'Test if nextSibling\'s innerHTML is from the template' );
  95. },
  96. // 3
  97. test_insertBefore: function() {
  98. var container = Ext.getBody().createChild({
  99. tag: 'div',
  100. cls: 'x-hidden'
  101. });
  102. this.es.push( container );
  103. var div = container.createChild({
  104. tag: 'div',
  105. html: 'foobar'
  106. });
  107. var tpl = new Ext.Template( '<div>{0} {1}</div>', {
  108. compiled: true,
  109. disableFormats: true
  110. });
  111. var newel = tpl.insertBefore( div, [ 'Hello', 'World' ] );
  112. Y.Assert.areEqual( 'Hello World', newel.innerHTML, 'Test if the new element\'s innerHTML matches the template' );
  113. Y.Assert.areSame( newel, container.dom.firstChild, 'Test if the container\'s firstChild is the created element' );
  114. Y.Assert.areEqual( 'Hello World', container.dom.firstChild.innerHTML, 'Test if the container\s firstChild innerHTML is from the template' );
  115. },
  116. // 3
  117. test_insertFirst: function() {
  118. var container = Ext.getBody().createChild({
  119. tag: 'div',
  120. cls: 'x-hidden'
  121. });
  122. this.es.push( container );
  123. container.createChild({
  124. tag: 'div',
  125. html: 'foobar'
  126. });
  127. var tpl = new Ext.Template( '<div>{0} {1}</div>', {
  128. compiled: true,
  129. disableFormats: true
  130. });
  131. var newel = tpl.insertFirst( container, [ 'Hello', 'World' ] );
  132. Y.Assert.areEqual( 'Hello World', newel.innerHTML, 'Test if the new element\'s innerHTML matches the template' );
  133. Y.Assert.areSame( newel, container.dom.firstChild, 'Test if the container\'s firstChild is the created element' );
  134. Y.Assert.areEqual( 'Hello World', container.dom.firstChild.innerHTML, 'Test if the container\s firstChild innerHTML is from the template' );
  135. },
  136. // 1
  137. test_overwrite: function() {
  138. var container = Ext.getBody().createChild({
  139. tag: 'div',
  140. cls: 'x-hidden'
  141. });
  142. this.es.push( container );
  143. container.createChild({
  144. tag: 'div',
  145. html: 'foobar'
  146. });
  147. var tpl = new Ext.Template( '{0} {1}', {
  148. compiled: true,
  149. disableFormats: true
  150. });
  151. var newel = tpl.overwrite( container, [ 'Hello', 'World' ] );
  152. Y.Assert.areEqual( 'Hello World', container.dom.innerHTML, 'Test if the container innerHTML matches the template' );
  153. },
  154. // 1
  155. test_set: function() {
  156. var foo = new Ext.Template( '{1}{0}' );
  157. foo.set( '{0}{1}', true );
  158. Y.Assert.areEqual( 'foobar', foo.apply( [ 'foo', 'bar' ] ), 'Test recompiled template using set' );
  159. }
  160. });