]> git.proxmox.com Git - mirror_xterm.js.git/blob - src/Viewport.test.ts
Fix tests
[mirror_xterm.js.git] / src / Viewport.test.ts
1 import { assert } from 'chai';
2 import { Viewport } from './Viewport';
3
4 class MockWindow {
5 // Disable refreshLoop in test
6 public requestAnimationFrame() { }
7 }
8
9 describe('Viewport', () => {
10 var terminal;
11 var viewportElement;
12 var charMeasureElement;
13 var viewport;
14 var scrollAreaElement;
15
16 const CHARACTER_HEIGHT = 10;
17
18 beforeEach(() => {
19 (<any>global).window = new MockWindow();
20 terminal = {
21 lines: [],
22 rows: 0,
23 ydisp: 0,
24 on: () => {},
25 rowContainer: {
26 style: {
27 lineHeight: 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 charMeasureElement = {
44 getBoundingClientRect: () => {
45 return { width: null, height: CHARACTER_HEIGHT };
46 }
47 };
48 viewport = new Viewport(terminal, viewportElement, scrollAreaElement, charMeasureElement);
49 });
50
51 describe('refresh', () => {
52 it('should set the line-height of the terminal', () => {
53 assert.equal(viewportElement.style.lineHeight, CHARACTER_HEIGHT + 'px');
54 assert.equal(terminal.rowContainer.style.lineHeight, CHARACTER_HEIGHT + 'px');
55 charMeasureElement.getBoundingClientRect = () => {
56 return { width: null, height: 1 };
57 };
58 viewport.refresh();
59 assert.equal(viewportElement.style.lineHeight, '1px');
60 assert.equal(terminal.rowContainer.style.lineHeight, '1px');
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 charMeasureElement.getBoundingClientRect = () => {
69 return { width: null, height: 20 };
70 };
71 viewport.refresh();
72 assert.equal(viewportElement.style.height, 20 + 'px');
73 });
74 });
75
76 describe('syncScrollArea', () => {
77 it('should sync the scroll area', () => {
78 terminal.lines.push('');
79 terminal.rows = 1;
80 assert.equal(scrollAreaElement.style.height, 0 * CHARACTER_HEIGHT + 'px');
81 viewport.syncScrollArea();
82 assert.ok(viewport.isRefreshQueued);
83 viewport.refresh();
84 assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
85 assert.equal(scrollAreaElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
86 terminal.lines.push('');
87 viewport.syncScrollArea();
88 assert.ok(viewport.isRefreshQueued);
89 viewport.refresh();
90 assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
91 assert.equal(scrollAreaElement.style.height, 2 * CHARACTER_HEIGHT + 'px');
92 });
93 });
94 });