]> git.proxmox.com Git - mirror_xterm.js.git/blob - test/viewport-test.js
Make `src/xterm.js` ES2015 and export EventEmitter into its own file
[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 it('should define Viewport.prototype.setApplicationMode', function () {
50 assert.isDefined(Terminal.Viewport.prototype.setApplicationMode);
51 });
52 });
53
54 describe('setApplicationMode', function () {
55 it('should restrict the scroll area to the viewport', function () {
56 terminal.lines.push('');
57 terminal.lines.push('');
58 terminal.rows = 1;
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');
65 });
66 });
67
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 };
74 };
75 viewport.refresh();
76 assert.equal(viewportElement.style.lineHeight, '1px');
77 assert.equal(terminal.rowContainer.style.lineHeight, '1px');
78 });
79 it('should set the height of the viewport when the line-height changed', function () {
80 terminal.lines.push('');
81 terminal.lines.push('');
82 terminal.rows = 1;
83 viewport.refresh();
84 assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
85 charMeasureElement.getBoundingClientRect = function () {
86 return { width: null, height: 20 };
87 };
88 viewport.refresh();
89 assert.equal(viewportElement.style.height, 20 + 'px');
90 });
91 });
92
93 describe('syncScrollArea', function () {
94 it('should sync the scroll area', function () {
95 terminal.lines.push('');
96 terminal.rows = 1;
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');
105 });
106 });
107 });