| 1 |
'use strict'; |
| 2 |
|
| 3 |
const { action, assert, utils } = require( 'api-testing' ); |
| 4 |
|
| 5 |
describe( 'Links', () => { |
| 6 |
const titles = ( list ) => list.map( ( p ) => utils.dbkey( p.title ) ); |
| 7 |
|
| 8 |
const pageX = utils.title( 'LinkTest_X_' ); |
| 9 |
const pageY = utils.title( 'LinkTest_Y_' ); |
| 10 |
const imageY = `File:${ pageY }`; |
| 11 |
const urlY = `http://example.com/${ pageY }`; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
let alice; |
| 16 |
|
| 17 |
before( async () => { |
| 18 |
alice = await action.alice(); |
| 19 |
|
| 20 |
const textX = `Mention a [[${ pageY }|Page]], ` + |
| 21 |
`include an [[${ imageY }]] and also link to [[:${ imageY }]], ` + |
| 22 |
`link to a URL[${ urlY }]`; |
| 23 |
|
| 24 |
|
| 25 |
await Promise.all( [ |
| 26 |
alice.edit( pageX, { text: textX } ), |
| 27 |
alice.edit( pageY, { text: 'Just some text' } ) |
| 28 |
] ); |
| 29 |
} ); |
| 30 |
|
| 31 |
describe( 'to pages', () => { |
| 32 |
it( 'can be listed', async () => { |
| 33 |
const result = await alice.prop( 'links', pageX ); |
| 34 |
const links = titles( result[ pageX ].links ); |
| 35 |
|
| 36 |
assert.sameMembers( links, [ pageY, imageY ] ); |
| 37 |
} ); |
| 38 |
|
| 39 |
it( 'can be filtered by namespace', async () => { |
| 40 |
const result = await alice.prop( 'links', pageX, { plnamespace: 0 } ); |
| 41 |
const links = titles( result[ pageX ].links ); |
| 42 |
|
| 43 |
assert.sameMembers( links, [ pageY ] ); |
| 44 |
} ); |
| 45 |
} ); |
| 46 |
|
| 47 |
describe( 'from pages', () => { |
| 48 |
it( 'can be listed', async () => { |
| 49 |
const result = await alice.prop( 'linkshere', pageY ); |
| 50 |
const links = titles( result[ pageY ].linkshere ); |
| 51 |
|
| 52 |
assert.sameMembers( links, [ pageX ] ); |
| 53 |
} ); |
| 54 |
} ); |
| 55 |
|
| 56 |
describe( 'to external pages', () => { |
| 57 |
it( 'can be listed', async () => { |
| 58 |
const result = await alice.prop( 'extlinks', pageX ); |
| 59 |
const links = result[ pageX ].extlinks.map( ( p ) => p[ '*' ] ); |
| 60 |
|
| 61 |
assert.sameMembers( links, [ urlY ] ); |
| 62 |
} ); |
| 63 |
} ); |
| 64 |
|
| 65 |
describe( 'to media', () => { |
| 66 |
it( 'can be listed', async () => { |
| 67 |
const result = await alice.prop( 'images', pageX ); |
| 68 |
const links = titles( result[ pageX ].images ); |
| 69 |
|
| 70 |
assert.sameMembers( links, [ imageY ] ); |
| 71 |
} ); |
| 72 |
} ); |
| 73 |
} ); |