Feature #44642 » 0001-Add-a-system-test-for-pasting-an-image-from-the-clip.patch
| test/system/issues_test.rb | ||
|---|---|---|
| 191 | 191 |
assert_no_selector '.add_attachment', :visible => true |
| 192 | 192 |
end |
| 193 | 193 | |
| 194 |
def test_paste_image_from_clipboard |
|
| 195 |
set_tmp_attachments_directory |
|
| 196 |
log_user('jsmith', 'jsmith')
|
|
| 197 |
visit '/projects/ecookbook/issues/new' |
|
| 198 | ||
| 199 |
page.execute_script(<<~JS) |
|
| 200 |
// 1x1 1-bit grayscale PNG image |
|
| 201 |
const png = Uint8Array.from(atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklEQVR42mNgAAAAAgAB5Sfe/AAAAABJRU5ErkJggg=='), c => c.charCodeAt(0));
|
|
| 202 |
const clipboardData = new DataTransfer(); |
|
| 203 |
clipboardData.items.add(new File([png], 'image.png', { type: 'image/png' }));
|
|
| 204 |
const event = new Event('paste', { bubbles: true, cancelable: true });
|
|
| 205 |
Object.defineProperty(event, 'clipboardData', { value: clipboardData });
|
|
| 206 |
document.getElementById('issue_description').dispatchEvent(event);
|
|
| 207 |
JS |
|
| 208 |
filename = find('.attachments_fields input.filename').value
|
|
| 209 |
assert_match /\Aclipboard-\d{12}-[a-z0-9]{5}\.png\z/, filename
|
|
| 210 |
assert_field 'issue_description', :with => %(<img style="width: 1px;" src="#{filename}"><br>\n)
|
|
| 211 |
end |
|
| 212 | ||
| 194 | 213 |
def test_pasting_image_beyond_max_attachments_at_once_should_show_error |
| 195 | 214 |
set_tmp_attachments_directory |
| 196 | 215 |
log_user('jsmith', 'jsmith')
|