add tests.

This commit is contained in:
Christopher Jeffrey 2014-01-12 06:19:54 -06:00
parent 0228b28cc4
commit c0b3115fb3
3 changed files with 204 additions and 0 deletions

View File

@ -2959,6 +2959,7 @@ Element.prototype._getCoords = function(get, noscroll) {
// Old way of doing things, this would not render right if a shrunken element
// with lots of boxes in it was within a scrollable element.
// See: $ node test/widget-shrink-fail.js
// var thisparent = this.parent;
var thisparent = el;
@ -3746,6 +3747,7 @@ ScrollableBox.prototype._scrollBottom = function() {
// larger than the scrollable element's context regardless of how much
// content is in the shrunken box, unless we do this (call getCoords
// without the scrollable calculation):
// See: $ node test/widget-shrink-fail-2.js
if (!el.detached) {
var lpos = el._getCoords(false, true);
if (lpos) {

View File

@ -0,0 +1,42 @@
var blessed = require('blessed');
var screen = blessed.screen({
autoPadding: true
});
var tab = blessed.box({
parent: screen,
top: 2,
left: 0,
right: 0,
bottom: 0,
scrollable: true,
keys: true,
vi: true,
alwaysScroll: true,
scrollbar: {
ch: ' '
},
style: {
scrollbar: {
inverse: true
}
}
});
tab._.data = blessed.text({
parent: tab,
top: 0,
left: 3,
height: 'shrink',
width: 'shrink',
content: '',
tags: true
});
tab._.data.setContent(require('util').inspect(process, null, 6));
screen.key('q', function() {
process.exit(0);
});
screen.render();

160
test/widget-shrink-fail.js Normal file
View File

@ -0,0 +1,160 @@
var blessed = require('blessed');
var screen = blessed.screen({
autoPadding: true
});
var tab = blessed.box({
parent: screen,
top: 2,
left: 0,
right: 0,
bottom: 0,
scrollable: true,
keys: true,
vi: true,
alwaysScroll: true,
scrollbar: {
ch: ' '
},
style: {
scrollbar: {
inverse: true
}
}
});
var form = blessed.box({
parent: tab,
top: 0,
left: 1,
right: 1,
//height: 9,
keys: true,
mouse: true,
// XXX Problem:
height: 'shrink',
label: ' {blue-fg}Form{/blue-fg} ',
border: 'line',
tags: true
});
form._.ftext = blessed.text({
parent: form,
top: 0,
left: 0,
height: 1,
content: 'Foo',
tags: true
});
form._.foo = blessed.textbox({
parent: form,
name: 'foo',
inputOnFocus: true,
top: 0,
left: 9,
right: 1,
height: 1,
style: {
bg: 'black',
focus: {
bg: 'blue'
},
hover: {
bg: 'blue'
}
}
});
form._.btext = blessed.text({
parent: form,
top: 2,
left: 0,
height: 1,
content: 'Bar',
tags: true
});
form._.bar = blessed.textbox({
parent: form,
name: 'bar',
inputOnFocus: true,
top: 2,
left: 9,
right: 1,
height: 1,
style: {
bg: 'black',
focus: {
bg: 'blue'
},
hover: {
bg: 'blue'
}
}
});
form._.ztext = blessed.text({
parent: form,
top: 4,
left: 0,
height: 1,
content: 'Baz',
tags: true
});
form._.baz = blessed.textbox({
parent: form,
name: 'baz',
inputOnFocus: true,
top: 4,
left: 9,
right: 1,
height: 1,
style: {
bg: 'black',
focus: {
bg: 'blue'
},
hover: {
bg: 'blue'
}
}
});
form._.submit = blessed.button({
parent: form,
name: 'submit',
top: 6,
right: 1,
height: 1,
//width: 'shrink',
width: 10,
content: 'send',
tags: true,
style: {
bg: 'black',
focus: {
bg: 'blue'
},
hover: {
bg: 'blue'
}
}
});
form._.submit.on('press', function() {
tabs.send._.form.submit();
});
form.on('submit', function(data) {
screen.leave();
console.log(data);
process.exit(0);
});
screen.key('q', function() {
process.exit(0);
});
screen.render();