]>
Commit | Line | Data |
---|---|---|
7048f6ed DI |
1 | var assert = require('chai').assert; |
2 | var Terminal = require('../src/xterm'); | |
3 | ||
4 | describe('Viewport', function () { | |
5 | var terminal; | |
6 | var viewportElement; | |
7 | var charMeasureElement; | |
8 | var viewport; | |
9 | ||
10 | var CHARACTER_HEIGHT = 10; | |
11 | ||
12 | beforeEach(function () { | |
13 | terminal = { | |
14 | lines: [], | |
15 | rows: 0, | |
16 | ydisp: 0, | |
17 | on: function () {}, | |
18 | rowContainer: { | |
19 | style: { | |
20 | lineHeight: 0 | |
21 | } | |
22 | } | |
23 | }; | |
24 | viewportElement = { | |
25 | addEventListener: function () {}, | |
26 | style: { | |
27 | height: 0, | |
28 | lineHeight: 0 | |
29 | } | |
30 | }; | |
31 | scrollAreaElement = { | |
32 | style: { | |
33 | height: 0 | |
34 | } | |
35 | }; | |
36 | charMeasureElement = { | |
37 | getBoundingClientRect: function () { | |
38 | return { width: null, height: CHARACTER_HEIGHT }; | |
39 | } | |
40 | }; | |
41 | viewport = new Terminal.Viewport(terminal, viewportElement, scrollAreaElement, charMeasureElement); | |
42 | }); | |
43 | ||
44 | describe('Public API', function () { | |
45 | it('should define Viewport.prototype.onWheel', function () { | |
46 | assert.isDefined(Terminal.Viewport.prototype.onWheel); | |
47 | }); | |
48 | it('should define Viewport.prototype.setApplicationMode', function () { | |
49 | assert.isDefined(Terminal.Viewport.prototype.setApplicationMode); | |
50 | }); | |
51 | }); | |
52 | ||
53 | describe('setApplicationMode', function () { | |
54 | it('should restrict the scroll area to the viewport', function () { | |
55 | terminal.lines.push(''); | |
56 | terminal.lines.push(''); | |
57 | terminal.rows = 1; | |
58 | viewport.syncScrollArea(); | |
59 | assert.equal(scrollAreaElement.style.height, 2 * CHARACTER_HEIGHT + 'px'); | |
60 | viewport.setApplicationMode(true); | |
61 | assert.equal(scrollAreaElement.style.height, CHARACTER_HEIGHT + 'px'); | |
62 | viewport.setApplicationMode(false); | |
63 | assert.equal(scrollAreaElement.style.height, 2 * CHARACTER_HEIGHT + 'px'); | |
64 | }); | |
65 | }); | |
66 | ||
67 | describe('refresh', function () { | |
68 | it('should set the line-height of the terminal', function () { | |
69 | assert.equal(viewportElement.style.lineHeight, CHARACTER_HEIGHT + 'px'); | |
70 | assert.equal(terminal.rowContainer.style.lineHeight, CHARACTER_HEIGHT + 'px'); | |
71 | charMeasureElement.getBoundingClientRect = function () { | |
72 | return { width: null, height: 1 }; | |
73 | }; | |
74 | viewport.refresh(); | |
75 | assert.equal(viewportElement.style.lineHeight, '1px'); | |
76 | assert.equal(terminal.rowContainer.style.lineHeight, '1px'); | |
77 | }); | |
78 | }); | |
79 | }); |