/test/test.html
http://github.com/adamsanderson/jquerycommandline · HTML · 176 lines · 147 code · 29 blank · 0 comment · 0 complexity · e9339156e5bc41f8ff01f35a650fec81 MD5 · raw file
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
- <title>JSSpec results</title>
- <link rel="stylesheet" type="text/css" href="JSSpec.css" />
- <script type="text/javascript" src="diff_match_patch.js"></script>
- <script type="text/javascript" src="JSSpec.js"></script>
- <script type="text/javascript" src="../js/jquery-1.2.6.js"></script>
- <script type="text/javascript" src="../js/jquery.command_line.js"></script>
- <script type="text/javascript" src="../js/json2.js"></script>
- <script type="text/javascript">
- describe('Command Line', {
- before: function(){
- // Setup the command line
- cl = $('#console').commandLine().data('commandLine.instance');
- },
-
- after: function(){
- // Remove the command line
- $('#console').data('commandLine.instance', null);
- $('#console').html('');
- },
-
- 'Should have a log': function() {
- value_of($('#console .log')).should_not_be_empty();
- },
-
- 'Should have a prompt': function() {
- value_of($('#console .prompt')).should_not_be_empty();
- },
-
- 'Entering valid commands should log them to the screen': function(){
- cl.command('1+1');
- value_of($('#console .log .command').length).should_be(1);
- value_of($('#console .log .command').text()).should_be('1+1');
- },
-
- 'Entering commands should clear the prompt': function(){
- cl.prompt.val("1+1");
- cl.command(cl.prompt.val());
- value_of($('#console .prompt').val()).should_be_empty();
- },
-
- 'Responses should be logged': function(){
- cl.command('1+1');
- cl.command('"a"');
- var responses = $('#console .log .response');
-
- value_of(responses.length).should_be(2);
- value_of($(responses[0]).text()).should_be('2');
- value_of($(responses[1]).text()).should_be('"a"');
- },
-
- 'Console should display Arrays': function(){
- cl.command('[1,2,3]');
- value_of($('#console .log .response')).should_not_be_empty();
- value_of($('#console .log .response').text()).should_be('[1,2,3]');
- },
-
- 'Console should display Hashes': function(){
- cl.command('{cake: "awesome!"}');
- value_of($('#console .log .response')).should_not_be_empty();
- value_of($('#console .log .response').text()).should_be('{"cake":"awesome!"}');
- },
-
- 'Console should display "undefined"': function(){
- cl.command('undefined');
- value_of($('#console .log .response')).should_not_be_empty();
- value_of($('#console .log .response').text()).should_be('undefined');
- },
-
- 'Console should display Functions': function(){
- cl.command('f = function(x){x+1}');
- value_of($('#console .log .response')).should_not_be_empty();
- delete f;
- },
-
- 'Console should display XML in supported browsers [[JSSpec.Browser.FF2 || JSSpec.Browser.FF3]]': function() {
- cl.command("<person name='joe'></person>");
- value_of($('#console .log .response').text()).should_be('<person name="joe"/>');
- },
-
- 'Console should display errors for invalid code': function(){
- cl.command('apple / lobster + 7!!');
- value_of($('#console .log .response')).should_be_empty();
- value_of($('#console .log .error').length).should_be(1);
- },
-
- 'Console should support commands as well as evaluation': function(){
- cl.command('about');
- value_of($('#console .log .response')).should_not_be_empty();
- }
- });
-
- describe('Command Line History', {
- before: function(){
- // Setup the command line
- cl = $('#console').commandLine().data('commandLine.instance');
- h = cl.history;
-
- commands = [
- '1',
- '1+1',
- '"three"'
- ];
-
- $.each(commands, function(n, cmd){ cl.command(cmd); });
- },
-
- after: function(){
- // Remove the command line
- $('#console').data('commandLine.instance', null);
- $('#console').html('');
- },
-
- 'History should included each executed command': function(){
- value_of(h.items).should_be(commands);
- },
-
- 'Going back should return the previous command': function(){
- value_of(h.back()).should_be(commands[2]);
- },
-
- 'You should not be able to go forward past the present command': function(){
- value_of(h.forward()).should_be('');
- },
-
- 'Stashing should store the current command': function(){
- var cmd = '"hi!"';
- h.stash(cmd);
- h.back();
- value_of(h.forward()).should_be(cmd);
- },
-
- 'You should not be able to go beyond the first command': function(){
- var i = 10; while(i-- > 0){h.back();}
- value_of(h.back()).should_be(commands[0]);
- },
-
- 'If there is a limit, no more than that number of commands should be stored': function(){
- h.limit = 5;
- var i = 10; while(i-- > 0){
- $.each(commands, function(n, cmd){ cl.command(cmd); });
- }
- value_of(h.items.length).should_be(h.limit);
- }
- });
-
- describe('Response Handlers', {
- before: function(){
- // Setup the command line
- cl = $('#console').commandLine().data('commandLine.instance');
- },
-
- after: function(){
- // Remove the command line
- $('#console').data('commandLine.instance', null);
- $('#console').html('');
- },
-
- 'Response Handlers Should Handle jQuery Specially': function(){
- cl.command('$("cake")');
- value_of($('#console .log .response').text()).should_match(/jQuery/);
- }
- });
- </script>
- </head>
- <body>
- <div id='test_body' style='display: none'>
- <div id='console'></div>
- </div>
- </body>
- </html>