@@ -44,6 +44,12 @@ export interface ITerminal {
|
||||
emit(event: string, data: any);
|
||||
}
|
||||
|
||||
export interface ICharMeasure {
|
||||
width: number;
|
||||
height: number;
|
||||
measure(): void;
|
||||
}
|
||||
|
||||
interface ICircularList<T> {
|
||||
length: number;
|
||||
maxLength: number;
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* @license MIT
|
||||
*/
|
||||
import { ICharMeasure, ITerminal } from '../Interfaces';
|
||||
|
||||
declare var assert: Chai.Assert;
|
||||
declare var Terminal: ITerminal;
|
||||
|
||||
// Do not describe tests unless in PhantomJS environment
|
||||
if (typeof Terminal !== 'undefined') {
|
||||
|
||||
const CharMeasure = (<any>Terminal).CharMeasure;
|
||||
|
||||
describe('CharMeasure', () => {
|
||||
const parentElement = document.createElement('div');
|
||||
let charMeasure: ICharMeasure;
|
||||
|
||||
beforeEach(() => {
|
||||
charMeasure = new CharMeasure(parentElement);
|
||||
document.querySelector('#xterm').appendChild(parentElement);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
if (parentElement && parentElement.parentElement) {
|
||||
parentElement.parentElement.removeChild(parentElement);
|
||||
}
|
||||
});
|
||||
|
||||
describe('measure', () => {
|
||||
it('should be performed async on first call', done => {
|
||||
assert.equal(charMeasure.width, null);
|
||||
charMeasure.measure();
|
||||
assert.equal(charMeasure.width, null);
|
||||
setTimeout(() => {
|
||||
assert.isTrue(charMeasure.width > 0);
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should be performed sync on successive calls', done => {
|
||||
charMeasure.measure();
|
||||
setTimeout(() => {
|
||||
const firstWidth = charMeasure.width;
|
||||
parentElement.style.fontSize = '2em';
|
||||
charMeasure.measure();
|
||||
assert.equal(charMeasure.width, firstWidth * 2);
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should NOT do a measure when the parent is hidden', done => {
|
||||
charMeasure.measure();
|
||||
setTimeout(() => {
|
||||
const firstWidth = charMeasure.width;
|
||||
parentElement.style.display = 'none';
|
||||
parentElement.style.fontSize = '2em';
|
||||
charMeasure.measure();
|
||||
assert.equal(charMeasure.width, firstWidth);
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
@@ -2237,6 +2237,9 @@ function keys(obj) {
|
||||
Terminal.EventEmitter = EventEmitter;
|
||||
Terminal.inherits = inherits;
|
||||
|
||||
// Expose for Phantom.JS tests
|
||||
Terminal.CharMeasure = CharMeasure;
|
||||
|
||||
/**
|
||||
* Adds an event listener to the terminal.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user