]> git.proxmox.com Git - mirror_xterm.js.git/blame - src/Viewport.test.ts
Merge pull request #542 from Tyriar/539_fix_initial_viewport_sync
[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;
7 let charMeasure;
8 let viewport;
9 let scrollAreaElement;
7048f6ed 10
5bddb937 11 const CHARACTER_HEIGHT = 10;
7048f6ed 12
5bddb937 13 beforeEach(() => {
7048f6ed
DI
14 terminal = {
15 lines: [],
16 rows: 0,
17 ydisp: 0,
5bddb937 18 on: () => {},
7048f6ed
DI
19 rowContainer: {
20 style: {
21 lineHeight: 0
22 }
23 }
24 };
25 viewportElement = {
5bddb937 26 addEventListener: () => {},
7048f6ed
DI
27 style: {
28 height: 0,
29 lineHeight: 0
30 }
31 };
32 scrollAreaElement = {
33 style: {
34 height: 0
35 }
36 };
07a8b8f4
DI
37 charMeasure = {
38 height: CHARACTER_HEIGHT
7048f6ed 39 };
07a8b8f4 40 viewport = new Viewport(terminal, viewportElement, scrollAreaElement, charMeasure);
7048f6ed
DI
41 });
42
5bddb937 43 describe('refresh', () => {
92f27d31
DI
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);
7048f6ed 55 });
5bddb937 56 it('should set the height of the viewport when the line-height changed', () => {
dcc991bd 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');
07a8b8f4 62 charMeasure.height = 20;
dcc991bd 63 viewport.refresh();
64 assert.equal(viewportElement.style.height, 20 + 'px');
65 });
7048f6ed 66 });
2c9c95f5 67
5bddb937 68 describe('syncScrollArea', () => {
92f27d31
DI
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);
2c9c95f5
DI
84 });
85 });
7048f6ed 86});