Skip to content

Commit

Permalink
fix unit tests #798
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Jun 23, 2022
1 parent 662f111 commit 2af8ab2
Showing 1 changed file with 35 additions and 39 deletions.
74 changes: 35 additions & 39 deletions __tests__/terminal.spec.js
Expand Up @@ -5724,72 +5724,68 @@ describe('Terminal plugin', function() {
});
it('should flush correctly with newline : false', function(){
var term = $('<div/>').terminal($.noop, {
greetings : "greet"
greetings : 'greet'
});
var cmd = term.find(".cmd");
var cmd = term.find('.cmd');

expect(term.find(".partial")[0]).toEqual(undefined);
expect(term.find("[data-index='0']").text()).toEqual("greet");
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 = "";
child.style.width = '';
let rect = child.getBoundingClientRect();
child.style.width = "100%";
child.style.width = '100%';
return rect;
}

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

var prompt = term.find(".cmd-prompt");
var partial = term.find(".partial");
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.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("###");
expect(cmd.css('top')).toEqual(`${-last_line_rect.height}px`);
expect(partial_children.first().text()).toEqual('###');

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

prompt = term.find(".cmd-prompt");
partial = term.find(".partial");
prompt = term.find('.cmd-prompt');
partial = term.find('.partial');
partial_children = partial.children();
last_line_rect = getLastLineRect(partial);
expect(partial.attr("data-index")).toEqual("1");
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");
expect(cmd.css('top')).toEqual(`${-last_line_rect.height}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();

prompt = term.find(".cmd-prompt");
partial = term.find(".partial");
prompt = term.find('.cmd-prompt');
partial = term.find('.partial');
partial_children = partial.children();
last_line_rect = getLastLineRect(partial);
expect(partial.attr("data-index")).toEqual("1");
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");
expect(cmd.css('top')).toEqual(`${-last_line_rect.height}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, "!!!");
enter(term, '!!!');

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);
prompt = term.find('.cmd-prompt');
expect(cmd.css('top')).toEqual('');
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> !!!"));
expect(term.find('[data-index="1"]').length).toEqual(1);
expect(term.find('[data-index="1"]').children().last().text()).toEqual(nbsp('ccc> !!!'));
});
});
describe('output_buffer', function() {
Expand Down

0 comments on commit 2af8ab2

Please sign in to comment.