mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	copy_and_paste: Add a simple extensible test suite.
This commit is mostly about adding the test suite; some of the results are things we'd like to change.
This commit is contained in:
		
							
								
								
									
										26
									
								
								frontend_tests/node_tests/copy_and_paste.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								frontend_tests/node_tests/copy_and_paste.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					global.stub_out_jquery();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var jsdom = require("jsdom");
 | 
				
			||||||
 | 
					global.document = jsdom.jsdom('<!DOCTYPE html><p>Hello world</p>');
 | 
				
			||||||
 | 
					var window = jsdom.jsdom().defaultView;
 | 
				
			||||||
 | 
					global.$ = require('jquery')(window);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					zrequire('toMarkdown', 'node_modules/to-markdown/dist/to-markdown.js');
 | 
				
			||||||
 | 
					var copy_and_paste = zrequire('copy_and_paste');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(function test_paste_handler() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var input = '<meta http-equiv="content-type" content="text/html; charset=utf-8"><span style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;"><span> </span>love the<span> </span><b>Zulip</b><b> </b></span><b style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">Organization</b><span style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">.</span>';
 | 
				
			||||||
 | 
					    assert.equal(copy_and_paste.paste_handler_converter(input),
 | 
				
			||||||
 | 
					                 'love the  **Zulip****Organization**.');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    input = '<meta http-equiv="content-type" content="text/html; charset=utf-8"><span style="color: rgb(36, 41, 46); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;">The<span> </span></span><code style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; padding: 0.2em 0.4em; margin: 0px; background-color: rgba(27, 31, 35, 0.05); border-radius: 3px; color: rgb(36, 41, 46); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">JSDOM</code><span style="color: rgb(36, 41, 46); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"><span> </span>constructor</span>';
 | 
				
			||||||
 | 
					    assert.equal(copy_and_paste.paste_handler_converter(input),
 | 
				
			||||||
 | 
					                 'The  `JSDOM`  constructor');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    input = '<meta http-equiv="content-type" content="text/html; charset=utf-8"><a href="https://zulip.readthedocs.io/en/latest/subsystems/logging.html" target="_blank" title="https://zulip.readthedocs.io/en/latest/subsystems/logging.html" style="color: rgb(0, 136, 204); text-decoration: none; cursor: pointer; font-family: "Source Sans Pro", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">https://zulip.readthedocs.io/en/latest/subsystems/logging.html</a>';
 | 
				
			||||||
 | 
					    // TODO: for cases where one is just pasting a link, we'd prefer
 | 
				
			||||||
 | 
					    // that this not use markdown syntax, since that feels unnecessary.
 | 
				
			||||||
 | 
					    assert.equal(copy_and_paste.paste_handler_converter(input),
 | 
				
			||||||
 | 
					                 '[https://zulip.readthedocs.io/en/latest/subsystems/logging.html](https://zulip.readthedocs.io/en/latest/subsystems/logging.html');
 | 
				
			||||||
 | 
					})();
 | 
				
			||||||
@@ -140,12 +140,7 @@ function copy_handler() {
 | 
				
			|||||||
    },0);
 | 
					    },0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.paste_handler = function (event) {
 | 
					exports.paste_handler_converter = function (paste_html) {
 | 
				
			||||||
    var clipboardData = event.originalEvent.clipboardData;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    var paste_html = clipboardData.getData('text/html');
 | 
					 | 
				
			||||||
    if (paste_html) {
 | 
					 | 
				
			||||||
        event.preventDefault();
 | 
					 | 
				
			||||||
    var markdown_html = toMarkdown(paste_html);
 | 
					    var markdown_html = toMarkdown(paste_html);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Now that we've done the main conversion, we want to remove
 | 
					    // Now that we've done the main conversion, we want to remove
 | 
				
			||||||
@@ -154,8 +149,16 @@ exports.paste_handler = function (event) {
 | 
				
			|||||||
    var div = document.createElement("div");
 | 
					    var div = document.createElement("div");
 | 
				
			||||||
    div.innerHTML = markdown_html;
 | 
					    div.innerHTML = markdown_html;
 | 
				
			||||||
    // Using textContent for modern browsers, innerText works for Internet Explorer
 | 
					    // Using textContent for modern browsers, innerText works for Internet Explorer
 | 
				
			||||||
        var text = div.textContent || div.innerText || "";
 | 
					    return div.textContent || div.innerText || "";
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exports.paste_handler = function (event) {
 | 
				
			||||||
 | 
					    var clipboardData = event.originalEvent.clipboardData;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var paste_html = clipboardData.getData('text/html');
 | 
				
			||||||
 | 
					    if (paste_html) {
 | 
				
			||||||
 | 
					        event.preventDefault();
 | 
				
			||||||
 | 
					        var text = exports.paste_handler_converter(paste_html);
 | 
				
			||||||
        compose_ui.insert_syntax_and_focus(text);
 | 
					        compose_ui.insert_syntax_and_focus(text);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -234,6 +234,7 @@ def build_custom_checkers(by_lang):
 | 
				
			|||||||
         'description': "Avoid using the `style=` attribute; we prefer styling in CSS files",
 | 
					         'description': "Avoid using the `style=` attribute; we prefer styling in CSS files",
 | 
				
			||||||
         'exclude': set([
 | 
					         'exclude': set([
 | 
				
			||||||
             'frontend_tests/node_tests/compose.js',
 | 
					             'frontend_tests/node_tests/compose.js',
 | 
				
			||||||
 | 
					             'frontend_tests/node_tests/copy_and_paste.js',
 | 
				
			||||||
             'frontend_tests/node_tests/templates.js',
 | 
					             'frontend_tests/node_tests/templates.js',
 | 
				
			||||||
             'static/js/compose.js',
 | 
					             'static/js/compose.js',
 | 
				
			||||||
             'static/js/dynamic_text.js',
 | 
					             'static/js/dynamic_text.js',
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user