gitoria

components

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit23b9164a23b9164aMdEditor: a clipboard whose text is only the names or file:// paths of its files (a file manager copy) is about the files, as before; any other text wins (tickets#49); gate casesmre23b9164a/tests/md-paste.mjs

7.3 KB

  1. // tests/md-paste.mjs — components#20: copy / cut / paste in the MdEditor, with REAL keys (Ctrl+C / X / V as editing commands on the
  2. // browser's own clipboard) and with pasted clipboards that carry plain text only or text/html too (as when copied from a rendered page).
  3. // The page must be /md-editor (editor 2, "summary", starts empty). mdPaste(page, { check, sleep, label }) runs in that one tab.
  4. export async function mdPaste(page, { check, sleep, label = '' }) {
  5. const L = label ? `[${label}] ` : '';
  6. const send = (m, p) => page.send(m, p);
  7. const CTRL = 2;
  8. const key = async (k, code, vk, text, modifiers = 0, commands) => {
  9. await send('Input.dispatchKeyEvent', { type: text !== undefined ? 'keyDown' : 'rawKeyDown', key: k, code, windowsVirtualKeyCode: vk, text, modifiers, commands });
  10. await send('Input.dispatchKeyEvent', { type: 'keyUp', key: k, code, windowsVirtualKeyCode: vk, modifiers });
  11. await sleep(40);
  12. };
  13. const chord = (ch, command) => key(ch, 'Key' + ch.toUpperCase(), ch.toUpperCase().charCodeAt(0), undefined, CTRL, command ? [command] : undefined);
  14. const ev = (e) => page.evaluate(e);
  15. const E = `document.querySelectorAll('md-editor')[1]`;
  16. const val = () => ev(`${E}.querySelector('input.value').value`);
  17. const focusEditor = async () => {
  18. await page.click('md-editor:nth-of-type(2) article');
  19. await page.waitFor(`${E}.querySelector('article').contains(document.activeElement)`, { label: 'editor focused' });
  20. };
  21. // the editor emptied through its Markdown source (real clicks and keys), like tests/md-keys.mjs
  22. const fresh = async () => {
  23. await page.click('md-editor:nth-of-type(2) footer button'); await sleep(200);
  24. await page.click('md-editor:nth-of-type(2) textarea');
  25. await chord('a'); await key('Backspace', 'Backspace', 8); await sleep(120);
  26. await page.click('md-editor:nth-of-type(2) footer button'); await sleep(250);
  27. await focusEditor(); await sleep(60);
  28. };
  29. // a paste the way a browser delivers it: a real paste event with a DataTransfer that holds exactly these formats
  30. // (Input.insertText has no clipboard event; this is the one place a clipboard with text/html is made, for the page-copied case)
  31. const pasteData = (formats) => ev(`(() => {
  32. const a = ${E}.querySelector('article'); a.focus();
  33. const dt = new DataTransfer(); for (const [k, v] of Object.entries(${JSON.stringify(formats)})) dt.setData(k, v);
  34. a.dispatchEvent(new ClipboardEvent('paste', { clipboardData: dt, bubbles: true, cancelable: true }));
  35. })()`);
  36. const plain = 'first line\nsecond line\nthird line';
  37. await focusEditor(); await fresh();
  38. // 1. real type, select all, Ctrl+C, collapse to the end, Ctrl+V twice: the text comes back
  39. for (const ch of 'alpha beta') await key(ch, '', undefined, ch);
  40. await chord('a'); await chord('c', 'copy');
  41. await key('End', 'End', 35); await chord('v', 'paste'); await sleep(250);
  42. const v1 = await val();
  43. check(L + 'copy all then paste at the end gives the text twice', v1.replace(/\s+/g, ' ').trim() === 'alpha betaalpha beta', JSON.stringify(v1));
  44. // 2. Ctrl+X then Ctrl+V puts the cut text back
  45. await fresh();
  46. for (const ch of 'gamma delta') await key(ch, '', undefined, ch);
  47. await chord('a'); await chord('x', 'cut'); await sleep(150);
  48. const cutLeft = await val();
  49. await chord('v', 'paste'); await sleep(250);
  50. const v2 = await val();
  51. check(L + 'cut empties the editor', cutLeft.trim() === '', JSON.stringify(cutLeft));
  52. check(L + 'cut then paste gives the cut text back', v2.trim() === 'gamma delta', JSON.stringify(v2));
  53. // 3. plain text with several lines, cursor in the middle of existing text
  54. await fresh();
  55. for (const ch of 'startend') await key(ch, '', undefined, ch);
  56. for (let i = 0; i < 3; i++) await key('ArrowLeft', 'ArrowLeft', 37);
  57. await pasteData({ 'text/plain': 'one\ntwo\nthree' }); await sleep(250);
  58. const v3 = await val();
  59. check(L + 'plain multi-line paste in the middle of text keeps all the words', ['start', 'one', 'two', 'three', 'end'].every(w => v3.includes(w)) && v3.indexOf('start') < v3.indexOf('one') && v3.indexOf('three') < v3.indexOf('end'), JSON.stringify(v3));
  60. // 4. text copied from a rendered page (text/html + text/plain), several lines, in the middle of text
  61. await fresh();
  62. for (const ch of 'headtail') await key(ch, '', undefined, ch);
  63. for (let i = 0; i < 4; i++) await key('ArrowLeft', 'ArrowLeft', 37);
  64. await pasteData({ 'text/plain': plain, 'text/html': '<meta charset="utf-8"><p>first line</p><p>second line</p><p>third line</p>' }); await sleep(250);
  65. const v4 = await val();
  66. check(L + 'html+plain paste in the middle of text keeps the lines in order', v4.indexOf('head') < v4.indexOf('first line') && v4.indexOf('first line') < v4.indexOf('second line') && v4.indexOf('second line') < v4.indexOf('third line') && v4.indexOf('third line') < v4.indexOf('tail'), JSON.stringify(v4));
  67. // 5. empty editor, plain text equals the value
  68. await fresh();
  69. await pasteData({ 'text/plain': plain }); await sleep(250);
  70. const v5 = await val();
  71. check(L + 'multi-line plain paste into an empty editor equals the text', v5.trim() === plain || v5.replace(/\n+/g, '\n').trim() === plain, JSON.stringify(v5));
  72. // 6. a document with a heading, bold, a link, code, lists: select all, Ctrl+C, empty the editor, Ctrl+V -> the same Markdown
  73. // (the browser's own plain text of the selection has the marks stripped and the lists run together)
  74. const doc = '# Head\n\nSome `code` and a [link](https://x.org) and **bold** words.\n\n- one\n- two\n\n1. a\n2. b';
  75. await fresh();
  76. await page.click('md-editor:nth-of-type(2) footer button'); await sleep(200);
  77. await page.click('md-editor:nth-of-type(2) textarea');
  78. await send('Input.insertText', { text: doc }); await sleep(250);
  79. await page.click('md-editor:nth-of-type(2) footer button'); await sleep(300);
  80. await focusEditor();
  81. await chord('a'); await chord('c', 'copy'); await sleep(100);
  82. await ev(`(() => { const a = ${E}.querySelector('article'); a.focus(); const r = document.createRange(); r.selectNodeContents(a); getSelection().removeAllRanges(); getSelection().addRange(r); })()`);
  83. await key('Backspace', 'Backspace', 8); await sleep(150);
  84. await ev(`(() => { const a = ${E}.querySelector('article'); a.innerHTML = '<p><br></p>'; a.focus(); })()`);
  85. await chord('v', 'paste'); await sleep(300);
  86. const v6 = await val();
  87. check(L + 'copy a formatted document, paste it into an emptied editor: the same Markdown', v6.trim() === doc, JSON.stringify(v6));
  88. // 7. cut one word with a real Shift+Arrow selection, paste it back at the end: the word comes back
  89. await fresh();
  90. for (const ch of 'say loud') await key(ch, '', undefined, ch);
  91. for (let i = 0; i < 4; i++) await key('ArrowLeft', 'ArrowLeft', 37, undefined, 8);
  92. await chord('x', 'cut'); await sleep(200);
  93. const cutRest = await val();
  94. await key('End', 'End', 35); await chord('v', 'paste'); await sleep(300);
  95. const v7 = await val();
  96. check(L + 'cut a word, paste it at the end: it comes back', cutRest.trim() === 'say' && v7.replace(/\s+/g, '').includes('sayloud'), JSON.stringify([cutRest, v7]));
  97. // 8. a clipboard with text/html and no text/plain (copied from some apps and pages): the pasted text arrives
  98. await fresh();
  99. await pasteData({ 'text/html': '<meta charset="utf-8"><p>first line</p><p>second line</p>' }); await sleep(250);
  100. const v8 = await val();
  101. check(L + 'html-only paste gives the text of its blocks', v8.includes('first line') && v8.includes('second line'), JSON.stringify(v8));
  102. }

