/test/test.html

http://github.com/adamsanderson/jquerycommandline · HTML · 176 lines · 147 code · 29 blank · 0 comment · 0 complexity · e9339156e5bc41f8ff01f35a650fec81 MD5 · raw file

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
  5. <title>JSSpec results</title>
  6. <link rel="stylesheet" type="text/css" href="JSSpec.css" />
  7. <script type="text/javascript" src="diff_match_patch.js"></script>
  8. <script type="text/javascript" src="JSSpec.js"></script>
  9. <script type="text/javascript" src="../js/jquery-1.2.6.js"></script>
  10. <script type="text/javascript" src="../js/jquery.command_line.js"></script>
  11. <script type="text/javascript" src="../js/json2.js"></script>
  12. <script type="text/javascript">
  13. describe('Command Line', {
  14. before: function(){
  15. // Setup the command line
  16. cl = $('#console').commandLine().data('commandLine.instance');
  17. },
  18. after: function(){
  19. // Remove the command line
  20. $('#console').data('commandLine.instance', null);
  21. $('#console').html('');
  22. },
  23. 'Should have a log': function() {
  24. value_of($('#console .log')).should_not_be_empty();
  25. },
  26. 'Should have a prompt': function() {
  27. value_of($('#console .prompt')).should_not_be_empty();
  28. },
  29. 'Entering valid commands should log them to the screen': function(){
  30. cl.command('1+1');
  31. value_of($('#console .log .command').length).should_be(1);
  32. value_of($('#console .log .command').text()).should_be('1+1');
  33. },
  34. 'Entering commands should clear the prompt': function(){
  35. cl.prompt.val("1+1");
  36. cl.command(cl.prompt.val());
  37. value_of($('#console .prompt').val()).should_be_empty();
  38. },
  39. 'Responses should be logged': function(){
  40. cl.command('1+1');
  41. cl.command('"a"');
  42. var responses = $('#console .log .response');
  43. value_of(responses.length).should_be(2);
  44. value_of($(responses[0]).text()).should_be('2');
  45. value_of($(responses[1]).text()).should_be('"a"');
  46. },
  47. 'Console should display Arrays': function(){
  48. cl.command('[1,2,3]');
  49. value_of($('#console .log .response')).should_not_be_empty();
  50. value_of($('#console .log .response').text()).should_be('[1,2,3]');
  51. },
  52. 'Console should display Hashes': function(){
  53. cl.command('{cake: "awesome!"}');
  54. value_of($('#console .log .response')).should_not_be_empty();
  55. value_of($('#console .log .response').text()).should_be('{"cake":"awesome!"}');
  56. },
  57. 'Console should display "undefined"': function(){
  58. cl.command('undefined');
  59. value_of($('#console .log .response')).should_not_be_empty();
  60. value_of($('#console .log .response').text()).should_be('undefined');
  61. },
  62. 'Console should display Functions': function(){
  63. cl.command('f = function(x){x+1}');
  64. value_of($('#console .log .response')).should_not_be_empty();
  65. delete f;
  66. },
  67. 'Console should display XML in supported browsers [[JSSpec.Browser.FF2 || JSSpec.Browser.FF3]]': function() {
  68. cl.command("<person name='joe'></person>");
  69. value_of($('#console .log .response').text()).should_be('<person name="joe"/>');
  70. },
  71. 'Console should display errors for invalid code': function(){
  72. cl.command('apple / lobster + 7!!');
  73. value_of($('#console .log .response')).should_be_empty();
  74. value_of($('#console .log .error').length).should_be(1);
  75. },
  76. 'Console should support commands as well as evaluation': function(){
  77. cl.command('about');
  78. value_of($('#console .log .response')).should_not_be_empty();
  79. }
  80. });
  81. describe('Command Line History', {
  82. before: function(){
  83. // Setup the command line
  84. cl = $('#console').commandLine().data('commandLine.instance');
  85. h = cl.history;
  86. commands = [
  87. '1',
  88. '1+1',
  89. '"three"'
  90. ];
  91. $.each(commands, function(n, cmd){ cl.command(cmd); });
  92. },
  93. after: function(){
  94. // Remove the command line
  95. $('#console').data('commandLine.instance', null);
  96. $('#console').html('');
  97. },
  98. 'History should included each executed command': function(){
  99. value_of(h.items).should_be(commands);
  100. },
  101. 'Going back should return the previous command': function(){
  102. value_of(h.back()).should_be(commands[2]);
  103. },
  104. 'You should not be able to go forward past the present command': function(){
  105. value_of(h.forward()).should_be('');
  106. },
  107. 'Stashing should store the current command': function(){
  108. var cmd = '"hi!"';
  109. h.stash(cmd);
  110. h.back();
  111. value_of(h.forward()).should_be(cmd);
  112. },
  113. 'You should not be able to go beyond the first command': function(){
  114. var i = 10; while(i-- > 0){h.back();}
  115. value_of(h.back()).should_be(commands[0]);
  116. },
  117. 'If there is a limit, no more than that number of commands should be stored': function(){
  118. h.limit = 5;
  119. var i = 10; while(i-- > 0){
  120. $.each(commands, function(n, cmd){ cl.command(cmd); });
  121. }
  122. value_of(h.items.length).should_be(h.limit);
  123. }
  124. });
  125. describe('Response Handlers', {
  126. before: function(){
  127. // Setup the command line
  128. cl = $('#console').commandLine().data('commandLine.instance');
  129. },
  130. after: function(){
  131. // Remove the command line
  132. $('#console').data('commandLine.instance', null);
  133. $('#console').html('');
  134. },
  135. 'Response Handlers Should Handle jQuery Specially': function(){
  136. cl.command('$("cake")');
  137. value_of($('#console .log .response').text()).should_match(/jQuery/);
  138. }
  139. });
  140. </script>
  141. </head>
  142. <body>
  143. <div id='test_body' style='display: none'>
  144. <div id='console'></div>
  145. </div>
  146. </body>
  147. </html>