]> git.proxmox.com Git - mirror_xterm.js.git/blame - src/Viewport.test.ts
Add comments explaining actions preventing x from wrapping
[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
DI
43 describe('refresh', () => {
44 it('should set the line-height of the terminal', () => {
7048f6ed
DI
45 assert.equal(viewportElement.style.lineHeight, CHARACTER_HEIGHT + 'px');
46 assert.equal(terminal.rowContainer.style.lineHeight, CHARACTER_HEIGHT + 'px');
07a8b8f4 47 charMeasure.height = 1;
7048f6ed
DI
48 viewport.refresh();
49 assert.equal(viewportElement.style.lineHeight, '1px');
50 assert.equal(terminal.rowContainer.style.lineHeight, '1px');
51 });
5bddb937 52 it('should set the height of the viewport when the line-height changed', () => {
dcc991bd 53 terminal.lines.push('');
54 terminal.lines.push('');
55 terminal.rows = 1;
56 viewport.refresh();
57 assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
07a8b8f4 58 charMeasure.height = 20;
dcc991bd 59 viewport.refresh();
60 assert.equal(viewportElement.style.height, 20 + 'px');
61 });
7048f6ed 62 });
2c9c95f5 63
5bddb937
DI
64 describe('syncScrollArea', () => {
65 it('should sync the scroll area', () => {
2c9c95f5
DI
66 terminal.lines.push('');
67 terminal.rows = 1;
68 assert.equal(scrollAreaElement.style.height, 0 * CHARACTER_HEIGHT + 'px');
69 viewport.syncScrollArea();
70 assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
71 assert.equal(scrollAreaElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
72 terminal.lines.push('');
73 viewport.syncScrollArea();
74 assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
75 assert.equal(scrollAreaElement.style.height, 2 * CHARACTER_HEIGHT + 'px');
76 });
77 });
7048f6ed 78});