', { 'class': 'mwe-popups-fade-in-up' } ),
hasThumbnail: false,
thumbnail: null,
isTall: false
},
done = assert.async( 1 ),
$container = $( '
' ).append( preview.el ),
promise = renderer.hide( preview );
assert.ok(
preview.el.hasClass( 'mwe-popups-fade-out-down' ),
'Thumbnail has faded out down.'
);
assert.notOk(
preview.el.hasClass( 'mwe-popups-fade-in-up' ),
'Fade-in class has been removed.'
);
assert.notEqual(
$container.html(),
'',
'Preview is still in the container.'
);
promise.done( function () {
assert.equal(
$container.html(),
'',
'Preview has been removed from the container.'
);
done();
} );
} );
QUnit.test( 'createThumbnail - tall image', function ( assert ) {
var devicePixelRatio = $.bracketedDevicePixelRatio(),
rawThumbnail = {
source: 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/8d/President_Barack_Obama.jpg/409px-President_Barack_Obama.jpg',
width: 409,
height: 512
},
thumbnail = renderer.createThumbnail( rawThumbnail );
assert.equal(
thumbnail.isTall,
true,
'Thumbnail is tall.'
);
assert.equal(
thumbnail.width,
thumbnail.width / devicePixelRatio,
'Thumbnail width is correct.'
);
assert.equal(
thumbnail.height,
thumbnail.height / devicePixelRatio,
'Thumbnail height is correct.'
);
} );
QUnit.test( 'createThumbnail - landscape image', function ( assert ) {
var devicePixelRatio = $.bracketedDevicePixelRatio(),
rawThumbnail = {
source: 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/8d/President_Barack_Obama.jpg/500px-President_Barack_Obama.jpg',
width: 500,
height: 400
},
thumbnail = renderer.createThumbnail( rawThumbnail );
assert.equal(
thumbnail.isTall,
false,
'Thumbnail is not tall.'
);
assert.equal(
thumbnail.width,
thumbnail.width / devicePixelRatio,
'Thumbnail width is correct.'
);
assert.equal(
thumbnail.height,
thumbnail.height / devicePixelRatio,
'Thumbnail height is correct.'
);
} );
QUnit.test( 'createThumbnailElement', function ( assert ) {
var className = 'thumb-class',
url = 'https://thumbnail.url',
x = 25,
y = 50,
thumbnailWidth = 200,
thumbnailHeight = 250,
width = 500,
height = 300,
clipPath = 'mwe-popups-mask',
$thumbnail = renderer.createThumbnailElement(
className, url, x, y, thumbnailWidth, thumbnailHeight,
width, height, clipPath );
assert.equal(
$thumbnail.html(),
'
',
'Thumbnail HTML is correct.'
);
assert.equal(
$thumbnail.attr( 'xmlns' ),
'http://www.w3.org/2000/svg',
'SVG namespace is correct.'
);
assert.equal( $thumbnail.attr( 'height' ), height, 'SVG height is correct.' );
assert.equal( $thumbnail.attr( 'width' ), width, 'SVG width is correct.' );
} );
QUnit.test( 'getProcessedElements', function ( assert ) {
var cases = [
[
'Isaac Newton was born in', 'Isaac Newton',
'
Isaac Newton was born in',
'Title as first word'
],
[
'The C* language not to be confused with C# or C', 'C*',
'The
C* language not to be confused with C# or C',
'Title containing *'
],
[
'I like trains', 'Train',
'I like
trains',
'Make the simple plural bold'
],
[
'Foo\'s pub is a pub in Bar', 'Foo\'s pub',
'
Foo\'s pub is a pub in Bar',
'Correct escaping'
],
[
'\"Heroes\" is a David Bowie album', '\"Heroes\"',
'
\"Heroes\" is a David Bowie album',
'Quotes in title'
],
[
'*Testing if Things are correctly identified', 'Things',
'*Testing if
Things are correctly identified',
'Article that begins with asterisk'
],
[
'Testing if repeated words are not matched when repeated', 'Repeated',
'Testing if
repeated words are not matched when repeated',
'Repeated title'
]
];
function test( extract, title, expected, msg ) {
var $div = $( '
' ).append(
renderer.renderExtract( extract, title )
);
assert.equal( $div.html(), expected, msg );
}
cases.forEach( function ( case_ ) {
test( case_[ 0 ], case_[ 1 ], case_[ 2 ], case_[ 3 ] );
} );
} );
QUnit.test( '#getClasses when no thumbnail is available', function ( assert ) {
var cases = [
// [ previewOptions, layoutOptions, expected, message ]
[
{
hasThumbnail: false,
isTall: false
},
{
flippedX: false,
flippedY: false
},
[
'mwe-popups-fade-in-up',
'mwe-popups-no-image-tri',
'mwe-popups-is-not-tall'
],
'No flip.'
],
[
{
hasThumbnail: false,
isTall: false
},
{
flippedX: false,
flippedY: true
},
[
'mwe-popups-fade-in-down',
'flipped_y',
'mwe-popups-is-not-tall'
],
'Y flipped.'
],
[
{
hasThumbnail: false,
isTall: false
},
{
flippedX: true,
flippedY: false
},
[
'mwe-popups-fade-in-up',
'flipped_x',
'mwe-popups-no-image-tri',
'mwe-popups-is-not-tall'
],
'X flipped.'
],
[
{
hasThumbnail: false,
isTall: false
},
{
flippedX: true,
flippedY: true
},
[
'mwe-popups-fade-in-down',
'flipped_x_y',
'mwe-popups-is-not-tall'
],
'X and Y flipped.'
]
];
cases.forEach( function ( case_ ) {
assert.deepEqual(
renderer.getClasses( case_[ 0 ], case_[ 1 ] ),
case_[ 2 ],
case_[ 3 ]
);
} );
} );
QUnit.test( '#getClasses when a non-tall thumbnail is available', function ( assert ) {
var cases = [
[
{
hasThumbnail: true,
isTall: false
},
{
flippedX: false,
flippedY: false
},
[
'mwe-popups-fade-in-up',
'mwe-popups-image-tri',
'mwe-popups-is-not-tall'
],
'No flip.'
],
[
{
hasThumbnail: true,
isTall: false
},
{
flippedX: false,
flippedY: true
},
[
'mwe-popups-fade-in-down',
'flipped_y',
'mwe-popups-is-not-tall'
],
'Y flipped.'
],
[
{
hasThumbnail: true,
isTall: false
},
{
flippedX: true,
flippedY: false
},
[
'mwe-popups-fade-in-up',
'flipped_x',
'mwe-popups-image-tri',
'mwe-popups-is-not-tall'
],
'X flipped.'
],
[
{
hasThumbnail: true,
isTall: false
},
{
flippedX: true,
flippedY: true
},
[
'mwe-popups-fade-in-down',
'flipped_x_y',
'mwe-popups-is-not-tall'
],
'X and Y flipped.'
]
];
cases.forEach( function ( case_ ) {
assert.deepEqual(
renderer.getClasses( case_[ 0 ], case_[ 1 ] ),
case_[ 2 ],
case_[ 3 ]
);
} );
} );
QUnit.test( '#getClasses when a tall thumbnail is available', function ( assert ) {
var cases = [
[
{
hasThumbnail: true,
isTall: true
},
{
flippedX: false,
flippedY: false
},
[
'mwe-popups-fade-in-up',
'mwe-popups-no-image-tri',
'mwe-popups-is-tall'
],
'No flip.'
],
[
{
hasThumbnail: true,
isTall: true
},
{
flippedX: false,
flippedY: true
},
[
'mwe-popups-fade-in-down',
'flipped_y',
'mwe-popups-is-tall'
],
'Y flipped.'
],
[
{
hasThumbnail: true,
isTall: true
},
{
flippedX: true,
flippedY: false
},
[
'mwe-popups-fade-in-up',
'flipped_x',
'mwe-popups-no-image-tri',
'mwe-popups-is-tall'
],
'X flipped.'
],
[
{
hasThumbnail: true,
isTall: true
},
{
flippedX: true,
flippedY: true
},
[
'mwe-popups-fade-in-down',
'flipped_x_y',
'mwe-popups-is-tall'
],
'X and Y flipped.'
]
];
cases.forEach( function ( case_ ) {
assert.deepEqual(
renderer.getClasses( case_[ 0 ], case_[ 1 ] ),
case_[ 2 ],
case_[ 3 ]
);
} );
} );
QUnit.test( 'getClosestYPosition', function ( assert ) {
assert.equal( renderer.getClosestYPosition( 100, [
{
top: 99,
bottom: 119
},
{
top: 120,
bottom: 140
}
] ), 119, 'Correct lower Y.' );
assert.equal( renderer.getClosestYPosition( 100, [
{
top: 99,
bottom: 119
},
{
top: 120,
bottom: 140
}
], true ), 99, 'Correct upper Y.' );
assert.equal( renderer.getClosestYPosition( 135, [
{
top: 99,
bottom: 119
},
{
top: 120,
bottom: 140
}
], true ), 120, 'Correct upper Y 2.' );
} );