]> git.proxmox.com Git - mirror_xterm.js.git/blobdiff - src/Viewport.test.ts
Merge pull request #926 from ficristo/search-fix
[mirror_xterm.js.git] / src / Viewport.test.ts
index 4fa77ec09af14def6a182b1d537097c52e85b267..6d09ea86a2b9d102b109ead0bc7746ff50f9f0d8 100644 (file)
@@ -1,5 +1,6 @@
 import { assert } from 'chai';
 import { Viewport } from './Viewport';
+import {BufferSet} from './BufferSet';
 
 describe('Viewport', () => {
   let terminal;
@@ -12,7 +13,6 @@ describe('Viewport', () => {
 
   beforeEach(() => {
     terminal = {
-      lines: [],
       rows: 0,
       ydisp: 0,
       on: () => {},
@@ -20,8 +20,16 @@ describe('Viewport', () => {
         style: {
           lineHeight: 0
         }
-      }
+      },
+      selectionContainer: {
+        style: {
+          height: 0
+        }
+      },
+      scrollback: 10
     };
+    terminal.buffers = new BufferSet(terminal);
+    terminal.buffer = terminal.buffers.active;
     viewportElement = {
       addEventListener: () => {},
       style: {
@@ -41,38 +49,46 @@ describe('Viewport', () => {
   });
 
   describe('refresh', () => {
-    it('should set the line-height of the terminal', () => {
-      assert.equal(viewportElement.style.lineHeight, CHARACTER_HEIGHT + 'px');
-      assert.equal(terminal.rowContainer.style.lineHeight, CHARACTER_HEIGHT + 'px');
-      charMeasure.height = 1;
-      viewport.refresh();
-      assert.equal(viewportElement.style.lineHeight, '1px');
-      assert.equal(terminal.rowContainer.style.lineHeight, '1px');
+    it('should set the line-height of the terminal', done => {
+      // Allow CharMeasure to be initialized
+      setTimeout(() => {
+        assert.equal(viewportElement.style.lineHeight, CHARACTER_HEIGHT + 'px');
+        assert.equal(terminal.rowContainer.style.lineHeight, CHARACTER_HEIGHT + 'px');
+        charMeasure.height = 1;
+        viewport.refresh();
+        assert.equal(viewportElement.style.lineHeight, '1px');
+        assert.equal(terminal.rowContainer.style.lineHeight, '1px');
+        done();
+      }, 0);
     });
     it('should set the height of the viewport when the line-height changed', () => {
-      terminal.lines.push('');
-      terminal.lines.push('');
+      terminal.buffer.lines.push('');
+      terminal.buffer.lines.push('');
       terminal.rows = 1;
       viewport.refresh();
       assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
-      charMeasure.height = 20;
+      charMeasure.height = 2 * CHARACTER_HEIGHT;
       viewport.refresh();
-      assert.equal(viewportElement.style.height, 20 + 'px');
+      assert.equal(viewportElement.style.height, 2 * CHARACTER_HEIGHT + 'px');
     });
   });
 
   describe('syncScrollArea', () => {
-    it('should sync the scroll area', () => {
-      terminal.lines.push('');
-      terminal.rows = 1;
-      assert.equal(scrollAreaElement.style.height, 0 * CHARACTER_HEIGHT + 'px');
-      viewport.syncScrollArea();
-      assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
-      assert.equal(scrollAreaElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
-      terminal.lines.push('');
-      viewport.syncScrollArea();
-      assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
-      assert.equal(scrollAreaElement.style.height, 2 * CHARACTER_HEIGHT + 'px');
+    it('should sync the scroll area', done => {
+      // Allow CharMeasure to be initialized
+      setTimeout(() => {
+        terminal.buffer.lines.push('');
+        terminal.rows = 1;
+        assert.equal(scrollAreaElement.style.height, 0 * CHARACTER_HEIGHT + 'px');
+        viewport.syncScrollArea();
+        assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
+        assert.equal(scrollAreaElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
+        terminal.buffer.lines.push('');
+        viewport.syncScrollArea();
+        assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
+        assert.equal(scrollAreaElement.style.height, 2 * CHARACTER_HEIGHT + 'px');
+        done();
+      }, 0);
     });
   });
 });