| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
QUnit.module( 've.ui.DSVFileTransferHandler' ); |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
QUnit.test( 'getInsertableData', ( assert ) => { |
| 12 |
const done = assert.async(), |
| 13 |
fn = function () {}, |
| 14 |
item = { |
| 15 |
getAsFile: function () { |
| 16 |
return { name: 'File' }; |
| 17 |
} |
| 18 |
}, |
| 19 |
mockSurface = { |
| 20 |
createProgress: function () { |
| 21 |
return ve.createDeferred().resolve( |
| 22 |
{ setProgress: fn }, |
| 23 |
ve.createDeferred().resolve().promise() |
| 24 |
).promise(); |
| 25 |
} |
| 26 |
}, |
| 27 |
mockReader = { |
| 28 |
readAsText: fn, |
| 29 |
result: 'a,b\nc,d\n' |
| 30 |
}; |
| 31 |
|
| 32 |
const handler = ve.ui.dataTransferHandlerFactory.create( 'dsv', mockSurface, item ); |
| 33 |
|
| 34 |
handler.reader = mockReader; |
| 35 |
handler.onFileLoad(); |
| 36 |
|
| 37 |
handler.getInsertableData().done( ( data ) => { |
| 38 |
assert.deepEqual( data, [ |
| 39 |
{ type: 'table' }, |
| 40 |
{ type: 'tableSection', attributes: { style: 'body' } }, |
| 41 |
{ type: 'tableRow' }, |
| 42 |
{ type: 'tableCell', attributes: { style: 'header' } }, |
| 43 |
{ type: 'paragraph', internal: { generated: 'wrapper' } }, |
| 44 |
'a', |
| 45 |
{ type: '/paragraph' }, |
| 46 |
{ type: '/tableCell' }, |
| 47 |
{ type: 'tableCell', attributes: { style: 'header' } }, |
| 48 |
{ type: 'paragraph', internal: { generated: 'wrapper' } }, |
| 49 |
'b', |
| 50 |
{ type: '/paragraph' }, |
| 51 |
{ type: '/tableCell' }, |
| 52 |
{ type: '/tableRow' }, |
| 53 |
{ type: 'tableRow' }, |
| 54 |
{ type: 'tableCell', attributes: { style: 'data' } }, |
| 55 |
{ type: 'paragraph', internal: { generated: 'wrapper' } }, |
| 56 |
'c', |
| 57 |
{ type: '/paragraph' }, |
| 58 |
{ type: '/tableCell' }, |
| 59 |
{ type: 'tableCell', attributes: { style: 'data' } }, |
| 60 |
{ type: 'paragraph', internal: { generated: 'wrapper' } }, |
| 61 |
'd', |
| 62 |
{ type: '/paragraph' }, |
| 63 |
{ type: '/tableCell' }, |
| 64 |
{ type: '/tableRow' }, |
| 65 |
{ type: '/tableSection' }, |
| 66 |
{ type: '/table' } |
| 67 |
], 'DSV data' ); |
| 68 |
done(); |
| 69 |
} ); |
| 70 |
} ); |