]> git.proxmox.com Git - mirror_xterm.js.git/blob - src/Viewport.test.ts
Merge pull request #367 from Tyriar/363_modifier_keys_no_scroll
[mirror_xterm.js.git] / src / Viewport.test.ts
1 import { assert } from 'chai';
2 import { Viewport } from './Viewport';
3
4 describe('Viewport', () => {
5 var terminal;
6 var viewportElement;
7 var charMeasureElement;
8 var viewport;
9 var 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 charMeasureElement = {
38 getBoundingClientRect: () => {
39 return { width: null, height: CHARACTER_HEIGHT };
40 }
41 };
42 viewport = new Viewport(terminal, viewportElement, scrollAreaElement, charMeasureElement);
43 });
44
45 describe('refresh', () => {
46 it('should set the line-height of the terminal', () => {
47 assert.equal(viewportElement.style.lineHeight, CHARACTER_HEIGHT + 'px');
48 assert.equal(terminal.rowContainer.style.lineHeight, CHARACTER_HEIGHT + 'px');
49 charMeasureElement.getBoundingClientRect = () => {
50 return { width: null, height: 1 };
51 };
52 viewport.refresh();
53 assert.equal(viewportElement.style.lineHeight, '1px');
54 assert.equal(terminal.rowContainer.style.lineHeight, '1px');
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 charMeasureElement.getBoundingClientRect = () => {
63 return { width: null, height: 20 };
64 };
65 viewport.refresh();
66 assert.equal(viewportElement.style.height, 20 + 'px');
67 });
68 });
69
70 describe('syncScrollArea', () => {
71 it('should sync the scroll area', () => {
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 });
83 });
84 });