2013-07-03 01:30:10 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface Actions FormatAction tests.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2013-07-03 01:30:10 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2022-03-04 13:48:14 +00:00
|
|
|
QUnit.module( 've.ui.FormatAction (MW)', ve.test.utils.newMwEnvironment() );
|
2013-07-03 01:30:10 +00:00
|
|
|
|
|
|
|
/* Tests */
|
|
|
|
|
2021-04-30 09:33:22 +00:00
|
|
|
QUnit.test( 'convert (MW-specific types)', ( assert ) => {
|
2021-04-29 14:42:18 +00:00
|
|
|
const cases = [
|
2013-07-03 01:30:10 +00:00
|
|
|
{
|
2016-05-11 11:57:36 +00:00
|
|
|
rangeOrSelection: new ve.Range( 14, 16 ),
|
2014-08-22 20:50:48 +00:00
|
|
|
type: 'mwHeading',
|
|
|
|
attributes: { level: 2 },
|
2016-05-11 11:57:36 +00:00
|
|
|
expectedRangeOrSelection: new ve.Range( 14, 16 ),
|
2021-04-30 09:33:22 +00:00
|
|
|
expectedData: ( data ) => {
|
2014-08-22 20:50:48 +00:00
|
|
|
data.splice( 11, 2, { type: '/list' }, { type: 'mwHeading', attributes: { level: 2 } } );
|
|
|
|
data.splice( 19, 2, { type: '/mwHeading' }, { type: 'list', attributes: { style: 'bullet' } } );
|
2013-07-03 01:30:10 +00:00
|
|
|
},
|
2016-05-11 11:57:36 +00:00
|
|
|
undo: true,
|
2014-08-22 20:50:48 +00:00
|
|
|
msg: 'converting partial selection of list item "Item 2" to level 2 mwHeading'
|
2013-07-03 01:30:10 +00:00
|
|
|
},
|
|
|
|
{
|
2016-05-11 11:57:36 +00:00
|
|
|
rangeOrSelection: new ve.Range( 15, 50 ),
|
2014-08-22 20:50:48 +00:00
|
|
|
type: 'mwHeading',
|
|
|
|
attributes: { level: 3 },
|
2016-05-11 11:57:36 +00:00
|
|
|
expectedRangeOrSelection: new ve.Range( 15, 44 ),
|
2021-04-30 09:33:22 +00:00
|
|
|
expectedData: ( data ) => {
|
2014-08-22 20:50:48 +00:00
|
|
|
data.splice( 11, 2, { type: '/list' }, { type: 'mwHeading', attributes: { level: 3 } } );
|
|
|
|
data.splice( 19, 4, { type: '/mwHeading' }, { type: 'mwHeading', attributes: { level: 3 } } );
|
|
|
|
data.splice( 27, 4, { type: '/mwHeading' }, { type: 'mwHeading', attributes: { level: 3 } } );
|
|
|
|
data.splice( 38, 4, { type: '/mwHeading' }, { type: 'mwHeading', attributes: { level: 3 } } );
|
|
|
|
data.splice( 46, 2, { type: '/mwHeading' }, { type: 'list', attributes: { style: 'bullet' } } );
|
2013-07-03 01:30:10 +00:00
|
|
|
},
|
2016-05-11 11:57:36 +00:00
|
|
|
undo: true,
|
2014-08-22 20:50:48 +00:00
|
|
|
msg: 'converting partial selection across two lists surrounding a paragraph'
|
2013-07-03 01:30:10 +00:00
|
|
|
},
|
|
|
|
{
|
2016-05-11 11:57:36 +00:00
|
|
|
rangeOrSelection: new ve.Range( 4, 28 ),
|
2014-08-22 20:50:48 +00:00
|
|
|
type: 'mwHeading',
|
|
|
|
attributes: { level: 1 },
|
2016-05-11 11:57:36 +00:00
|
|
|
expectedRangeOrSelection: new ve.Range( 2, 22 ),
|
2021-04-30 09:33:22 +00:00
|
|
|
expectedData: ( data ) => {
|
2014-08-22 20:50:48 +00:00
|
|
|
data.splice( 0, 3, { type: 'mwHeading', attributes: { level: 1 } } );
|
|
|
|
data.splice( 7, 4, { type: '/mwHeading' }, { type: 'mwHeading', attributes: { level: 1 } } );
|
|
|
|
data.splice( 15, 4, { type: '/mwHeading' }, { type: 'mwHeading', attributes: { level: 1 } } );
|
|
|
|
data.splice( 23, 3, { type: '/mwHeading' } );
|
2013-07-03 01:30:10 +00:00
|
|
|
},
|
2016-05-11 11:57:36 +00:00
|
|
|
undo: true,
|
2014-08-22 20:50:48 +00:00
|
|
|
msg: 'converting partial selection of all list items to level 1 MWheadings'
|
2013-07-03 01:30:10 +00:00
|
|
|
},
|
|
|
|
{
|
2016-05-11 11:57:36 +00:00
|
|
|
rangeOrSelection: new ve.Range( 5, 26 ),
|
2014-08-22 20:50:48 +00:00
|
|
|
type: 'mwPreformatted',
|
|
|
|
attributes: undefined,
|
2016-05-11 11:57:36 +00:00
|
|
|
expectedRangeOrSelection: new ve.Range( 3, 20 ),
|
2021-04-30 09:33:22 +00:00
|
|
|
expectedData: ( data ) => {
|
2014-08-22 20:50:48 +00:00
|
|
|
data.splice( 0, 3, { type: 'mwPreformatted' } );
|
|
|
|
data.splice( 7, 4, { type: '/mwPreformatted' }, { type: 'mwPreformatted' } );
|
|
|
|
data.splice( 15, 4, { type: '/mwPreformatted' }, { type: 'mwPreformatted' } );
|
|
|
|
data.splice( 23, 3, { type: '/mwPreformatted' } );
|
2013-07-03 01:30:10 +00:00
|
|
|
},
|
2016-05-11 11:57:36 +00:00
|
|
|
undo: true,
|
2014-08-22 20:50:48 +00:00
|
|
|
msg: 'converting partial selection of some list items to mwPreformatted text'
|
2013-07-03 01:30:10 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2021-04-29 14:42:18 +00:00
|
|
|
for ( let i = 0; i < cases.length; i++ ) {
|
2016-05-11 11:57:36 +00:00
|
|
|
ve.test.utils.runActionTest(
|
|
|
|
'format', assert, cases[ i ].html || ve.dm.example.isolationHtml, false, 'convert',
|
|
|
|
[ cases[ i ].type, cases[ i ].attributes ], cases[ i ].rangeOrSelection, cases[ i ].msg,
|
|
|
|
{
|
|
|
|
expectedData: cases[ i ].expectedData,
|
|
|
|
expectedRangeOrSelection: cases[ i ].expectedRangeOrSelection,
|
|
|
|
undo: cases[ i ].undo
|
|
|
|
}
|
|
|
|
);
|
2013-07-03 01:30:10 +00:00
|
|
|
}
|
|
|
|
} );
|