]> git.proxmox.com Git - mirror_xterm.js.git/blob - src/Viewport.test.ts
Merge branch 'master' into 642_link_wrapped_char_duplication
[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 selectionContainer;
8 let charMeasure;
9 let viewport;
10 let scrollAreaElement;
11
12 const CHARACTER_HEIGHT = 10;
13
14 beforeEach(() => {
15 terminal = {
16 lines: [],
17 rows: 0,
18 ydisp: 0,
19 on: () => {},
20 rowContainer: {
21 style: {
22 lineHeight: 0
23 }
24 },
25 selectionContainer: {
26 style: {
27 height: 0
28 }
29 }
30 };
31 viewportElement = {
32 addEventListener: () => {},
33 style: {
34 height: 0,
35 lineHeight: 0
36 }
37 };
38 scrollAreaElement = {
39 style: {
40 height: 0
41 }
42 };
43 charMeasure = {
44 height: CHARACTER_HEIGHT
45 };
46 viewport = new Viewport(terminal, viewportElement, scrollAreaElement, charMeasure);
47 });
48
49 describe('refresh', () => {
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);
61 });
62 it('should set the height of the viewport when the line-height changed', () => {
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');
68 charMeasure.height = 20;
69 viewport.refresh();
70 assert.equal(viewportElement.style.height, 20 + 'px');
71 });
72 });
73
74 describe('syncScrollArea', () => {
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);
90 });
91 });
92 });