]>
git.proxmox.com Git - mirror_xterm.js.git/blob - test/viewport-test.js
7e99c4301fb67eb7d9d2955e92ad5d4c6547bb52
1 var assert
= require('chai').assert
;
2 var Terminal
= require('../src/xterm');
4 describe('Viewport', function () {
7 var charMeasureElement
;
10 var CHARACTER_HEIGHT
= 10;
12 beforeEach(function () {
25 addEventListener: function () {},
36 charMeasureElement
= {
37 getBoundingClientRect: function () {
38 return { width
: null, height
: CHARACTER_HEIGHT
};
41 viewport
= new Terminal
.Viewport(terminal
, viewportElement
, scrollAreaElement
, charMeasureElement
);
44 describe('Public API', function () {
45 it('should define Viewport.prototype.onWheel', function () {
46 assert
.isDefined(Terminal
.Viewport
.prototype.onWheel
);
48 it('should define Viewport.prototype.setApplicationMode', function () {
49 assert
.isDefined(Terminal
.Viewport
.prototype.setApplicationMode
);
53 describe('setApplicationMode', function () {
54 it('should restrict the scroll area to the viewport', function () {
55 terminal
.lines
.push('');
56 terminal
.lines
.push('');
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');
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 };
75 assert
.equal(viewportElement
.style
.lineHeight
, '1px');
76 assert
.equal(terminal
.rowContainer
.style
.lineHeight
, '1px');
78 it('should set the height of the viewport when the line-height changed', function () {
79 terminal
.lines
.push('');
80 terminal
.lines
.push('');
83 assert
.equal(viewportElement
.style
.height
, 1 * CHARACTER_HEIGHT
+ 'px');
84 charMeasureElement
.getBoundingClientRect = function () {
85 return { width
: null, height
: 20 };
88 assert
.equal(viewportElement
.style
.height
, 20 + 'px');
92 describe('syncScrollArea', function () {
93 it('should sync the scroll area', function () {
94 terminal
.lines
.push('');
96 assert
.equal(scrollAreaElement
.style
.height
, 0 * CHARACTER_HEIGHT
+ 'px');
97 viewport
.syncScrollArea();
98 assert
.equal(viewportElement
.style
.height
, 1 * CHARACTER_HEIGHT
+ 'px');
99 assert
.equal(scrollAreaElement
.style
.height
, 1 * CHARACTER_HEIGHT
+ 'px');
100 terminal
.lines
.push('');
101 viewport
.syncScrollArea();
102 assert
.equal(viewportElement
.style
.height
, 1 * CHARACTER_HEIGHT
+ 'px');
103 assert
.equal(scrollAreaElement
.style
.height
, 2 * CHARACTER_HEIGHT
+ 'px');