jirb-online / trunk / test / javascript / RubyConsoleInputTest.html

<html>
<head>
    <title>Test Page for RubyConsoleInput</title>
    <script language="javascript" src="../../tools/jsunit/app/jsUnitCore.js"></script>
    <script language="javascript" src="../../test/javascript/JsUnitTestHelper.js"></script>

    <script language="javascript" src="../../src/webapp/javascript/lib/jquery-1.3.2.js"></script>
    <script language="javascript" src="../../src/webapp/javascript/lib/DUI.js"></script>
    <script language="javascript" src="../../src/webapp/javascript/core/RubyConsoleInput.js"></script>

</head>
<body>
<script language="javascript">
    var rubyConsoleInput;

    function setUp() {
        rubyConsoleInput = new RubyConsoleInput('#console_window_1', ["i = 'str'", "puts i", "i << 'blah'"]);
        $('#console_window_1 .line').val('');
        $('#console_window_1 .please_wait').hide();
    }

    function testShouldDisplayPleaseWaitMessage() {
        rubyConsoleInput.displayPleaseWait(true);
        assertEquals(true, $('#console_window_1 .please_wait').is(':visible'));
    }

    function testShouldHidePleaseWaitMessage() {
        rubyConsoleInput.displayPleaseWait(true);
        rubyConsoleInput.displayPleaseWait(false);
        assertEquals(false, $('#console_window_1 .please_wait').is(':visible'));
    }

    function testShouldClearInputLine() {
        $('#console_window_1 .line').val('existing text');
        $('#console_window_1 .line').attr('rows', 3);
        $('#console_window_1 .line').css('height', '20em');

        rubyConsoleInput.clearInputLine();

        assertEquals('', $('#console_window_1 .line').val());
        assertEquals(1, $('#console_window_1 .line').attr('rows'));
        assertEquals('1.2em', $('#console_window_1 .line').css('height'));
    }

    function testShouldPrepareForMultilineInput() {
        $('#console_window_1 .line').val('existing text');

        rubyConsoleInput.prepareForNextLine();

        assertEquals('existing text\n', $('#console_window_1 .line').val());
        assertEquals(2, $('#console_window_1 .line').attr('rows'));
        assertEquals('2.4em', $('#console_window_1 .line').css('height'));
    }

    function testShouldSetFocusOnInputLine() {
        $('#console_window_1 .line').blur();
        rubyConsoleInput.focus();
        assertTrue($('#console_window_1 .line').is('.focus'))
    }

    function testShouldLoseFocusFromInputLine() {
        $('#console_window_1 .line').focus()
        rubyConsoleInput.blur();
        assertFalse($('#console_window_1 .line').is('.focus'))
    }

    function testShouldMoveUpInHistory() {
        $('#console_window_1 .line').val('existing text');

        rubyConsoleInput.upInHistory();
        assertEquals("i << 'blah'", $('#console_window_1 .line').val());

        rubyConsoleInput.upInHistory();
        assertEquals("puts i", $('#console_window_1 .line').val());

        rubyConsoleInput.upInHistory();
        assertEquals("i = 'str'", $('#console_window_1 .line').val());

        rubyConsoleInput.upInHistory();
        assertEquals("i = 'str'", $('#console_window_1 .line').val());
    }

    function testShouldMoveDownInHistory() {
        $('#console_window_1 .line').val('existing text');

        rubyConsoleInput.downInHistory();
        assertEquals('', $('#console_window_1 .line').val());

        rubyConsoleInput.upInHistory();
        rubyConsoleInput.upInHistory();
        rubyConsoleInput.upInHistory();
        rubyConsoleInput.downInHistory();
        assertEquals("puts i", $('#console_window_1 .line').val());

        rubyConsoleInput.downInHistory();
        assertEquals("i << 'blah'", $('#console_window_1 .line').val());

        rubyConsoleInput.downInHistory();
        assertEquals('', $('#console_window_1 .line').val());
    }

    function testShouldAddToHistory() {
        rubyConsoleInput.addToHistory("x = 'x'");

        rubyConsoleInput.upInHistory();
        assertEquals("x = 'x'", $('#console_window_1 .line').val());

        rubyConsoleInput.upInHistory();
        assertEquals("i << 'blah'", $('#console_window_1 .line').val());

        rubyConsoleInput.downInHistory();
        assertEquals("x = 'x'", $('#console_window_1 .line').val());

        rubyConsoleInput.downInHistory();
        assertEquals('', $('#console_window_1 .line').val());
    }

    jsUnitSetOnLoad(window, function() { runPageTests("../../tools/jsunit/"); });
</script>

<div id="console_window_1">
    <span class="console">
    </span>
    <textarea class="line" rows="1" cols="70" style="height:1.2em;"></textarea>
    <span class='please_wait' style="display:none" >Please wait...</span>
</div>
</body>
</html>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.