htmltestsuite-row-tests.html 4.36 KB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">

<!--
Copyright 2004 ThoughtWorks, Inc

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JsUnit Utility Tests</title>
    <link rel="stylesheet" type="text/css" href="../../jsunit/css/jsUnitStyle.css">
    <script language="JavaScript" type="text/javascript" src="../../jsunit/app/jsUnitCore.js"></script>
    <script language="JavaScript" type="text/javascript" src="../jsmock/mock.js"></script>
    <script language="JavaScript" type="text/javascript" src="../../core/lib/prototype.js"></script>
    <script language="JavaScript" type="text/javascript" src="../../core/scripts/htmlutils.js"></script>
    <script language="JavaScript" type="text/javascript" src="../../core/scripts/selenium-commandhandlers.js"></script>
    <script language="JavaScript" type="text/javascript" src="../../core/scripts/selenium-browserdetect.js"></script>
    <script language="JavaScript" type="text/javascript" src="../../core/scripts/selenium-testrunner.js"></script>
    <script language="JavaScript" type="text/javascript" src="../dummy-logging.js"></script>
    <script language="JavaScript" type="text/javascript">

        var MockSeleniumFrame = Class.create();
        Object.extend(MockSeleniumFrame.prototype, {
            initialize: function() {
                this.fireLoading = false;
            },
            load: function() {
                this.location = arguments[0];
                if (this.fireLoading) this.loadListener();
            },
            addLoadListener: function(listener) {
                this.loadListener = listener;
            }
        });

        function setUp() {
            mockFrame = new MockSeleniumFrame();
            mockHtmlTestSuite = {};
            suiteRow = new HtmlTestSuiteRow($("trRow"), mockFrame, mockHtmlTestSuite);
        }

        function testShouldLoadTestCaseWhenRowElementsClick() {
            assertNotUndefined($("link").onclick);
            suiteRow.testCaseLoaded = false;
            suiteRow.loadTestCase = function() {
                suiteRow.testCaseLoaded = true;
            }
            // testing onclick method must return false to prevent event spreading
            assertFalse($("link").onclick());
            assert(suiteRow.testCaseLoaded);
        }

        function testLoadTestCaseShouldChangeTestFramesLocation() {
            mockFrame.fireLoading = false;
            mockHtmlTestSuite.currentRowUnselected = false;
            mockHtmlTestSuite.unselectCurrentRow = function() {
                this.currentRowUnselected = true;
            };
            assertUndefined(mockFrame.location);
            suiteRow.loadTestCase();
            assertEquals($("link").href, mockFrame.location);
            assert(mockHtmlTestSuite.currentRowUnselected);
        }

        function testMarkFailedShouldMarkTrElementFailed() {
            suiteRow.markFailed();
            assertEquals("status_failed", $("trRow").className);
        }

        function testMarkPassedShouldMarkTrElementPassed() {
            $("trRow").bgColor = "";
            suiteRow.markPassed();
            assertEquals("status_passed", $("trRow").className);
        }

        function testSelectShouldMarkTrElementSelected() {
            $("trRow").bgColor = "";
            suiteRow.select();
            assertEquals("selected", $("trRow").className);
        }

    </script>
</head>

<body>
<table id="suiteTable" cellpadding="1" cellspacing="1" border="1" class="selenium">
    <tbody>
        <tr id="trRow"><td><a id="link" href="test1.html">test1</a></td></tr>
        <tr id="trRow2"><td><a id="link" href="test2.html">test2</a></td></tr>
    </tbody>
</table>

</body>
</html>