]>
git.proxmox.com Git - mirror_xterm.js.git/blob - test/viewport-test.js
1 var assert
= require('chai').assert
;
2 var Terminal
= require('../src/xterm');
4 describe('Viewport', function () {
7 var charMeasureElement
;
11 var CHARACTER_HEIGHT
= 10;
13 beforeEach(function () {
26 addEventListener: function () {},
37 charMeasureElement
= {
38 getBoundingClientRect: function () {
39 return { width
: null, height
: CHARACTER_HEIGHT
};
42 viewport
= new Terminal
.Viewport(terminal
, viewportElement
, scrollAreaElement
, charMeasureElement
);
45 describe('Public API', function () {
46 it('should define Viewport.prototype.onWheel', function () {
47 assert
.isDefined(Terminal
.Viewport
.prototype.onWheel
);
49 it('should define Viewport.prototype.setApplicationMode', function () {
50 assert
.isDefined(Terminal
.Viewport
.prototype.setApplicationMode
);
54 describe('setApplicationMode', function () {
55 it('should restrict the scroll area to the viewport', function () {
56 terminal
.lines
.push('');
57 terminal
.lines
.push('');
59 viewport
.syncScrollArea();
60 assert
.equal(scrollAreaElement
.style
.height
, 2 * CHARACTER_HEIGHT
+ 'px');
61 viewport
.setApplicationMode(true);
62 assert
.equal(scrollAreaElement
.style
.height
, CHARACTER_HEIGHT
+ 'px');
63 viewport
.setApplicationMode(false);
64 assert
.equal(scrollAreaElement
.style
.height
, 2 * CHARACTER_HEIGHT
+ 'px');
68 describe('refresh', function () {
69 it('should set the line-height of the terminal', function () {
70 assert
.equal(viewportElement
.style
.lineHeight
, CHARACTER_HEIGHT
+ 'px');
71 assert
.equal(terminal
.rowContainer
.style
.lineHeight
, CHARACTER_HEIGHT
+ 'px');
72 charMeasureElement
.getBoundingClientRect = function () {
73 return { width
: null, height
: 1 };
76 assert
.equal(viewportElement
.style
.lineHeight
, '1px');
77 assert
.equal(terminal
.rowContainer
.style
.lineHeight
, '1px');
79 it('should set the height of the viewport when the line-height changed', function () {
80 terminal
.lines
.push('');
81 terminal
.lines
.push('');
84 assert
.equal(viewportElement
.style
.height
, 1 * CHARACTER_HEIGHT
+ 'px');
85 charMeasureElement
.getBoundingClientRect = function () {
86 return { width
: null, height
: 20 };
89 assert
.equal(viewportElement
.style
.height
, 20 + 'px');
93 describe('syncScrollArea', function () {
94 it('should sync the scroll area', function () {
95 terminal
.lines
.push('');
97 assert
.equal(scrollAreaElement
.style
.height
, 0 * CHARACTER_HEIGHT
+ 'px');
98 viewport
.syncScrollArea();
99 assert
.equal(viewportElement
.style
.height
, 1 * CHARACTER_HEIGHT
+ 'px');
100 assert
.equal(scrollAreaElement
.style
.height
, 1 * CHARACTER_HEIGHT
+ 'px');
101 terminal
.lines
.push('');
102 viewport
.syncScrollArea();
103 assert
.equal(viewportElement
.style
.height
, 1 * CHARACTER_HEIGHT
+ 'px');
104 assert
.equal(scrollAreaElement
.style
.height
, 2 * CHARACTER_HEIGHT
+ 'px');