summaryrefslogtreecommitdiff
path: root/test/js
diff options
context:
space:
mode:
Diffstat (limited to 'test/js')
-rw-r--r--test/js/index.html68
-rw-r--r--test/js/tests.js48
2 files changed, 55 insertions, 61 deletions
diff --git a/test/js/index.html b/test/js/index.html
index f89c57af..746dc374 100644
--- a/test/js/index.html
+++ b/test/js/index.html
@@ -4,15 +4,40 @@
<title>Coverage.py Javascript Test Suite</title>
<link rel="stylesheet" href="../qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="../../coverage/htmlfiles/jquery-1.4.3.min.js"></script>
+ <script type='text/javascript' src="../../coverage/htmlfiles/jquery.isonscreen.js"></script>
<script type="text/javascript" src="../../coverage/htmlfiles/coverage_html.js"></script>
<script type="text/javascript" src="../qunit/qunit.js"></script>
+ <script type="text/javascript" src="../qunit/jquery.tmpl.min.js"></script>
<style>
- .red { background-color: red; }
- .white { }
- .blue { background-color: blue; }
+ .r { background-color: red; }
+ .w { }
+ .b { background-color: blue; }
</style>
+ <!-- Templates for the coverage report output -->
+ <script id="fixture-template" type="text/x-jquery-tmpl">
+ <table cellspacing='0' cellpadding='0'>
+ <tr>
+ <td class='linenos' valign='top'>
+ <!-- #lineno-template goes here -->
+ </td>
+ <td class='text' valign='top'>
+ <!-- #text-template goes here -->
+ </td>
+ </tr>
+ </table>
+ </script>
+
+ <script id="lineno-template" type="text/x-jquery-tmpl">
+ <p id='n${number}' class='${klass}'><a href='#n${number}'>${number}</a></p>
+ </script>
+
+ <script id="text-template" type="text/x-jquery-tmpl">
+ <p id='t${number}' class='${klass}'>Hello, world!</p>
+ </script>
+
+ <!-- Pull in the tests -->
<script type="text/javascript" src="tests.js"></script>
</head>
@@ -22,41 +47,6 @@
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
- <div id="qunit-fixture">
-
- <div id='rrwwrr'>
- <p class='t1 red'>red</p>
- <p class='t2 red'>red</p>
- <p class='t3 white'>white</p>
- <p class='t4 white'>white</p>
- <p class='t5 red'>red</p>
- <p class='t6 red'>red</p>
- </div>
-
- <div id='rb'>
- <p class='t1 red'>red</p>
- <p class='t2 blue'>blue</p>
- </div>
-
- <div id='wrrwrrw'>
- <p class='t1 white'>white</p>
- <p class='t2 red'>red</p>
- <p class='t3 red'>red</p>
- <p class='t4 white'>white</p>
- <p class='t5 red'>red</p>
- <p class='t6 red'>red</p>
- <p class='t7 white'>white</p>
- </div>
-
- <div id='rrrbbb'>
- <p class='t1 red'>red</p>
- <p class='t2 red'>red</p>
- <p class='t3 red'>red</p>
- <p class='t4 blue'>blue</p>
- <p class='t5 blue'>blue</p>
- <p class='t6 blue'>blue</p>
- </div>
-
- </div>
+ <div id="qunit-fixture"></div>
</body>
</html>
diff --git a/test/js/tests.js b/test/js/tests.js
index d298cebe..cd4f9d58 100644
--- a/test/js/tests.js
+++ b/test/js/tests.js
@@ -1,53 +1,57 @@
-// To make the code more testable, we monkeypatch some of it.
-$.extend(coverage, {
- line_elt: function(n) {
- return $(coverage.fixture + " .t" + n);
- },
- num_elt: function(n) {
- return $(coverage.fixture + " .n" + n);
- },
- scroll_to_selection: function() {}
-});
+// Tests of coverage.py HTML report chunk navigation.
// Test helpers
function selection_is(sel) {
- equals(coverage.sel_begin, sel[0]);
- equals(coverage.sel_end, sel[1]);
+ var beg = sel[0], end = sel[1];
+ equals(coverage.sel_begin, beg);
+ equals(coverage.sel_end, end);
+ equals(coverage.code_container().find(".highlight").length, end-beg);
+}
+
+function build_fixture(spec) {
+ $("#fixture-template").tmpl().appendTo("#qunit-fixture");
+ for (var i = 0; i < spec.length; i++) {
+ var data = {number: i+1, klass: spec.substr(i, 1)};
+ $("#lineno-template").tmpl(data).appendTo("#qunit-fixture .linenos");
+ $("#text-template").tmpl(data).appendTo("#qunit-fixture .text");
+ }
}
// Tests
$.each([
- ['rrwwrr', [1,3], [5,7]],
+ ['rrwwrrrr', [1,3], [5,9]],
['rb', [1,2], [2,3]],
- ['wrrwrrw', [2,4], [5,7]],
+ ['wrrwrrrrw', [2,4], [5,9]],
['rrrbbb', [1,4], [4,7]]
], function(i, params) {
+ // Each of these tests uses a fixture with two highlighted chunks.
+
var id = params[0];
var fixture = "#"+id;
var c1 = params[1];
var c2 = params[2];
function setup() {
- coverage.fixture = fixture;
+ build_fixture(id);
};
- test("first chunk on line 1 "+id, function() {
+ test("first chunk on line 1: "+id, function() {
setup();
coverage.to_first_chunk();
selection_is(c1);
});
- test("move to next chunk "+id, function() {
+ test("move to next chunk: "+id, function() {
setup();
coverage.to_first_chunk();
coverage.to_next_chunk();
selection_is(c2);
});
- test("move to first chunk "+id, function() {
+ test("move to first chunk: "+id, function() {
setup();
coverage.to_first_chunk();
coverage.to_next_chunk();
@@ -55,7 +59,7 @@ $.each([
selection_is(c1);
});
- test("move to previous chunk "+id, function() {
+ test("move to previous chunk: "+id, function() {
setup();
coverage.to_first_chunk();
coverage.to_next_chunk();
@@ -63,7 +67,7 @@ $.each([
selection_is(c1);
});
- test("next doesn't move after last chunk "+id, function() {
+ test("next doesn't move after last chunk: "+id, function() {
setup();
coverage.to_first_chunk();
coverage.to_next_chunk();
@@ -71,7 +75,7 @@ $.each([
selection_is(c2);
});
- test("prev doesn't move before first chunk "+id, function() {
+ test("prev doesn't move before first chunk: "+id, function() {
setup();
coverage.to_first_chunk();
coverage.to_next_chunk();
@@ -83,7 +87,7 @@ $.each([
});
test("jump from a line selected", function() {
- coverage.fixture = "#rrwwrr";
+ build_fixture("rrwwrr");
coverage.set_sel(3, 4);
coverage.to_next_chunk();
selection_is([5,7]);