| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
QUnit.module( 've.dm.LinkAnnotation' ); |
| 8 |
|
| 9 |
QUnit.test( 'getFragment', ( assert ) => { |
| 10 |
const cases = [ |
| 11 |
{ |
| 12 |
msg: 'No fragment returns null', |
| 13 |
annotation: new ve.dm.LinkAnnotation( { |
| 14 |
type: 'link', |
| 15 |
attributes: { href: 'https://www.example.org/' } |
| 16 |
} ), |
| 17 |
expected: null |
| 18 |
}, |
| 19 |
{ |
| 20 |
msg: 'Blank fragment returns empty string', |
| 21 |
annotation: new ve.dm.LinkAnnotation( { |
| 22 |
type: 'link', |
| 23 |
attributes: { href: 'https://www.example.org/#' } |
| 24 |
} ), |
| 25 |
expected: '' |
| 26 |
}, |
| 27 |
{ |
| 28 |
msg: 'Extant fragment returns same string', |
| 29 |
annotation: new ve.dm.LinkAnnotation( { |
| 30 |
type: 'link', |
| 31 |
attributes: { href: 'https://www.example.org/#foo' } |
| 32 |
} ), |
| 33 |
expected: 'foo' |
| 34 |
}, |
| 35 |
{ |
| 36 |
msg: 'Hash-bang works returns full string', |
| 37 |
annotation: new ve.dm.LinkAnnotation( { |
| 38 |
type: 'link', |
| 39 |
attributes: { href: 'https://www.example.org/#!foo' } |
| 40 |
} ), |
| 41 |
expected: '!foo' |
| 42 |
}, |
| 43 |
{ |
| 44 |
msg: 'Double-hash returns everything after the first hash', |
| 45 |
annotation: new ve.dm.LinkAnnotation( { |
| 46 |
type: 'link', |
| 47 |
attributes: { href: 'https://www.example.org/##foo' } |
| 48 |
} ), |
| 49 |
expected: '#foo' |
| 50 |
}, |
| 51 |
{ |
| 52 |
msg: 'Multi-fragment returns everything after the first hash', |
| 53 |
annotation: new ve.dm.LinkAnnotation( { |
| 54 |
type: 'link', |
| 55 |
attributes: { href: 'https://www.example.org/#foo#bar#baz' } |
| 56 |
} ), |
| 57 |
expected: 'foo#bar#baz' |
| 58 |
} |
| 59 |
]; |
| 60 |
|
| 61 |
cases.forEach( ( caseItem ) => { |
| 62 |
assert.strictEqual( caseItem.annotation.getFragment(), caseItem.expected, caseItem.msg ); |
| 63 |
} ); |
| 64 |
} ); |