Skip to content

Commit e65a17e

Browse files
committed
Add tests for link label editing on mobile
Change-Id: Ie3cd4039630924e41b27ccf694e99a1a68bb9fd0
1 parent 523bd8e commit e65a17e

File tree

1 file changed

+66
-3
lines changed

1 file changed

+66
-3
lines changed

tests/ui/inspectors/ve.ui.FragmentInspector.test.js

+66-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ ve.test.utils.runFragmentInspectorTests = function ( surface, assert, cases ) {
2020

2121
surfaceModel.setLinearSelection( caseItem.range );
2222
const setupData = ve.extendObject( { surface: surface, fragment: surfaceModel.getFragment() }, caseItem.setupData );
23+
const isMobile = OO.ui.isMobile;
24+
if ( caseItem.isMobile ) {
25+
// Mock isMobile
26+
OO.ui.isMobile = () => true;
27+
}
2328
return inspector.setup( setupData ).then( () => inspector.ready( setupData ).then( () => {
2429
if ( caseItem.input ) {
2530
caseItem.input.call( inspector );
@@ -47,6 +52,9 @@ ve.test.utils.runFragmentInspectorTests = function ( surface, assert, cases ) {
4752
}
4853
// Insertion annotations are not cleared by undo
4954
surfaceModel.setInsertionAnnotations( null );
55+
56+
// Restore isMobile
57+
OO.ui.isMobile = isMobile;
5058
} );
5159
} ) );
5260
} ) );
@@ -167,7 +175,7 @@ QUnit.test( 'Different selections and inputs', ( assert ) => {
167175
expectedData: () => {}
168176
},
169177
{
170-
msg: 'Link modified',
178+
msg: 'Link target modified',
171179
name: 'link',
172180
range: new ve.Range( 5, 8 ),
173181
input: function () {
@@ -184,7 +192,7 @@ QUnit.test( 'Different selections and inputs', ( assert ) => {
184192
}
185193
},
186194
{
187-
msg: 'Link removed (clear input)',
195+
msg: 'Link target removed (clear input)',
188196
name: 'link',
189197
range: new ve.Range( 5, 8 ),
190198
input: function () {
@@ -199,7 +207,7 @@ QUnit.test( 'Different selections and inputs', ( assert ) => {
199207
}
200208
},
201209
{
202-
msg: 'Clear input & cancel is still a no-op',
210+
msg: 'Link target removed input then cancel is still a no-op',
203211
name: 'link',
204212
range: new ve.Range( 5, 8 ),
205213
input: function () {
@@ -209,6 +217,61 @@ QUnit.test( 'Different selections and inputs', ( assert ) => {
209217
expectedData: () => {},
210218
actionData: {}
211219
},
220+
{
221+
msg: 'Link label modified (mobile)',
222+
name: 'link',
223+
range: new ve.Range( 5, 8 ),
224+
isMobile: true,
225+
input: function () {
226+
this.labelInput.setValue( 'bat' );
227+
},
228+
expectedRange: new ve.Range( 5, 8 ),
229+
expectedData: function ( data ) {
230+
data.splice(
231+
5, 3,
232+
[ 'b', [ barHash ] ],
233+
[ 'a', [ barHash ] ],
234+
[ 't', [ barHash ] ]
235+
);
236+
}
237+
},
238+
{
239+
msg: 'Link label and link target (mobile)',
240+
name: 'link',
241+
range: new ve.Range( 5, 8 ),
242+
isMobile: true,
243+
input: function () {
244+
this.labelInput.setValue( 'bat' );
245+
this.annotationInput.getTextInputWidget().setValue( 'quux' );
246+
},
247+
expectedRange: new ve.Range( 5, 8 ),
248+
expectedData: function ( data ) {
249+
data.splice(
250+
5, 3,
251+
[ 'b', [ quuxHash ] ],
252+
[ 'a', [ quuxHash ] ],
253+
[ 't', [ quuxHash ] ]
254+
);
255+
}
256+
},
257+
{
258+
msg: 'Removing link label defaults to using link target as label (mobile)',
259+
name: 'link',
260+
range: new ve.Range( 34 ),
261+
isMobile: true,
262+
input: function () {
263+
this.labelInput.setValue( '' );
264+
},
265+
expectedRange: new ve.Range( 31, 34 ),
266+
expectedData: function ( data ) {
267+
data.splice(
268+
31, 5,
269+
[ 'b', [ barHash ] ],
270+
[ 'a', [ barHash ] ],
271+
[ 'r', [ barHash ] ]
272+
);
273+
}
274+
},
212275
{
213276
msg: 'Comment change',
214277
name: 'comment',

0 commit comments

Comments
 (0)