|
| 1 | +import dd from 'ts-dedent'; |
| 2 | + |
| 3 | +import {expect, test} from 'playwright/core'; |
| 4 | + |
| 5 | +import {Playground} from './Playground.helpers'; |
| 6 | + |
| 7 | +test.describe('Clipboard', () => { |
| 8 | + test.beforeEach(async ({mount, editor}) => { |
| 9 | + await mount(<Playground />); |
| 10 | + await editor.clearContent(); |
| 11 | + }); |
| 12 | + |
| 13 | + const emphasisMarkup = dd` |
| 14 | + ## Emphasis |
| 15 | +
|
| 16 | + **This is bold text** |
| 17 | +
|
| 18 | + *This is italic text* |
| 19 | +
|
| 20 | + ~~Strikethrough~~ |
| 21 | + `; |
| 22 | + |
| 23 | + test('should copy from wysiwyg and paste formatted to markup mode', async ({ |
| 24 | + browserName, |
| 25 | + expectScreenshot, |
| 26 | + helpers: {keys}, |
| 27 | + editor, |
| 28 | + page, |
| 29 | + }) => { |
| 30 | + test.skip(browserName === 'webkit', 'Clipboard does not work correctly in webkit'); |
| 31 | + |
| 32 | + await editor.switchMode('wysiwyg'); |
| 33 | + await editor.paste(emphasisMarkup); |
| 34 | + await editor.press(keys.selectAll); |
| 35 | + await editor.press(keys.copy); |
| 36 | + await editor.clearContent(); |
| 37 | + await editor.switchMode('markup'); |
| 38 | + await editor.press(keys.paste); |
| 39 | + |
| 40 | + await page.waitForTimeout(500); |
| 41 | + await expectScreenshot(); |
| 42 | + }); |
| 43 | + |
| 44 | + test('should copy from markup mode and paste formatted to wysiwyg', async ({ |
| 45 | + expectScreenshot, |
| 46 | + browserName, |
| 47 | + helpers: {keys}, |
| 48 | + editor, |
| 49 | + page, |
| 50 | + }) => { |
| 51 | + test.skip(browserName === 'webkit', 'Clipboard does not work correctly in webkit'); |
| 52 | + |
| 53 | + await editor.switchMode('markup'); |
| 54 | + await editor.paste(emphasisMarkup); |
| 55 | + await editor.press(keys.selectAll); |
| 56 | + await editor.press(keys.copy); |
| 57 | + await editor.clearContent(); |
| 58 | + await editor.switchMode('wysiwyg'); |
| 59 | + await editor.press(keys.paste); |
| 60 | + |
| 61 | + await page.waitForTimeout(500); |
| 62 | + await expectScreenshot(); |
| 63 | + }); |
| 64 | + |
| 65 | + test.describe('WYSIWYG mode', () => { |
| 66 | + test.beforeEach(async ({editor}) => { |
| 67 | + await editor.switchMode('wysiwyg'); |
| 68 | + }); |
| 69 | + |
| 70 | + test('should copy and paste with preserve markup', async ({ |
| 71 | + helpers: {keys}, |
| 72 | + editor, |
| 73 | + page, |
| 74 | + expectScreenshot, |
| 75 | + }) => { |
| 76 | + await editor.paste(emphasisMarkup); |
| 77 | + await editor.press(keys.selectAll); |
| 78 | + await editor.press(keys.copy); |
| 79 | + await editor.press('ArrowRight'); |
| 80 | + await editor.press('Enter'); |
| 81 | + await editor.press(keys.paste); |
| 82 | + |
| 83 | + await page.waitForTimeout(500); |
| 84 | + await expectScreenshot(); |
| 85 | + }); |
| 86 | + |
| 87 | + test.describe('Copy', () => { |
| 88 | + test('should set data to clipboard buffer', async ({ |
| 89 | + editor, |
| 90 | + helpers, |
| 91 | + browserName, |
| 92 | + platform, |
| 93 | + }) => { |
| 94 | + test.skip( |
| 95 | + browserName === 'webkit' && platform === 'linux', |
| 96 | + 'Skip in webkit on linux, see https://github.com/microsoft/playwright/issues/34307', |
| 97 | + ); |
| 98 | + |
| 99 | + await editor.paste('## Lorem *ipsum* **dolor** ~~sit~~ amet'); |
| 100 | + await editor.press(helpers.keys.selectAll); |
| 101 | + await editor.press(helpers.keys.copy); |
| 102 | + |
| 103 | + const data = await helpers.getClipboardData(); |
| 104 | + |
| 105 | + expect(data).toStrictEqual({ |
| 106 | + 'text/plain': 'Lorem ipsum dolor sit amet', |
| 107 | + 'text/html': |
| 108 | + '<h2 data-pm-slice="1 1 []">Lorem <em>ipsum</em> <strong>dolor</strong> <strike>sit</strike> amet</h2>', |
| 109 | + }); |
| 110 | + }); |
| 111 | + }); |
| 112 | + |
| 113 | + test.describe('Cut', () => { |
| 114 | + test('should set data to clipboard buffer', async ({ |
| 115 | + editor, |
| 116 | + helpers, |
| 117 | + browserName, |
| 118 | + platform, |
| 119 | + }) => { |
| 120 | + test.skip( |
| 121 | + browserName === 'webkit' && platform === 'linux', |
| 122 | + 'Skip in webkit on linux, see https://github.com/microsoft/playwright/issues/34307', |
| 123 | + ); |
| 124 | + |
| 125 | + await editor.paste('## Lorem *ipsum* **dolor** ~~sit~~ amet'); |
| 126 | + await editor.press(helpers.keys.selectAll); |
| 127 | + await editor.press(helpers.keys.cut); |
| 128 | + |
| 129 | + const data = await helpers.getClipboardData(); |
| 130 | + |
| 131 | + expect(data).toStrictEqual({ |
| 132 | + 'text/plain': 'Lorem ipsum dolor sit amet', |
| 133 | + 'text/html': |
| 134 | + '<h2 data-pm-slice="1 1 []">Lorem <em>ipsum</em> <strong>dolor</strong> <strike>sit</strike> amet</h2>', |
| 135 | + }); |
| 136 | + }); |
| 137 | + }); |
| 138 | + |
| 139 | + test.describe('Paste', () => { |
| 140 | + test('should parse markdown markup', async ({page, editor, expectScreenshot}) => { |
| 141 | + await editor.paste({ |
| 142 | + 'text/plain': 'Lorem ipsum dolor sit amet', |
| 143 | + 'text/yfm': '## Lorem *ipsum* **dolor** ~~sit~~ amet', |
| 144 | + }); |
| 145 | + |
| 146 | + await page.waitForTimeout(500); |
| 147 | + await expectScreenshot(); |
| 148 | + }); |
| 149 | + |
| 150 | + test('should parse pasting text as markdown markup', async ({ |
| 151 | + page, |
| 152 | + editor, |
| 153 | + expectScreenshot, |
| 154 | + }) => { |
| 155 | + await editor.paste('## Lorem *ipsum* **dolor** ~~sit~~ amet'); |
| 156 | + |
| 157 | + await page.waitForTimeout(500); |
| 158 | + await expectScreenshot(); |
| 159 | + }); |
| 160 | + |
| 161 | + test('should wrap text to link from clipboard', async ({ |
| 162 | + page, |
| 163 | + editor, |
| 164 | + expectScreenshot, |
| 165 | + }) => { |
| 166 | + await editor.fill('Gravity UI'); |
| 167 | + await editor.selectTextIn('p'); |
| 168 | + await editor.paste('https://gravity-ui.com/'); |
| 169 | + await editor.blur(); |
| 170 | + |
| 171 | + await page.waitForTimeout(500); |
| 172 | + await expectScreenshot(); |
| 173 | + }); |
| 174 | + |
| 175 | + test('should paste to code block without as is', async ({ |
| 176 | + editor, |
| 177 | + page, |
| 178 | + expectScreenshot, |
| 179 | + }) => { |
| 180 | + await editor.fill('```'); |
| 181 | + await editor.paste('## Lorem *ipsum* **dolor** ~~sit~~ amet'); |
| 182 | + await editor.blur(); |
| 183 | + |
| 184 | + await page.waitForTimeout(500); |
| 185 | + await expectScreenshot(); |
| 186 | + }); |
| 187 | + |
| 188 | + test('should replace selected text from code block with link as text', async ({ |
| 189 | + editor, |
| 190 | + page, |
| 191 | + expectScreenshot, |
| 192 | + }) => { |
| 193 | + await editor.fill('```'); |
| 194 | + await editor.fill('Lorem ipsum dolor sit amet'); |
| 195 | + await editor.selectTextIn('pre code'); |
| 196 | + await editor.paste('https://gravity-ui.com/'); |
| 197 | + await editor.blur(); |
| 198 | + |
| 199 | + await page.waitForTimeout(500); |
| 200 | + await expectScreenshot(); |
| 201 | + }); |
| 202 | + |
| 203 | + test('should insert into inline code without formatting', async ({ |
| 204 | + editor, |
| 205 | + page, |
| 206 | + expectScreenshot, |
| 207 | + }) => { |
| 208 | + await editor.paste('`Code:`'); |
| 209 | + await editor.press('ArrowLeft'); |
| 210 | + await editor.press('Space'); |
| 211 | + |
| 212 | + await editor.paste('## Lorem *ipsum* **dolor** ~~sit~~ amet'); |
| 213 | + await editor.blur(); |
| 214 | + |
| 215 | + await page.waitForTimeout(500); |
| 216 | + await expectScreenshot(); |
| 217 | + }); |
| 218 | + |
| 219 | + test('should insert link from ios safari share button', async ({ |
| 220 | + editor, |
| 221 | + page, |
| 222 | + expectScreenshot, |
| 223 | + }) => { |
| 224 | + await editor.paste({ |
| 225 | + 'text/uri-list': 'https://gravity-ui.com/', |
| 226 | + }); |
| 227 | + await editor.blur(); |
| 228 | + |
| 229 | + await page.waitForTimeout(500); |
| 230 | + await expectScreenshot(); |
| 231 | + }); |
| 232 | + }); |
| 233 | + }); |
| 234 | +}); |
0 commit comments