1 import { assert } from 'chai';
2 import { Viewport } from './Viewport';
4 describe('Viewport', () => {
7 var charMeasureElement;
11 const CHARACTER_HEIGHT = 10;
26 addEventListener: () => {},
37 charMeasureElement = {
38 getBoundingClientRect: () => {
39 return { width: null, height: CHARACTER_HEIGHT };
42 viewport = new Viewport(terminal, viewportElement, scrollAreaElement, charMeasureElement);
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 };
53 assert.equal(viewportElement.style.lineHeight, '1px');
54 assert.equal(terminal.rowContainer.style.lineHeight, '1px');
56 it('should set the height of the viewport when the line-height changed', () => {
57 terminal.lines.push('');
58 terminal.lines.push('');
61 assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
62 charMeasureElement.getBoundingClientRect = () => {
63 return { width: null, height: 20 };
66 assert.equal(viewportElement.style.height, 20 + 'px');
70 describe('syncScrollArea', () => {
71 it('should sync the scroll area', () => {
72 terminal.lines.push('');
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');