]> git.proxmox.com Git - mirror_xterm.js.git/blob - src/Viewport.test.ts
Merge remote-tracking branch 'upstream/master' into 425_xon_xoff_on_280
[mirror_xterm.js.git] / src / Viewport.test.ts
1 import { assert } from 'chai';
2 import { Viewport } from './Viewport';
3
4 describe('Viewport', () => {
5 let terminal;
6 let viewportElement;
7 let charMeasure;
8 let viewport;
9 let scrollAreaElement;
10
11 const CHARACTER_HEIGHT = 10;
12
13 beforeEach(() => {
14 terminal = {
15 lines: [],
16 rows: 0,
17 ydisp: 0,
18 on: () => {},
19 rowContainer: {
20 style: {
21 lineHeight: 0
22 }
23 }
24 };
25 viewportElement = {
26 addEventListener: () => {},
27 style: {
28 height: 0,
29 lineHeight: 0
30 }
31 };
32 scrollAreaElement = {
33 style: {
34 height: 0
35 }
36 };
37 charMeasure = {
38 height: CHARACTER_HEIGHT
39 };
40 viewport = new Viewport(terminal, viewportElement, scrollAreaElement, charMeasure);
41 });
42
43 describe('refresh', () => {
44 it('should set the line-height of the terminal', () => {
45 assert.equal(viewportElement.style.lineHeight, CHARACTER_HEIGHT + 'px');
46 assert.equal(terminal.rowContainer.style.lineHeight, CHARACTER_HEIGHT + 'px');
47 charMeasure.height = 1;
48 viewport.refresh();
49 assert.equal(viewportElement.style.lineHeight, '1px');
50 assert.equal(terminal.rowContainer.style.lineHeight, '1px');
51 });
52 it('should set the height of the viewport when the line-height changed', () => {
53 terminal.lines.push('');
54 terminal.lines.push('');
55 terminal.rows = 1;
56 viewport.refresh();
57 assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
58 charMeasure.height = 20;
59 viewport.refresh();
60 assert.equal(viewportElement.style.height, 20 + 'px');
61 });
62 });
63
64 describe('syncScrollArea', () => {
65 it('should sync the scroll area', () => {
66 terminal.lines.push('');
67 terminal.rows = 1;
68 assert.equal(scrollAreaElement.style.height, 0 * CHARACTER_HEIGHT + 'px');
69 viewport.syncScrollArea();
70 assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
71 assert.equal(scrollAreaElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
72 terminal.lines.push('');
73 viewport.syncScrollArea();
74 assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
75 assert.equal(scrollAreaElement.style.height, 2 * CHARACTER_HEIGHT + 'px');
76 });
77 });
78 });