mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	compose: Fix bug in undo operation
This fixes compose.test_video_link_compose_clicked to just use a stub for compose_ui.insert_syntax_and_focus. It also adds direct tests for compose_ui.insert_syntax_and_focus. Fixes #6362
This commit is contained in:
		@@ -1136,20 +1136,20 @@ function test_with_mock_socket(test_params) {
 | 
			
		||||
    }());
 | 
			
		||||
 | 
			
		||||
    (function test_video_link_compose_clicked() {
 | 
			
		||||
        // Hackishly pretend caret is the same as val, since we don't
 | 
			
		||||
        // have a cursor anyway.
 | 
			
		||||
        $('#compose-textarea').caret = function (x) {
 | 
			
		||||
            $('#compose-textarea').val(x);
 | 
			
		||||
        var syntax_to_insert;
 | 
			
		||||
 | 
			
		||||
        compose_ui.insert_syntax_and_focus = function (syntax) {
 | 
			
		||||
            syntax_to_insert = syntax;
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        var handler = $("#compose").get_on_handler("click", "#video_link");
 | 
			
		||||
        assert.equal($('#compose-textarea').val(), '');
 | 
			
		||||
        $('#compose-textarea').val('');
 | 
			
		||||
 | 
			
		||||
        handler(event);
 | 
			
		||||
 | 
			
		||||
        // video link ids consist of 15 random digits
 | 
			
		||||
        var video_link_regex = /\[Click to join video call\]\(https:\/\/meet.jit.si\/\d{15}\)/;
 | 
			
		||||
        assert(video_link_regex.test($('#compose-textarea').val()));
 | 
			
		||||
        assert(video_link_regex.test(syntax_to_insert));
 | 
			
		||||
    }());
 | 
			
		||||
 | 
			
		||||
    (function test_markdown_preview_compose_clicked() {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,14 @@
 | 
			
		||||
zrequire('compose_ui');
 | 
			
		||||
 | 
			
		||||
set_global('document', {
 | 
			
		||||
    execCommand: function () { return false; },
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
set_global('$', global.make_zjquery());
 | 
			
		||||
set_global('blueslip', {});
 | 
			
		||||
 | 
			
		||||
var noop = function () {};
 | 
			
		||||
 | 
			
		||||
function make_textbox(s) {
 | 
			
		||||
    // Simulate a jQuery textbox for testing purposes.
 | 
			
		||||
    var widget = {};
 | 
			
		||||
@@ -45,6 +54,24 @@ function make_textbox(s) {
 | 
			
		||||
    return widget;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
(function test_insert_syntax_and_focus() {
 | 
			
		||||
    blueslip.error = noop;
 | 
			
		||||
    blueslip.log = noop;
 | 
			
		||||
    $('#compose-textarea').val("xyz ");
 | 
			
		||||
    $('#compose-textarea').caret = function (syntax) {
 | 
			
		||||
        if (syntax !== undefined) {
 | 
			
		||||
            $('#compose-textarea').val($('#compose-textarea').val() + syntax);
 | 
			
		||||
        } else {
 | 
			
		||||
            return 4;
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
    compose_ui.insert_syntax_and_focus(':octopus:');
 | 
			
		||||
    assert.equal($('#compose-textarea').caret(), 4);
 | 
			
		||||
    assert.equal($('#compose-textarea').val(), 'xyz :octopus:');
 | 
			
		||||
    assert($("#compose-textarea").is_focused());
 | 
			
		||||
 | 
			
		||||
}());
 | 
			
		||||
 | 
			
		||||
(function test_smart_insert() {
 | 
			
		||||
    var textbox = make_textbox('abc ');
 | 
			
		||||
    textbox.caret(4);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user