]> git.proxmox.com Git - mirror_xterm.js.git/blob - src/Viewport.test.ts
Merge pull request #542 from Tyriar/539_fix_initial_viewport_sync
[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', done => {
45 // Allow CharMeasure to be initialized
46 setTimeout(() => {
47 assert.equal(viewportElement.style.lineHeight, CHARACTER_HEIGHT + 'px');
48 assert.equal(terminal.rowContainer.style.lineHeight, CHARACTER_HEIGHT + 'px');
49 charMeasure.height = 1;
50 viewport.refresh();
51 assert.equal(viewportElement.style.lineHeight, '1px');
52 assert.equal(terminal.rowContainer.style.lineHeight, '1px');
53 done();
54 }, 0);
55 });
56 it('should set the height of the viewport when the line-height changed', () => {
57 terminal.lines.push('');
58 terminal.lines.push('');
59 terminal.rows = 1;
60 viewport.refresh();
61 assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
62 charMeasure.height = 20;
63 viewport.refresh();
64 assert.equal(viewportElement.style.height, 20 + 'px');
65 });
66 });
67
68 describe('syncScrollArea', () => {
69 it('should sync the scroll area', done => {
70 // Allow CharMeasure to be initialized
71 setTimeout(() => {
72 terminal.lines.push('');
73 terminal.rows = 1;
74 assert.equal(scrollAreaElement.style.height, 0 * CHARACTER_HEIGHT + 'px');
75 viewport.syncScrollArea();
76 assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
77 assert.equal(scrollAreaElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
78 terminal.lines.push('');
79 viewport.syncScrollArea();
80 assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
81 assert.equal(scrollAreaElement.style.height, 2 * CHARACTER_HEIGHT + 'px');
82 done();
83 }, 0);
84 });
85 });
86 });