Skip to content

Commit

Permalink
Move new flush test next to other flush test, lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Hood committed Feb 28, 2021
1 parent fbd014f commit 5779894
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 72 deletions.
140 changes: 70 additions & 70 deletions __tests__/terminal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2948,75 +2948,6 @@ describe('sub plugins', function() {
});
});
describe('Terminal plugin', function() {
describe('flush', function(){
it('flush', function(){
var term = $('<div/>').terminal($.noop, {
greetings : "greet"
});
var cmd = term.find(".cmd");

expect(term.find(".partial")[0]).toEqual(undefined);
expect(term.find("[data-index='0']").text()).toEqual("greet");

function getLastLineRect(partial){
let child = partial[0].lastElementChild;
child.style.width = "";
let rect = child.getBoundingClientRect();
child.style.width = "100%";
return rect;
}

term.echo("###", {newline : false});

var prompt = term.find(".cmd-prompt");
var partial = term.find(".partial");
var partial_children = partial.children();
var last_line_rect = getLastLineRect(partial);
expect(partial.attr("data-index")).toEqual("1");
expect(partial_children.length).toEqual(1);
expect(cmd.css("top")).toEqual(`${-last_line_rect.height}px`)
expect(prompt[0].style.marginLeft).toEqual(`${last_line_rect.width}px`);
expect(partial_children.first().text()).toEqual("###");

term.echo("aaa\nbbb\nccc", {newline : false});

var prompt = term.find(".cmd-prompt");
var partial = term.find(".partial");
var partial_children = partial.children();
var last_line_rect = getLastLineRect(partial);
expect(partial.attr("data-index")).toEqual("1");
expect(partial_children.length).toEqual(3);
expect(cmd.css("top")).toEqual(`${-last_line_rect.height}px`)
expect(prompt[0].style.marginLeft).toEqual(`${last_line_rect.width}px`);
expect(partial_children.eq(0).text()).toEqual("###aaa");
expect(partial_children.eq(1).text()).toEqual("bbb");
expect(partial_children.eq(2).text()).toEqual("ccc");
term.refresh();

var prompt = term.find(".cmd-prompt");
var partial = term.find(".partial");
var partial_children = partial.children();
var last_line_rect = getLastLineRect(partial);
expect(partial.attr("data-index")).toEqual("1");
expect(partial_children.length).toEqual(3);
expect(cmd.css("top")).toEqual(`${-last_line_rect.height}px`)
expect(prompt[0].style.marginLeft).toEqual(`${last_line_rect.width}px`);
expect(partial_children.eq(0).text()).toEqual("###aaa");
expect(partial_children.eq(1).text()).toEqual("bbb");
expect(partial_children.eq(2).text()).toEqual("ccc");

enter(term, "!!!");

var prompt = term.find(".cmd-prompt");
expect(cmd.css("top")).toEqual(`0px`)
expect(prompt[0].style.marginLeft).toEqual(`0px`);
expect(term.find("[data-index='1']").children().last().text()).toEqual(nbsp("ccc> !!!"));
expect(term.find(".partial")[0]).toEqual(undefined);

term.refresh();
expect(term.find("[data-index='1']").children().last().text()).toEqual(nbsp("ccc> !!!"));
});
});
describe('jQuery Terminal options', function() {
describe('prompt', function() {
it('should set prompt', function() {
Expand Down Expand Up @@ -5575,14 +5506,83 @@ describe('Terminal plugin', function() {
});
// missing methods after version
describe('flush', function() {
var term = $('<div/>').terminal($.noop, {greetings: false});
it('should echo stuff that was called with flush false', function() {
var term = $('<div/>').terminal($.noop, {greetings: false});
term.echo('foo', {flush: false});
term.echo('bar', {flush: false});
term.echo('baz', {flush: false});
term.flush();
expect(term.find('.terminal-output').text()).toEqual('foobarbaz');
});
it('should flush correctly with newline : false', function(){
var term = $('<div/>').terminal($.noop, {
greetings : "greet"
});
var cmd = term.find(".cmd");

expect(term.find(".partial")[0]).toEqual(undefined);
expect(term.find("[data-index='0']").text()).toEqual("greet");

function getLastLineRect(partial){
let child = partial[0].lastElementChild;
child.style.width = "";
let rect = child.getBoundingClientRect();
child.style.width = "100%";
return rect;
}

term.echo("###", {newline : false});

var prompt = term.find(".cmd-prompt");
var partial = term.find(".partial");
var partial_children = partial.children();
var last_line_rect = getLastLineRect(partial);
expect(partial.attr("data-index")).toEqual("1");
expect(partial_children.length).toEqual(1);
expect(cmd.css("top")).toEqual(`${-last_line_rect.height}px`)
expect(prompt[0].style.marginLeft).toEqual(`${last_line_rect.width}px`);
expect(partial_children.first().text()).toEqual("###");

term.echo("aaa\nbbb\nccc", {newline : false});

var prompt = term.find(".cmd-prompt");
var partial = term.find(".partial");
var partial_children = partial.children();
var last_line_rect = getLastLineRect(partial);
expect(partial.attr("data-index")).toEqual("1");
expect(partial_children.length).toEqual(3);
expect(cmd.css("top")).toEqual(`${-last_line_rect.height}px`)
expect(prompt[0].style.marginLeft).toEqual(`${last_line_rect.width}px`);
expect(partial_children.eq(0).text()).toEqual("###aaa");
expect(partial_children.eq(1).text()).toEqual("bbb");
expect(partial_children.eq(2).text()).toEqual("ccc");
term.refresh();

var prompt = term.find(".cmd-prompt");
var partial = term.find(".partial");
var partial_children = partial.children();
var last_line_rect = getLastLineRect(partial);
expect(partial.attr("data-index")).toEqual("1");
expect(partial_children.length).toEqual(3);
expect(cmd.css("top")).toEqual(`${-last_line_rect.height}px`)
expect(prompt[0].style.marginLeft).toEqual(`${last_line_rect.width}px`);
expect(partial_children.eq(0).text()).toEqual("###aaa");
expect(partial_children.eq(1).text()).toEqual("bbb");
expect(partial_children.eq(2).text()).toEqual("ccc");

enter(term, "!!!");

var prompt = term.find(".cmd-prompt");
expect(cmd.css("top")).toEqual(`0px`)
expect(prompt[0].style.marginLeft).toEqual(`0px`);
expect(term.find("[data-index='1']").length).toEqual(1);
expect(term.find("[data-index='1']").children().last().text()).toEqual(nbsp("ccc> !!!"));
expect(term.find(".partial")[0]).toEqual(undefined);

term.refresh();
expect(term.find("[data-index='1']").length).toEqual(1);
expect(term.find("[data-index='1']").children().last().text()).toEqual(nbsp("ccc> !!!"));
});
});
describe('last_index', function() {
var term = $('<div/>').terminal($.noop, {greetings: false});
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.terminal-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -7500,7 +7500,7 @@
}));
});
}
if(!line_settings.newline && string.endsWith('\n')){
if (!line_settings.newline && string.endsWith('\n')) {
line_settings.newline = true;
// This adjusts the value for the caller so that when it
// updates the lines list it does the right thing. This is
Expand Down Expand Up @@ -9353,7 +9353,7 @@
div = wrapper.children().last().append(line);
appending_to_partial = false;
} else {
var div = $('<div/>').html(line);
div = $('<div/>').html(line);
if (data.newline) {
div.addClass('cmd-end-line');
}
Expand Down

0 comments on commit 5779894

Please sign in to comment.