Skip to content

Commit 3aea0bf

Browse files
Adam Ahmedmarijnh
authored andcommitted
Add line widget tests (for #2460)
1 parent 8d87f56 commit 3aea0bf

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

test/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ <h2>Test Suite</h2>
9696
<script src="../mode/xquery/test.js"></script>
9797
<script src="../addon/mode/multiplex_test.js"></script>
9898
<script src="vim_test.js"></script>
99+
<script src="widget_test.js"></script>
99100
<script src="emacs_test.js"></script>
100101
<script>
101102
window.onload = runHarness;

test/widget_test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
(function() {
2+
"use strict";
3+
4+
namespace = "widget_";
5+
6+
function makeLineWidget(cm, line, height, options) {
7+
var widgetEl = document.createElement('div');
8+
widgetEl.style.height = height + 'px';
9+
widgetEl.textContent = 'dummy text';
10+
11+
return {
12+
el : widgetEl,
13+
widget : cm.addLineWidget(line, widgetEl, options || {})
14+
};
15+
}
16+
17+
function testWidgetsAffectDocumentHeight(tagline, docLines, widgetLine, viewportLine) {
18+
var initialHeight = 100;
19+
var changedHeight = 150;
20+
21+
testCM('lineWidgetDocHeight_' + tagline, function(cm) {
22+
var startingDocHeight = cm.getScrollInfo().height;
23+
24+
if (viewportLine != null) {
25+
cm.scrollIntoView({ line : viewportLine, ch: 0 });
26+
}
27+
28+
var widgetInfo = makeLineWidget(cm, widgetLine, initialHeight);
29+
eq(startingDocHeight + initialHeight, cm.getScrollInfo().height, 'addLineWidget(): widget height should be added to document height.');
30+
31+
widgetInfo.el.style.height = changedHeight + 'px';
32+
widgetInfo.widget.changed();
33+
eq(startingDocHeight + changedHeight, cm.getScrollInfo().height, 'widget.changed(): widget height should be updated in document height.');
34+
35+
widgetInfo.widget.clear();
36+
eq(startingDocHeight, cm.getScrollInfo().height, 'widget.clear(): widget height should be removed from document height.');
37+
}, {
38+
value : new Array(docLines + 1).join('blah\n')
39+
})
40+
}
41+
42+
testWidgetsAffectDocumentHeight('shortFile_WidgetAtTop', 50, 0);
43+
testWidgetsAffectDocumentHeight('shortFile_WidgetAtBottom', 50, 49);
44+
45+
testWidgetsAffectDocumentHeight('longFile_WidgetAtTop', 1000, 1);
46+
testWidgetsAffectDocumentHeight('longFile_WidgetAtMiddle', 1000, 500);
47+
testWidgetsAffectDocumentHeight('longFile_WidgetAtBottom', 1000, 1000);
48+
49+
testWidgetsAffectDocumentHeight('longFile_WidgetAtTop_viewportBottom', 1000, 0, 999);
50+
testWidgetsAffectDocumentHeight('longFile_WidgetAtMiddle_viewportBottom', 1000, 499, 999);
51+
testWidgetsAffectDocumentHeight('longFile_WidgetAtBottom_viewportBottom', 1000, 999, 999);
52+
53+
})();

0 commit comments

Comments
 (0)