]> git.proxmox.com Git - mirror_xterm.js.git/blob - test/viewport-test.js
Fix tests
[mirror_xterm.js.git] / test / viewport-test.js
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 var scrollAreaElement;
10
11 var CHARACTER_HEIGHT = 10;
12
13 beforeEach(function () {
14 terminal = {
15 lines: [],
16 rows: 0,
17 ydisp: 0,
18 on: function () {},
19 rowContainer: {
20 style: {
21 lineHeight: 0
22 }
23 }
24 };
25 viewportElement = {
26 addEventListener: function () {},
27 style: {
28 height: 0,
29 lineHeight: 0
30 }
31 };
32 scrollAreaElement = {
33 style: {
34 height: 0
35 }
36 };
37 charMeasureElement = {
38 getBoundingClientRect: function () {
39 return { width: null, height: CHARACTER_HEIGHT };
40 }
41 };
42 viewport = new Terminal.Viewport(terminal, viewportElement, scrollAreaElement, charMeasureElement);
43 });
44
45 describe('Public API', function () {
46 it('should define Viewport.prototype.onWheel', function () {
47 assert.isDefined(Terminal.Viewport.prototype.onWheel);
48 });
49 });
50
51 describe('refresh', function () {
52 it('should set the line-height of the terminal', function () {
53 assert.equal(viewportElement.style.lineHeight, CHARACTER_HEIGHT + 'px');
54 assert.equal(terminal.rowContainer.style.lineHeight, CHARACTER_HEIGHT + 'px');
55 charMeasureElement.getBoundingClientRect = function () {
56 return { width: null, height: 1 };
57 };
58 viewport.refresh();
59 assert.equal(viewportElement.style.lineHeight, '1px');
60 assert.equal(terminal.rowContainer.style.lineHeight, '1px');
61 });
62 it('should set the height of the viewport when the line-height changed', function () {
63 terminal.lines.push('');
64 terminal.lines.push('');
65 terminal.rows = 1;
66 viewport.refresh();
67 assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
68 charMeasureElement.getBoundingClientRect = function () {
69 return { width: null, height: 20 };
70 };
71 viewport.refresh();
72 assert.equal(viewportElement.style.height, 20 + 'px');
73 });
74 });
75
76 describe('syncScrollArea', function () {
77 it('should sync the scroll area', function () {
78 terminal.lines.push('');
79 terminal.rows = 1;
80 assert.equal(scrollAreaElement.style.height, 0 * CHARACTER_HEIGHT + 'px');
81 viewport.syncScrollArea();
82 assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
83 assert.equal(scrollAreaElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
84 terminal.lines.push('');
85 viewport.syncScrollArea();
86 assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
87 assert.equal(scrollAreaElement.style.height, 2 * CHARACTER_HEIGHT + 'px');
88 });
89 });
90 });