File: ve.dm.SurfaceFragment.test.js

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (93 lines) | stat: -rw-r--r-- 2,656 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*!
 * VisualEditor DataModel MediaWiki-specific SurfaceFragment tests.
 *
 * @copyright See AUTHORS.txt
 * @license The MIT License (MIT); see LICENSE.txt
 */

QUnit.module( 've.dm.SurfaceFragment (MW)', ve.test.utils.newMwEnvironment() );

/* Tests */

QUnit.test( 'isolateAndUnwrap (MWheading)', ( assert ) => {
	const cases = [
		{
			type: 'mwHeading',
			range: new ve.Range( 12, 20 ),
			expected: ( data ) => {
				data.splice( 11, 0, { type: '/list' } );
				data.splice( 12, 1 );
				data.splice( 20, 1, { type: 'list', attributes: { style: 'bullet' } } );
			},
			base: ve.dm.mwExample.baseUri,
			msg: 'isolating paragraph in list item "Item 2" for MWheading'
		},
		{
			type: 'mwHeading',
			range: new ve.Range( 202, 212 ),
			expected: ( data ) => {
				data.splice( 201, 1,
					{ type: '/list' }, { type: '/listItem' }, { type: '/list' }
				);
				data.splice( 214, 1,
					{ type: 'list', attributes: { style: 'bullet' } },
					{ type: 'listItem' },
					{ type: 'list', attributes: { style: 'number' } }
				);
			},
			base: ve.dm.mwExample.baseUri,
			msg: 'isolating paragraph in list item "Nested 2" for MWheading'
		}
	];
	cases.forEach( ( caseItem ) => ve.test.utils.runIsolateTest( assert, caseItem ) );
} );

QUnit.test( 'insertContent (MWheading)', ( assert ) => {
	const doc = new ve.dm.Document( [
			{ type: 'list', attributes: { style: 'bullet' } },
			{ type: 'listItem' },
			{ type: 'paragraph' },
			...'ab',
			{ type: '/paragraph' },
			{ type: '/listItem' },
			{ type: '/list' },
			{ type: 'internalList' },
			{ type: '/internalList' }
		] ),
		surface = new ve.dm.Surface( doc ),
		headingData = [ { type: 'mwHeading', attributes: { level: 3 } }, 'x', { type: '/mwHeading' } ];

	let fragment = surface.getLinearFragment( new ve.Range( 4, 4 ) );
	fragment.insertContent( headingData );
	assert.deepEqual(
		doc.getData( new ve.Range( 3, 14 ) ),
		[
			'a',
			{ type: '/paragraph' },
			{ type: '/listItem' },
			{ type: '/list' },
			{ type: 'mwHeading', attributes: { level: 3 } },
			'x',
			{ type: '/mwHeading' },
			{ type: 'list', attributes: { style: 'bullet' } },
			{ type: 'listItem' },
			{ type: 'paragraph' },
			'b'
		],
		'inserting a mwheading into a listitem should isolate it from the list'
	);

	surface.undo();
	fragment = surface.getLinearFragment( new ve.Range( 8, 8 ) );
	fragment.insertContent( headingData );
	assert.deepEqual(
		doc.getData( new ve.Range( 7, 11 ) ),
		[
			{ type: '/list' },
			{ type: 'mwHeading', attributes: { level: 3 } },
			'x',
			{ type: '/mwHeading' }
		],
		'inserting a mwheading to the document root should not add any extra closing elements'
	);
} );