mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
#900 Add tests for events on Terminal
This commit is contained in:
+123
-19
@@ -26,7 +26,7 @@ describe('term.js addons', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
term = new TestTerminal(termOptions);
|
||||
term.refresh = () => {};
|
||||
term.refresh = () => { };
|
||||
(<any>term).renderer = new MockRenderer();
|
||||
term.viewport = new MockViewport();
|
||||
(<any>term)._compositionHelper = new MockCompositionHelper();
|
||||
@@ -37,8 +37,8 @@ describe('term.js addons', () => {
|
||||
};
|
||||
(<any>term).element = {
|
||||
classList: {
|
||||
toggle: () => {},
|
||||
remove: () => {}
|
||||
toggle: () => { },
|
||||
remove: () => { }
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -68,24 +68,128 @@ describe('term.js addons', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('on', () => {
|
||||
beforeEach(() => {
|
||||
term.on('key', () => { });
|
||||
term.on('keypress', () => { });
|
||||
term.on('keydown', () => { });
|
||||
});
|
||||
|
||||
describe('data', () => {
|
||||
it('should emit a data event', (done) => {
|
||||
term.on('data', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
term.handler('fake');
|
||||
});
|
||||
});
|
||||
|
||||
describe(`keypress (including 'key' event)`, () => {
|
||||
it('should receive a string and event object', () => {
|
||||
const evKeyPress = <KeyboardEvent>{
|
||||
preventDefault: () => { },
|
||||
stopPropagation: () => { },
|
||||
type: 'keypress',
|
||||
keyCode: 77
|
||||
};
|
||||
|
||||
term.on('keypress', (key, event) => {
|
||||
assert.equal(typeof key, 'string');
|
||||
expect(event).to.be.an.instanceof(Object);
|
||||
});
|
||||
|
||||
term.on('key', (key, event) => {
|
||||
assert.equal(typeof key, 'string');
|
||||
expect(event).to.be.an.instanceof(Object);
|
||||
});
|
||||
|
||||
term.keyPress(evKeyPress);
|
||||
});
|
||||
});
|
||||
|
||||
describe(`keydown (including 'key' event)`, () => {
|
||||
it('should receive a string and event object', () => {
|
||||
const evKeyDown = <KeyboardEvent>{
|
||||
preventDefault: () => { },
|
||||
stopPropagation: () => { },
|
||||
type: 'keydown',
|
||||
keyCode: 77
|
||||
};
|
||||
|
||||
term.on('keydown', (key, event) => {
|
||||
assert.equal(typeof key, 'string');
|
||||
expect(event).to.be.an.instanceof(Object);
|
||||
});
|
||||
|
||||
term.on('key', (key, event) => {
|
||||
assert.equal(typeof key, 'string');
|
||||
expect(event).to.be.an.instanceof(Object);
|
||||
});
|
||||
|
||||
term.keyDown(evKeyDown);
|
||||
});
|
||||
});
|
||||
|
||||
describe('refresh', () => {
|
||||
it('should receive an object: {start: number, end: number}', () => {
|
||||
term.on('refresh', (data) => {
|
||||
expect(data).to.have.keys(['start', 'end']);
|
||||
assert.equal(typeof data.start, 'number');
|
||||
assert.equal(typeof data.end, 'number');
|
||||
});
|
||||
term.refresh(0, term.rows - 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('resize', () => {
|
||||
it('should receive an object: {cols: number, rows: number}', () => {
|
||||
term.on('resize', (data) => {
|
||||
expect(data).to.have.keys(['cols', 'rows']);
|
||||
assert.equal(typeof data.cols, 'number');
|
||||
assert.equal(typeof data.rows, 'number');
|
||||
});
|
||||
term.resize(1, 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('scroll', () => {
|
||||
it('should receive a number', () => {
|
||||
term.on('scroll', (ydisp) => {
|
||||
assert.equal(typeof ydisp, 'number');
|
||||
});
|
||||
term.scroll();
|
||||
});
|
||||
});
|
||||
|
||||
describe('title', () => {
|
||||
it('should receive a string', () => {
|
||||
term.on('title', (title) => {
|
||||
assert.equal(typeof title, 'string');
|
||||
});
|
||||
term.handleTitle('title');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('attachCustomKeyEventHandler', () => {
|
||||
const evKeyDown = <KeyboardEvent>{
|
||||
preventDefault: () => {},
|
||||
stopPropagation: () => {},
|
||||
preventDefault: () => { },
|
||||
stopPropagation: () => { },
|
||||
type: 'keydown',
|
||||
keyCode: 77
|
||||
};
|
||||
const evKeyPress = <KeyboardEvent>{
|
||||
preventDefault: () => {},
|
||||
stopPropagation: () => {},
|
||||
preventDefault: () => { },
|
||||
stopPropagation: () => { },
|
||||
type: 'keypress',
|
||||
keyCode: 77
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
term.handler = () => {};
|
||||
term.showCursor = () => {};
|
||||
term.clearSelection = () => {};
|
||||
term.handler = () => { };
|
||||
term.showCursor = () => { };
|
||||
term.clearSelection = () => { };
|
||||
});
|
||||
|
||||
it('should process the keydown/keypress event based on what the handler returns', () => {
|
||||
@@ -305,8 +409,8 @@ describe('term.js addons', () => {
|
||||
type: 'keydown',
|
||||
key: 'a',
|
||||
keyCode: 65,
|
||||
preventDefault: () => {},
|
||||
stopPropagation: () => {}
|
||||
preventDefault: () => { },
|
||||
stopPropagation: () => { }
|
||||
};
|
||||
|
||||
term.buffer.ydisp = 0;
|
||||
@@ -473,9 +577,9 @@ describe('term.js addons', () => {
|
||||
let evKeyPress: any;
|
||||
|
||||
beforeEach(() => {
|
||||
term.handler = () => {};
|
||||
term.showCursor = () => {};
|
||||
term.clearSelection = () => {};
|
||||
term.handler = () => { };
|
||||
term.showCursor = () => { };
|
||||
term.clearSelection = () => { };
|
||||
// term.compositionHelper = {
|
||||
// isComposing: false,
|
||||
// keydown: {
|
||||
@@ -485,15 +589,15 @@ describe('term.js addons', () => {
|
||||
// }
|
||||
// };
|
||||
evKeyDown = {
|
||||
preventDefault: () => {},
|
||||
stopPropagation: () => {},
|
||||
preventDefault: () => { },
|
||||
stopPropagation: () => { },
|
||||
type: 'keydown',
|
||||
altKey: null,
|
||||
keyCode: null
|
||||
};
|
||||
evKeyPress = {
|
||||
preventDefault: () => {},
|
||||
stopPropagation: () => {},
|
||||
preventDefault: () => { },
|
||||
stopPropagation: () => { },
|
||||
type: 'keypress',
|
||||
altKey: null,
|
||||
charCode: null,
|
||||
|
||||
Reference in New Issue
Block a user