Branches

Latest commits

  • 23b9164aMdEditor: a clipboard whose text is only the names or file:// paths of its files (a file manager copy) is about the files, as before; any other text wins (tickets#49); gate casesmre
  • b0f1ec28MdEditor: a clipboard with text always pastes the text, also when a picture is on it too (a spreadsheet or office app), files on or off; a picture alone still goes to the files; real Ctrl+V gate tests/md-paste-files.mjs (tickets#49)mre
  • 4bd11128MdEditor: the Table button's empty table is written as a real pipe table (empty cells), so it survives the source switch, a save and a reload (notes#7)mre
  • 7437e32bMdEditor draws its surface at once when claimed from server HTML: 1 ms mount animation, the first editor mounts all editors of the pagemre
  • 5de0264cRe-vendor onto Hybriel master acaceaf3 (set-day27b): binary, lib and plugins; exit 1 on a startup fault; .gitignore binmre
  • 79c77e7dMerge sb3-standby: components deploys through its standbymre
  • c5442043components: no jobs switch needed in the standbymre
  • 8d2fb24ccomponents: a standby container (port 45016, profile standby); deploy hands over through standby-swap.sh without a gapmre
  • c2834dd3Merge mr-fixes: media player state after a queue pick, Range handling, cover-less audio, accessibility labelsmre
  • 354fe3c6Media player: audio without a cover starts and shows its time (the mount tick sits on the seek bar, which every item has); the speed button names the current speed, the seek slider says its time in words; a gate page for the first render on cover-less audio and a fourth demo queue item without a covermre
  • ee4aee1eMedia player: a new queue item shows its own speed, mute, play state and time and starts when asked, also for two videos in a row; the media route reads suffix ranges and ignores range lists and garbage instead of answering 500; stronger gate checks (the 10 percent drag, the played bar, the queue tap)mre
  • 9a4f9b31Merge mp-player: media served from the committed filesmre
  • ab96e686Media route: serve the demo's media from the committed files in components/media-player (storage/ is not in git, the deploy gate found no files)mre
  • b2980734Merge mp-player: the media player (components/media-player), its demo and the media iconsmre
  • 1c41293eMediaPlayer: back / forward 10 s as replay / forward 10 icons (circular arrow with a 10), the play button keeps its surface background on audio and video, the media route's range end is a letmre
  • 9e1ab228MP: report, LOG line, STATUS entrymre
  • dd003e5dMediaPlayer: audio and video in one phone-first player (components/media-player), its demo /media-player with a queue, the media icons in components/icons, the demo's media files served with ranges (lib/media.hl), 35 gate checksmre
  • e54f83adMdEditor: text typed before the editor is built is kept (the build takes it in once, the input handler no longer writes it to the field first), tickets#35mre
  • 8c920932gate: the 11 old drop-zone checks now test the one-box pick mode (drop anywhere in the box, Choose files button inside it, no drop zone)mre
  • 626de199MdEditor: copy and cut put the selection's Markdown on the clipboard, a clipboard with HTML only pastes its text, gate checks for copy, cut and paste (components#20)mre