1 import { assert } from 'chai';
2 import { Viewport } from './Viewport';
5 // Disable refreshLoop in test
6 public requestAnimationFrame() { }
9 describe('Viewport', () => {
12 var charMeasureElement;
14 var scrollAreaElement;
16 const CHARACTER_HEIGHT = 10;
19 (<any>global).window = new MockWindow();
32 addEventListener: () => {},
43 charMeasureElement = {
44 getBoundingClientRect: () => {
45 return { width: null, height: CHARACTER_HEIGHT };
48 viewport = new Viewport(terminal, viewportElement, scrollAreaElement, charMeasureElement);
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 };
59 assert.equal(viewportElement.style.lineHeight, '1px');
60 assert.equal(terminal.rowContainer.style.lineHeight, '1px');
62 it('should set the height of the viewport when the line-height changed', () => {
63 terminal.lines.push('');
64 terminal.lines.push('');
67 assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
68 charMeasureElement.getBoundingClientRect = () => {
69 return { width: null, height: 20 };
72 assert.equal(viewportElement.style.height, 20 + 'px');
76 describe('syncScrollArea', () => {
77 it('should sync the scroll area', () => {
78 terminal.lines.push('');
80 assert.equal(scrollAreaElement.style.height, 0 * CHARACTER_HEIGHT + 'px');
81 viewport.syncScrollArea();
82 assert.ok(viewport.isRefreshQueued);
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);
90 assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
91 assert.equal(scrollAreaElement.style.height, 2 * CHARACTER_HEIGHT + 'px');