mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	node tests: Further simplify Mac shortcut tests.
I now just use inline the code to create stubs
for the line items in the markdown_content
container, and I don't add methods to the
zjquery stubs.
And then I use the new "children" feature in
zjquery's `$.create(sel, opts)` to set up
$(".markdown_content"), which means I don't
have to stub `each` any more.
			
			
This commit is contained in:
		
				
					committed by
					
						
						Steve Howell
					
				
			
			
				
	
			
			
			
						parent
						
							131375a26e
						
					
				
				
					commit
					55150c8195
				
			@@ -25,15 +25,6 @@ $(input).val = (arg) => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
zrequire("common");
 | 
					zrequire("common");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_key_stub_html(key_text, expected_key, obj_name) {
 | 
					 | 
				
			||||||
    const key_stub = $.create(obj_name);
 | 
					 | 
				
			||||||
    key_stub.text(key_text);
 | 
					 | 
				
			||||||
    key_stub.expected_key = function () {
 | 
					 | 
				
			||||||
        return expected_key;
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
    return key_stub;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
run_test("basics", () => {
 | 
					run_test("basics", () => {
 | 
				
			||||||
    common.autofocus("#home");
 | 
					    common.autofocus("#home");
 | 
				
			||||||
    assert($("#home").is_focused());
 | 
					    assert($("#home").is_focused());
 | 
				
			||||||
@@ -99,33 +90,30 @@ run_test("adjust_mac_shortcuts mac", () => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    $.clear_all_elements();
 | 
					    $.clear_all_elements();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const keys_elem_list = [];
 | 
					    const test_items = [];
 | 
				
			||||||
    let key_no = 1;
 | 
					    let key_no = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (const [key, value] of keys_to_test_mac) {
 | 
					    for (const [old_key, mac_key] of keys_to_test_mac) {
 | 
				
			||||||
        keys_elem_list.push(get_key_stub_html(key, value, "hotkey_" + key_no));
 | 
					        const test_item = {};
 | 
				
			||||||
 | 
					        const stub = $.create("hotkey_" + key_no);
 | 
				
			||||||
 | 
					        stub.text(old_key);
 | 
				
			||||||
 | 
					        assert.equal(stub.hasClass("mac-cmd-key"), false);
 | 
				
			||||||
 | 
					        test_item.stub = stub;
 | 
				
			||||||
 | 
					        test_item.mac_key = mac_key;
 | 
				
			||||||
 | 
					        test_item.is_cmd_key = old_key.includes("Ctrl");
 | 
				
			||||||
 | 
					        test_items.push(test_item);
 | 
				
			||||||
        key_no += 1;
 | 
					        key_no += 1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $(".markdown_content").each = (f) => {
 | 
					    const children = test_items.map((test_item) => ({to_$: () => test_item.stub}));
 | 
				
			||||||
        for (const key_elem of keys_elem_list) {
 | 
					 | 
				
			||||||
            f.call(key_elem);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
    common.adjust_mac_shortcuts(".markdown_content");
 | 
					 | 
				
			||||||
    for (const key_elem of keys_elem_list) {
 | 
					 | 
				
			||||||
        assert.equal(key_elem.text(), key_elem.expected_key());
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const markdown_hotkey_1 = get_key_stub_html(
 | 
					    $.create(".markdown_content", {children});
 | 
				
			||||||
        "Ctrl + Backspace",
 | 
					
 | 
				
			||||||
        "⌘ + Delete",
 | 
					    const require_cmd = true;
 | 
				
			||||||
        "markdown_hotkey_1",
 | 
					    common.adjust_mac_shortcuts(".markdown_content", require_cmd);
 | 
				
			||||||
    );
 | 
					
 | 
				
			||||||
    $(".markdown_content").each = (f) => {
 | 
					    for (const test_item of test_items) {
 | 
				
			||||||
        f.call(markdown_hotkey_1);
 | 
					        assert.equal(test_item.stub.hasClass("mac-cmd-key"), test_item.is_cmd_key);
 | 
				
			||||||
    };
 | 
					        assert.equal(test_item.stub.text(), test_item.mac_key);
 | 
				
			||||||
    common.adjust_mac_shortcuts(".markdown_content", true);
 | 
					    }
 | 
				
			||||||
    assert.equal(markdown_hotkey_1.text(), markdown_hotkey_1.expected_key());
 | 
					 | 
				
			||||||
    assert.equal(markdown_hotkey_1.hasClass("mac-cmd-key"), true);
 | 
					 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user