]> git.proxmox.com Git - mirror_xterm.js.git/blame - src/Viewport.test.ts
Add a comment
[mirror_xterm.js.git] / src / Viewport.test.ts
CommitLineData
5bddb937
DI
1import { assert } from 'chai';
2import { Viewport } from './Viewport';
7048f6ed 3
5bddb937 4describe('Viewport', () => {
07a8b8f4
DI
5 let terminal;
6 let viewportElement;
f719a4e9 7 let selectionContainer;
07a8b8f4
DI
8 let charMeasure;
9 let viewport;
10 let scrollAreaElement;
7048f6ed 11
5bddb937 12 const CHARACTER_HEIGHT = 10;
7048f6ed 13
5bddb937 14 beforeEach(() => {
7048f6ed
DI
15 terminal = {
16 lines: [],
17 rows: 0,
18 ydisp: 0,
5bddb937 19 on: () => {},
7048f6ed
DI
20 rowContainer: {
21 style: {
22 lineHeight: 0
23 }
f719a4e9
DI
24 },
25 selectionContainer: {
26 style: {
27 height: 0
28 }
7048f6ed
DI
29 }
30 };
31 viewportElement = {
5bddb937 32 addEventListener: () => {},
7048f6ed
DI
33 style: {
34 height: 0,
35 lineHeight: 0
36 }
37 };
38 scrollAreaElement = {
39 style: {
40 height: 0
41 }
42 };
07a8b8f4
DI
43 charMeasure = {
44 height: CHARACTER_HEIGHT
7048f6ed 45 };
07a8b8f4 46 viewport = new Viewport(terminal, viewportElement, scrollAreaElement, charMeasure);
7048f6ed
DI
47 });
48
5bddb937 49 describe('refresh', () => {
92f27d31
DI
50 it('should set the line-height of the terminal', done => {
51 // Allow CharMeasure to be initialized
52 setTimeout(() => {
53 assert.equal(viewportElement.style.lineHeight, CHARACTER_HEIGHT + 'px');
54 assert.equal(terminal.rowContainer.style.lineHeight, CHARACTER_HEIGHT + 'px');
55 charMeasure.height = 1;
56 viewport.refresh();
57 assert.equal(viewportElement.style.lineHeight, '1px');
58 assert.equal(terminal.rowContainer.style.lineHeight, '1px');
59 done();
60 }, 0);
7048f6ed 61 });
5bddb937 62 it('should set the height of the viewport when the line-height changed', () => {
dcc991bd 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');
07a8b8f4 68 charMeasure.height = 20;
dcc991bd 69 viewport.refresh();
70 assert.equal(viewportElement.style.height, 20 + 'px');
71 });
7048f6ed 72 });
2c9c95f5 73
5bddb937 74 describe('syncScrollArea', () => {
92f27d31
DI
75 it('should sync the scroll area', done => {
76 // Allow CharMeasure to be initialized
77 setTimeout(() => {
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 done();
89 }, 0);
2c9c95f5
DI
90 });
91 });
7048f6ed 92});