Debian Codegraph @

extensions/VisualEditor/lib/ve/tests/init/ve.init.Target.test.js

raw symbols SCIP
1 /*!
2 * VisualEditor tests for ve.init.Target.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 QUnit.module( 've.init.Target' );
8
9 QUnit.test( 'createModelFromDom/parseDocument (source mode)', ( assert ) => {
10 const testCases = [
11 {
12 name: 'empty',
13 sourceText: '',
14 expectedParsedDocument: '',
15 expectedModel: [ { type: 'paragraph' }, { type: '/paragraph' }, { type: 'internalList' }, { type: '/internalList' } ]
16 },
17 {
18 name: 'basic',
19 sourceText: 'A? B! CD.',
20 expectedParsedDocument: 'A? B! CD.',
21 expectedModel: [ { type: 'paragraph' }, ...'A? B! CD.', { type: '/paragraph' }, { type: 'internalList' }, { type: '/internalList' } ]
22 },
23 {
24 name: 'complex',
25 sourceText: 'A?\nB\n<!-- C! -->\n\nD.',
26 expectedParsedDocument: 'A?\nB\n<!-- C! -->\n\nD.',
27 expectedModel: [ { type: 'paragraph' }, ...'A?', { type: '/paragraph' }, { type: 'paragraph' }, 'B', { type: '/paragraph' }, { type: 'paragraph' }, ...'<!-- C! -->', { type: '/paragraph' }, { type: 'paragraph' }, { type: '/paragraph' }, { type: 'paragraph' }, ...'D.', { type: '/paragraph' }, { type: 'internalList' }, { type: '/internalList' } ]
28 },
29 {
30 name: 'unicode',
31 sourceText: '維基百科ㅋㅏ난다韓國語',
32 expectedParsedDocument: '維基百科ㅋㅏ난다韓國語',
33 expectedModel: [ { type: 'paragraph' }, ...'維基百科ㅋㅏ난다韓國語', { type: '/paragraph' }, { type: 'internalList' }, { type: '/internalList' } ]
34 }
35 ];
36
37 for ( const testCase of testCases ) {
38 const sourceDoc = ve.init.Target.static.createModelFromDom( testCase.sourceText, 'source' );
39
40 assert.true(
41 sourceDoc instanceof ve.dm.Document,
42 'Source "' + testCase.name + '" document returns a Document'
43 );
44 assert.deepEqual(
45 sourceDoc.getData(),
46 testCase.expectedModel,
47 'Source "' + testCase.name + '" document has the correct content'
48 );
49
50 const parsedSourceDoc = ve.init.Target.static.parseDocument( testCase.sourceText, 'source' );
51 assert.strictEqual(
52 parsedSourceDoc,
53 testCase.expectedParsedDocument,
54 'Source "' + testCase.name + '" document is returned intact by parseDocument'
55 );
56 }
57 } );