New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
#900 Add tests for events on Terminal #1646
Changes from 1 commit
70afb13
cbbf6bd
1dc88d2
48cf73c
25e0e97
c291ab1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test needs to be asynchronous and verify both events pass, as currently it will pass if key and keydown don't fire |
||
}); | ||
}); | ||
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test needs to be asynchronous and verify the event happens (add done to end of event listener) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After additional investigation, I've found out that Next thing is that the There are two ways:
Don't know which one is preferable. 馃槂 |
||
}); | ||
}); | ||
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add done to end of event handler |
||
}); | ||
}); | ||
|
||
describe('scroll', () => { | ||
it('should receive a number', () => { | ||
term.on('scroll', (ydisp) => { | ||
assert.equal(typeof ydisp, 'number'); | ||
}); | ||
term.scroll(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add done to end of event handler |
||
}); | ||
}); | ||
|
||
describe('title', () => { | ||
it('should receive a string', () => { | ||
term.on('title', (title) => { | ||
assert.equal(typeof title, 'string'); | ||
}); | ||
term.handleTitle('title'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add done to end of event handler |
||
}); | ||
}); | ||
}); | ||
|
||
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, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test needs to be asynchronous and verify both events pass, as currently it will pass if key and keypress don't fire