2019-11-11 20:15:16 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface FragmentInspector tests.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2019-11-11 20:15:16 +00:00
|
|
|
*/
|
|
|
|
|
2022-03-04 13:48:14 +00:00
|
|
|
QUnit.module( 've.ui.FragmentInspector (MW)', ve.test.utils.newMwEnvironment( {
|
2021-04-30 09:33:22 +00:00
|
|
|
beforeEach() {
|
2020-05-20 14:54:04 +00:00
|
|
|
// Mock XHR for mw.Api()
|
|
|
|
this.server = this.sandbox.useFakeServer();
|
|
|
|
this.server.respondImmediately = true;
|
2022-03-04 13:48:14 +00:00
|
|
|
}
|
2020-05-20 14:54:04 +00:00
|
|
|
} ) );
|
2019-11-11 20:15:16 +00:00
|
|
|
|
|
|
|
/* Tests */
|
|
|
|
|
2024-06-04 03:39:48 +00:00
|
|
|
QUnit.test( 'Wikitext link inspector', ( assert ) => {
|
2021-04-29 14:42:18 +00:00
|
|
|
const done = assert.async(),
|
2019-11-11 20:15:16 +00:00
|
|
|
surface = ve.init.target.createSurface(
|
|
|
|
ve.dm.converter.getModelFromDom(
|
|
|
|
ve.createDocumentFromHtml(
|
|
|
|
'<p>Foo [[bar]] [[Quux|baz]] x</p>' +
|
|
|
|
'<p>wh]]ee</p>'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
{ mode: 'source' }
|
|
|
|
),
|
|
|
|
cases = [
|
|
|
|
{
|
|
|
|
msg: 'Collapsed selection expands to word',
|
|
|
|
name: 'wikitextLink',
|
|
|
|
range: new ve.Range( 2 ),
|
|
|
|
expectedRange: new ve.Range( 1, 8 ),
|
2021-04-30 09:33:22 +00:00
|
|
|
expectedData: ( data ) => {
|
2019-11-11 20:15:16 +00:00
|
|
|
data.splice(
|
|
|
|
1, 3,
|
2024-05-24 21:23:42 +00:00
|
|
|
...'[[Foo]]'
|
2019-11-11 20:15:16 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Collapsed selection in word (noExpand)',
|
|
|
|
name: 'wikitextLink',
|
|
|
|
range: new ve.Range( 2 ),
|
|
|
|
setupData: { noExpand: true },
|
|
|
|
expectedRange: new ve.Range( 2 ),
|
2021-04-30 09:33:22 +00:00
|
|
|
expectedData: () => {}
|
2019-11-11 20:15:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Cancel restores original data & selection',
|
|
|
|
name: 'wikitextLink',
|
|
|
|
range: new ve.Range( 2 ),
|
|
|
|
expectedRange: new ve.Range( 2 ),
|
2021-04-30 09:33:22 +00:00
|
|
|
expectedData: () => {},
|
2019-11-11 20:15:16 +00:00
|
|
|
actionData: {}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Collapsed selection inside existing link',
|
|
|
|
name: 'wikitextLink',
|
|
|
|
range: new ve.Range( 5 ),
|
|
|
|
expectedRange: new ve.Range( 5, 12 ),
|
2021-04-30 09:33:22 +00:00
|
|
|
expectedData: () => {}
|
2019-11-11 20:15:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Selection inside existing link',
|
|
|
|
name: 'wikitextLink',
|
|
|
|
range: new ve.Range( 19, 20 ),
|
|
|
|
expectedRange: new ve.Range( 13, 25 ),
|
2021-04-30 09:33:22 +00:00
|
|
|
expectedData: () => {}
|
2019-11-11 20:15:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Selection spanning existing link',
|
|
|
|
name: 'wikitextLink',
|
|
|
|
range: new ve.Range( 3, 8 ),
|
|
|
|
expectedRange: new ve.Range( 3, 8 ),
|
2021-04-30 09:33:22 +00:00
|
|
|
expectedData: () => {}
|
2019-11-11 20:15:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Selection with whitespace is trimmed',
|
|
|
|
name: 'wikitextLink',
|
|
|
|
range: new ve.Range( 1, 5 ),
|
|
|
|
expectedRange: new ve.Range( 1, 8 )
|
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Link insertion',
|
|
|
|
name: 'wikitextLink',
|
|
|
|
range: new ve.Range( 26 ),
|
|
|
|
input: function () {
|
|
|
|
this.annotationInput.getTextInputWidget().setValue( 'quux' );
|
|
|
|
},
|
|
|
|
expectedRange: new ve.Range( 34 ),
|
2021-04-30 09:33:22 +00:00
|
|
|
expectedData: ( data ) => {
|
2024-05-29 16:03:23 +00:00
|
|
|
data.splice( 26, 0, ...[ ...'[[quux]]' ] );
|
2019-11-11 20:15:16 +00:00
|
|
|
}
|
|
|
|
},
|
2019-12-02 17:19:33 +00:00
|
|
|
{
|
|
|
|
msg: 'Link insertion to file page',
|
|
|
|
name: 'wikitextLink',
|
|
|
|
range: new ve.Range( 26 ),
|
|
|
|
input: function () {
|
|
|
|
this.annotationInput.getTextInputWidget().setValue( 'File:foo.jpg' );
|
|
|
|
},
|
|
|
|
expectedRange: new ve.Range( 43 ),
|
2021-04-30 09:33:22 +00:00
|
|
|
expectedData: ( data ) => {
|
2024-05-29 16:03:23 +00:00
|
|
|
data.splice( 26, 0, ...[ ...'[[:File:foo.jpg]]' ] );
|
2019-12-02 17:19:33 +00:00
|
|
|
}
|
|
|
|
},
|
2019-11-11 20:15:16 +00:00
|
|
|
{
|
|
|
|
msg: 'Link insertion with no input is no-op',
|
|
|
|
name: 'wikitextLink',
|
|
|
|
range: new ve.Range( 26 ),
|
|
|
|
expectedRange: new ve.Range( 26 ),
|
2021-04-30 09:33:22 +00:00
|
|
|
expectedData: () => {}
|
2019-11-11 20:15:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Link modified',
|
|
|
|
name: 'wikitextLink',
|
|
|
|
range: new ve.Range( 5, 12 ),
|
|
|
|
input: function () {
|
|
|
|
this.annotationInput.getTextInputWidget().setValue( 'quux' );
|
|
|
|
},
|
|
|
|
expectedRange: new ve.Range( 5, 17 ),
|
2021-04-30 09:33:22 +00:00
|
|
|
expectedData: ( data ) => {
|
2024-05-29 16:03:23 +00:00
|
|
|
data.splice( 7, 3, ...[ ...'Quux|bar' ] );
|
2019-11-11 20:15:16 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Link modified with initial selection including whitespace',
|
|
|
|
name: 'wikitextLink',
|
|
|
|
range: new ve.Range( 4, 13 ),
|
|
|
|
input: function () {
|
|
|
|
this.annotationInput.getTextInputWidget().setValue( 'quux' );
|
|
|
|
},
|
|
|
|
expectedRange: new ve.Range( 5, 17 ),
|
2021-04-30 09:33:22 +00:00
|
|
|
expectedData: ( data ) => {
|
2024-05-29 16:03:23 +00:00
|
|
|
data.splice( 7, 3, ...[ ...'Quux|bar' ] );
|
2019-11-11 20:15:16 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Piped link modified',
|
|
|
|
name: 'wikitextLink',
|
|
|
|
range: new ve.Range( 16 ),
|
|
|
|
input: function () {
|
|
|
|
this.annotationInput.getTextInputWidget().setValue( 'whee' );
|
|
|
|
},
|
|
|
|
expectedRange: new ve.Range( 13, 25 ),
|
2021-04-30 09:33:22 +00:00
|
|
|
expectedData: ( data ) => {
|
2024-05-29 16:03:23 +00:00
|
|
|
data.splice( 15, 4, ...[ ...'Whee' ] );
|
2019-11-11 20:15:16 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Link modified',
|
|
|
|
name: 'wikitextLink',
|
|
|
|
range: new ve.Range( 30, 36 ),
|
|
|
|
input: function () {
|
|
|
|
this.annotationInput.getTextInputWidget().setValue( 'foo' );
|
|
|
|
},
|
|
|
|
expectedRange: new ve.Range( 30, 61 ),
|
2021-04-30 09:33:22 +00:00
|
|
|
expectedData: ( data ) => {
|
2024-05-29 16:03:23 +00:00
|
|
|
data.splice( 30, 6, ...[ ...'[[Foo|wh<nowiki>]]</nowiki>ee]]' ] );
|
2019-11-11 20:15:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Skips clear annotation test, not implement yet
|
|
|
|
];
|
|
|
|
|
2021-04-30 09:33:22 +00:00
|
|
|
ve.test.utils.runFragmentInspectorTests( surface, assert, cases ).finally( () => {
|
2019-11-11 20:15:16 +00:00
|
|
|
done();
|
|
|
|
} );
|
|
|
|
} );
|