2017-07-28 17:32:46 +00:00
|
|
|
import * as renderer from '../../../src/ui/renderer';
|
2018-08-05 00:41:47 +00:00
|
|
|
import * as constants from '../../../src/constants';
|
2018-03-07 11:10:53 +00:00
|
|
|
import { createNullModel, previewTypes } from '../../../src/preview/model';
|
2018-03-08 20:38:23 +00:00
|
|
|
import { createThumbnail } from '../../../src/ui/thumbnail';
|
2017-07-28 17:32:46 +00:00
|
|
|
|
2018-03-19 19:39:41 +00:00
|
|
|
const $ = jQuery,
|
2018-01-11 14:57:41 +00:00
|
|
|
MSG_NO_PREVIEW = 'There was an issue displaying this preview',
|
2018-03-07 11:10:53 +00:00
|
|
|
MSG_GO_TO_PAGE = 'Go to this page',
|
|
|
|
MSG_DISAMBIGUATION = 'This title relates to more than one page',
|
|
|
|
MSG_DISAMBIGUATION_LINK = 'View similar pages';
|
2017-04-27 16:03:44 +00:00
|
|
|
|
2017-05-05 19:36:04 +00:00
|
|
|
/**
|
|
|
|
* A utility function that creates a bare bones preview
|
|
|
|
*
|
|
|
|
* @param {boolean} [isTall]
|
|
|
|
* @param {boolean} [hasThumbnail]
|
|
|
|
* @param {ext.popups.Thumbnail} [thumbnail]
|
|
|
|
* @return {ext.popups.Preview}
|
|
|
|
*/
|
2018-03-07 11:10:53 +00:00
|
|
|
function createPagePreview( isTall, hasThumbnail, thumbnail ) {
|
2017-05-03 14:50:44 +00:00
|
|
|
return {
|
|
|
|
el: $( '<div>' )
|
2017-05-05 19:36:04 +00:00
|
|
|
.append( hasThumbnail ? $( '<image>' ) : '' )
|
2017-05-03 14:50:44 +00:00
|
|
|
.append( $( '<a>', { 'class': 'mwe-popups-extract', text: 'extract' } ) )
|
2017-05-05 19:36:04 +00:00
|
|
|
.append( $( '<a>', { 'class': 'mwe-popups-settings-icon' } ) ),
|
2018-03-14 19:44:22 +00:00
|
|
|
isTall,
|
|
|
|
hasThumbnail,
|
|
|
|
thumbnail
|
2017-05-03 14:50:44 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function createBehavior( sandbox ) {
|
|
|
|
return {
|
|
|
|
settingsUrl: 'https://settings.url',
|
|
|
|
showSettings: sandbox.spy(),
|
|
|
|
previewDwell: sandbox.spy(),
|
|
|
|
previewAbandon: sandbox.spy(),
|
|
|
|
previewShow: sandbox.spy(),
|
|
|
|
click: sandbox.spy()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-04-27 21:44:22 +00:00
|
|
|
QUnit.module( 'ext.popups#renderer', {
|
2018-03-14 22:04:59 +00:00
|
|
|
beforeEach() {
|
2018-08-05 00:41:47 +00:00
|
|
|
this.sandbox.stub( constants.default, 'BRACKETED_DEVICE_PIXEL_RATIO' ).value( 1 );
|
2017-05-02 21:30:30 +00:00
|
|
|
|
2018-06-21 15:47:13 +00:00
|
|
|
mediaWiki.msg = ( key ) => {
|
2017-05-02 20:09:54 +00:00
|
|
|
switch ( key ) {
|
|
|
|
case 'popups-preview-no-preview':
|
2018-01-11 14:57:41 +00:00
|
|
|
return MSG_NO_PREVIEW;
|
2017-05-02 20:09:54 +00:00
|
|
|
case 'popups-preview-footer-read':
|
2018-01-11 14:57:41 +00:00
|
|
|
return MSG_GO_TO_PAGE;
|
2018-03-07 11:10:53 +00:00
|
|
|
case 'popups-preview-disambiguation':
|
|
|
|
return MSG_DISAMBIGUATION;
|
|
|
|
case 'popups-preview-disambiguation-link':
|
|
|
|
return MSG_DISAMBIGUATION_LINK;
|
2017-05-02 20:09:54 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-24 14:06:21 +00:00
|
|
|
mediaWiki.html = { escape: ( str ) => {
|
|
|
|
return str && str.replace( /</g, '<' );
|
|
|
|
} };
|
2018-04-12 01:51:42 +00:00
|
|
|
|
|
|
|
// Some tests below stub this function. Keep a copy so it can be restored.
|
|
|
|
this.getElementById = document.getElementById;
|
2017-04-27 21:44:22 +00:00
|
|
|
},
|
2018-03-14 22:04:59 +00:00
|
|
|
afterEach() {
|
2018-04-12 01:51:42 +00:00
|
|
|
// Restore getElementsById to its original state.
|
|
|
|
document.getElementById = this.getElementById;
|
2018-06-21 15:47:13 +00:00
|
|
|
mediaWiki.msg = null;
|
|
|
|
mediaWiki.html = null;
|
2017-04-27 21:44:22 +00:00
|
|
|
}
|
|
|
|
} );
|
2017-04-27 16:03:44 +00:00
|
|
|
|
2018-06-26 20:47:10 +00:00
|
|
|
QUnit.test( 'getExtractWidth', ( assert ) => {
|
|
|
|
const cases = [
|
|
|
|
[
|
|
|
|
null,
|
|
|
|
''
|
|
|
|
],
|
|
|
|
[ {
|
|
|
|
isNarrow: true, offset: 10
|
|
|
|
}, `${renderer.defaultExtractWidth + 10}px` ],
|
|
|
|
[ {
|
|
|
|
// Fall back to css stylesheet for non-narrow thumbs.
|
|
|
|
isNarrow: false, offset: 100
|
|
|
|
}, '' ]
|
|
|
|
];
|
|
|
|
|
|
|
|
cases.forEach( ( case_, i ) => {
|
|
|
|
assert.strictEqual(
|
|
|
|
renderer.getExtractWidth( case_[ 0 ] ),
|
|
|
|
case_[ 1 ],
|
|
|
|
`Case ${i}: the expected extract width matches.`
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2018-04-26 13:25:55 +00:00
|
|
|
QUnit.test( 'createPointerMasks', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const $container = $( '<div>' ),
|
2017-04-27 19:55:43 +00:00
|
|
|
cases = [
|
|
|
|
[ 'clippath#mwe-popups-mask polygon', '0 8, 10 8, 18 0, 26 8, 1000 8, 1000 1000, 0 1000' ],
|
|
|
|
[ 'clippath#mwe-popups-mask-flip polygon', '0 8, 274 8, 282 0, 290 8, 1000 8, 1000 1000, 0 1000' ],
|
|
|
|
[ 'clippath#mwe-popups-landscape-mask polygon', '0 8, 174 8, 182 0, 190 8, 1000 8, 1000 1000, 0 1000' ],
|
|
|
|
[ 'clippath#mwe-popups-landscape-mask-flip polygon', '0 0, 1000 0, 1000 242, 190 242, 182 250, 174 242, 0 242' ]
|
|
|
|
];
|
|
|
|
|
2018-04-26 13:25:55 +00:00
|
|
|
renderer.createPointerMasks( $container.get( 0 ) );
|
2017-04-27 19:55:43 +00:00
|
|
|
|
2018-05-08 19:48:17 +00:00
|
|
|
cases.forEach( ( case_, i ) => {
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-04-27 19:55:43 +00:00
|
|
|
$container.find( case_[ 0 ] ).attr( 'points' ),
|
2018-05-08 19:48:17 +00:00
|
|
|
case_[ 1 ],
|
|
|
|
`Case ${i}: the SVG's polygons match.`
|
2017-04-27 19:55:43 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'createPagePreview', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const model = {
|
2017-05-02 21:30:30 +00:00
|
|
|
title: 'Test',
|
|
|
|
url: 'https://en.wikipedia.org/wiki/Test',
|
|
|
|
languageCode: 'en',
|
|
|
|
languageDirection: 'ltr',
|
|
|
|
extract: 'This is a test page.',
|
2018-03-07 11:10:53 +00:00
|
|
|
type: previewTypes.TYPE_PAGE,
|
2017-05-02 21:30:30 +00:00
|
|
|
thumbnail: {
|
|
|
|
source: 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/8d/President_Barack_Obama.jpg/409px-President_Barack_Obama.jpg',
|
|
|
|
width: 409,
|
|
|
|
height: 512
|
|
|
|
}
|
|
|
|
},
|
2018-03-19 19:39:41 +00:00
|
|
|
preview = renderer.createPreviewWithType( model );
|
2017-05-02 21:30:30 +00:00
|
|
|
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual( preview.hasThumbnail, true, 'Preview has thumbnail.' );
|
2017-05-02 21:30:30 +00:00
|
|
|
assert.deepEqual(
|
2018-03-13 22:03:49 +00:00
|
|
|
preview.thumbnail.el.html(),
|
|
|
|
createThumbnail( model.thumbnail ).el.html(),
|
2017-05-02 21:30:30 +00:00
|
|
|
'Preview thumbnail is the correct one.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-02 21:30:30 +00:00
|
|
|
preview.isTall,
|
|
|
|
true,
|
|
|
|
'Preview is tall (because the thumbnail is tall).'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-02 21:30:30 +00:00
|
|
|
preview.el.find( '.mwe-popups-extract' ).text(),
|
|
|
|
'This is a test page.',
|
|
|
|
'Preview extract is correct.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'createEmptyPreview(model)', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const model = {
|
2017-05-02 20:09:54 +00:00
|
|
|
title: 'Test',
|
|
|
|
url: 'https://en.wikipedia.org/wiki/Test',
|
|
|
|
languageCode: 'en',
|
|
|
|
languageDirection: 'ltr',
|
|
|
|
extract: 'This is a test page.',
|
2018-03-07 11:10:53 +00:00
|
|
|
type: previewTypes.TYPE_GENERIC,
|
2017-05-02 20:09:54 +00:00
|
|
|
thumbnail: {
|
|
|
|
source: 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/8d/President_Barack_Obama.jpg/409px-President_Barack_Obama.jpg',
|
|
|
|
width: 409,
|
|
|
|
height: 512
|
|
|
|
}
|
|
|
|
},
|
2018-03-07 11:10:53 +00:00
|
|
|
emptyPreview = renderer.createPreviewWithType( model );
|
2017-05-02 20:09:54 +00:00
|
|
|
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-02 20:09:54 +00:00
|
|
|
emptyPreview.hasThumbnail,
|
|
|
|
false,
|
|
|
|
'Empty preview doesn\'t have a thumbnail (even though one is provided).'
|
|
|
|
);
|
|
|
|
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-02 20:09:54 +00:00
|
|
|
emptyPreview.isTall,
|
|
|
|
false,
|
|
|
|
'Empty preview is never tall (even though the supplied thumbnail is tall).'
|
|
|
|
);
|
|
|
|
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2018-03-13 22:03:49 +00:00
|
|
|
emptyPreview.el.find( '.mwe-popups-title' ).text().trim(),
|
|
|
|
'',
|
|
|
|
'Empty preview title is hidden.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2018-03-13 22:03:49 +00:00
|
|
|
emptyPreview.el.find( '.mwe-popups-extract' ).text().trim(),
|
|
|
|
MSG_NO_PREVIEW,
|
|
|
|
'Empty preview extract is correct.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2018-03-13 22:03:49 +00:00
|
|
|
emptyPreview.el.find( '.mwe-popups-read-link' ).text().trim(),
|
|
|
|
MSG_GO_TO_PAGE,
|
|
|
|
'Empty preview link text is correct.'
|
2017-05-02 20:09:54 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'createEmptyPreview(null model)', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const model = createNullModel( 'Test', '/wiki/Test' ),
|
2018-03-07 11:10:53 +00:00
|
|
|
emptyPreview = renderer.createPreviewWithType( model );
|
2018-01-11 03:23:28 +00:00
|
|
|
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2018-01-11 03:23:28 +00:00
|
|
|
emptyPreview.hasThumbnail,
|
|
|
|
false,
|
|
|
|
'Null preview doesn\'t have a thumbnail.'
|
|
|
|
);
|
|
|
|
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2018-01-11 03:23:28 +00:00
|
|
|
emptyPreview.isTall,
|
|
|
|
false,
|
|
|
|
'Null preview is never tall.'
|
|
|
|
);
|
|
|
|
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2018-03-13 22:03:49 +00:00
|
|
|
emptyPreview.el.find( '.mwe-popups-title' ).text().trim(),
|
|
|
|
'',
|
|
|
|
'Empty preview title is hidden.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2018-03-13 22:03:49 +00:00
|
|
|
emptyPreview.el.find( '.mwe-popups-extract' ).text().trim(),
|
|
|
|
MSG_NO_PREVIEW,
|
|
|
|
'Empty preview extract is correct.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2018-03-13 22:03:49 +00:00
|
|
|
emptyPreview.el.find( '.mwe-popups-read-link' ).text().trim(),
|
|
|
|
MSG_GO_TO_PAGE,
|
|
|
|
'Empty preview link text is correct.'
|
2018-03-07 11:10:53 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'createDisambiguationPreview(model)', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const model = {
|
2018-03-07 11:10:53 +00:00
|
|
|
title: 'Barack (disambiguation)',
|
|
|
|
url: 'url/Barack (disambiguation)',
|
|
|
|
languageCode: 'en',
|
|
|
|
languageDirection: 'ltr',
|
|
|
|
extract: 'Barack Hussein Obama II born August 4, 1961) ...',
|
|
|
|
type: previewTypes.TYPE_DISAMBIGUATION
|
|
|
|
},
|
|
|
|
preview = renderer.createPreviewWithType( model );
|
|
|
|
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2018-03-07 11:10:53 +00:00
|
|
|
preview.hasThumbnail,
|
|
|
|
false,
|
|
|
|
'Disambiguation preview doesn\'t have a thumbnail.'
|
|
|
|
);
|
|
|
|
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2018-03-07 11:10:53 +00:00
|
|
|
preview.isTall,
|
|
|
|
false,
|
|
|
|
'Disambiguation preview is never tall.'
|
|
|
|
);
|
|
|
|
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2018-03-13 22:03:49 +00:00
|
|
|
preview.el.find( '.mwe-popups-title' ).text().trim(),
|
|
|
|
'Barack (disambiguation)',
|
|
|
|
'Preview title is show.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2018-03-13 22:03:49 +00:00
|
|
|
preview.el.find( '.mwe-popups-extract' ).text().trim(),
|
|
|
|
MSG_DISAMBIGUATION,
|
|
|
|
'Preview extract is correct.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2018-03-13 22:03:49 +00:00
|
|
|
preview.el.find( '.mwe-popups-read-link' ).text().trim(),
|
|
|
|
MSG_DISAMBIGUATION_LINK,
|
|
|
|
'Preview link text is correct.'
|
2018-01-11 03:23:28 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2019-01-24 14:06:21 +00:00
|
|
|
QUnit.test( 'createReferencePreview(model)', ( assert ) => {
|
|
|
|
const model = {
|
|
|
|
title: 'Custom <title>',
|
|
|
|
url: '#custom_id',
|
2019-01-24 14:31:36 +00:00
|
|
|
extract: 'Custom <i>extract</i> with a <a href="//wikipedia.de">link</a>',
|
2019-01-24 14:06:21 +00:00
|
|
|
type: previewTypes.TYPE_REFERENCE
|
|
|
|
},
|
|
|
|
preview = renderer.createPreviewWithType( model );
|
|
|
|
|
|
|
|
assert.strictEqual( preview.hasThumbnail, false );
|
|
|
|
assert.strictEqual( preview.isTall, false );
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
preview.el.find( '.mwe-popups-title' ).text().trim(),
|
|
|
|
'Custom <title>'
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
preview.el.find( '.mwe-popups-extract' ).text().trim(),
|
2019-01-24 14:31:36 +00:00
|
|
|
'Custom extract with a link'
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
preview.el.find( 'a[target="_blank"]' ).length,
|
|
|
|
// TODO: T213908
|
|
|
|
0,
|
|
|
|
'links in (and only in) the content open in new tabs'
|
2019-01-24 14:06:21 +00:00
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
preview.el.find( '.mwe-popups-read-link' ).attr( 'href' ),
|
|
|
|
'#custom_id'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2017-05-03 14:50:44 +00:00
|
|
|
QUnit.test( 'bindBehavior - preview dwell', function ( assert ) {
|
2018-03-19 19:39:41 +00:00
|
|
|
const preview = createPagePreview(),
|
2017-05-03 14:50:44 +00:00
|
|
|
behavior = createBehavior( this.sandbox );
|
|
|
|
|
|
|
|
renderer.bindBehavior( preview, behavior );
|
|
|
|
preview.el.mouseenter();
|
|
|
|
|
2018-04-24 22:03:32 +00:00
|
|
|
assert.strictEqual( behavior.previewDwell.callCount, 1, 'Preview dwell is called.' );
|
2018-01-18 18:48:16 +00:00
|
|
|
assert.notOk(
|
|
|
|
behavior.previewAbandon.called, 'Preview abandon is NOT called.' );
|
2017-05-03 14:50:44 +00:00
|
|
|
assert.notOk( behavior.click.called, 'Click is NOT called.' );
|
|
|
|
assert.notOk( behavior.showSettings.called, 'Show settings is NOT called.' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'bindBehavior - preview abandon', function ( assert ) {
|
2018-03-19 19:39:41 +00:00
|
|
|
const preview = createPagePreview(),
|
2017-05-03 14:50:44 +00:00
|
|
|
behavior = createBehavior( this.sandbox );
|
|
|
|
|
|
|
|
renderer.bindBehavior( preview, behavior );
|
|
|
|
preview.el.mouseleave();
|
|
|
|
|
|
|
|
assert.notOk( behavior.previewDwell.called, 'Preview dwell is NOT called.' );
|
2018-04-24 22:03:32 +00:00
|
|
|
assert.strictEqual( behavior.previewAbandon.callCount, 1, 'Preview abandon is called.' );
|
2017-05-03 14:50:44 +00:00
|
|
|
assert.notOk( behavior.click.called, 'Click is NOT called.' );
|
|
|
|
assert.notOk( behavior.showSettings.called, 'Show settings is NOT called.' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'bindBehavior - preview click', function ( assert ) {
|
2018-03-19 19:39:41 +00:00
|
|
|
const preview = createPagePreview(),
|
2017-05-03 14:50:44 +00:00
|
|
|
behavior = createBehavior( this.sandbox );
|
|
|
|
|
|
|
|
renderer.bindBehavior( preview, behavior );
|
|
|
|
preview.el.click();
|
|
|
|
|
|
|
|
assert.notOk( behavior.previewDwell.called, 'Preview dwell is NOT called.' );
|
2018-01-18 18:48:16 +00:00
|
|
|
assert.notOk(
|
|
|
|
behavior.previewAbandon.called, 'Preview abandon is NOT called.' );
|
2018-04-24 22:03:32 +00:00
|
|
|
assert.strictEqual( behavior.click.callCount, 1, 'Click is called.' );
|
2018-01-18 18:48:16 +00:00
|
|
|
assert.notOk( behavior.showSettings.called,
|
|
|
|
'Settings link click is NOT called.' );
|
2017-05-03 14:50:44 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'bindBehavior - settings link click', function ( assert ) {
|
2018-03-19 19:39:41 +00:00
|
|
|
const preview = createPagePreview(),
|
2017-05-03 14:50:44 +00:00
|
|
|
behavior = createBehavior( this.sandbox );
|
|
|
|
|
|
|
|
renderer.bindBehavior( preview, behavior );
|
|
|
|
preview.el.find( '.mwe-popups-settings-icon' ).click();
|
|
|
|
|
|
|
|
assert.notOk( behavior.previewDwell.called, 'Preview dwell is NOT called.' );
|
2018-01-18 18:48:16 +00:00
|
|
|
assert.notOk(
|
|
|
|
behavior.previewAbandon.called, 'Preview abandon is NOT called.' );
|
2017-05-03 14:50:44 +00:00
|
|
|
assert.notOk( behavior.click.called, 'Click is NOT called.' );
|
2018-01-18 18:48:16 +00:00
|
|
|
assert.ok(
|
|
|
|
behavior.showSettings.calledOnce, 'Settings link click is called.' );
|
2017-05-03 14:50:44 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'bindBehavior - settings link URL', function ( assert ) {
|
2018-03-19 19:39:41 +00:00
|
|
|
const preview = createPagePreview(),
|
2017-05-03 14:50:44 +00:00
|
|
|
behavior = createBehavior( this.sandbox );
|
|
|
|
|
|
|
|
renderer.bindBehavior( preview, behavior );
|
|
|
|
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-03 14:50:44 +00:00
|
|
|
preview.el.find( '.mwe-popups-settings-icon' ).attr( 'href' ),
|
|
|
|
behavior.settingsUrl,
|
|
|
|
'Settings link URL is correct.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2017-05-08 16:51:42 +00:00
|
|
|
QUnit.test( 'show', function ( assert ) {
|
2018-03-19 19:39:41 +00:00
|
|
|
const preview = createPagePreview(),
|
2017-05-08 16:51:42 +00:00
|
|
|
event = {
|
|
|
|
pageX: 252,
|
|
|
|
pageY: 1146,
|
|
|
|
clientY: 36
|
|
|
|
},
|
|
|
|
link = {
|
2018-03-14 22:04:59 +00:00
|
|
|
get() {
|
2017-05-08 16:51:42 +00:00
|
|
|
return {
|
2018-03-14 22:04:59 +00:00
|
|
|
getClientRects() {
|
2017-05-08 16:51:42 +00:00
|
|
|
return [ {
|
|
|
|
bottom: 37,
|
|
|
|
height: 13,
|
|
|
|
left: 201,
|
|
|
|
right: 357,
|
|
|
|
top: 24,
|
|
|
|
width: 156
|
|
|
|
} ];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
2018-03-14 22:04:59 +00:00
|
|
|
offset() {
|
2017-05-08 16:51:42 +00:00
|
|
|
return {
|
|
|
|
top: 1134,
|
|
|
|
left: 201
|
|
|
|
};
|
|
|
|
},
|
2018-03-14 22:04:59 +00:00
|
|
|
width() {
|
2017-05-08 16:51:42 +00:00
|
|
|
return 156;
|
|
|
|
},
|
2018-03-14 22:04:59 +00:00
|
|
|
height() {
|
2017-05-08 16:51:42 +00:00
|
|
|
return 13;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
behavior = createBehavior( this.sandbox ),
|
|
|
|
token = 'some-token',
|
2018-03-19 19:39:41 +00:00
|
|
|
$container = $( '<div>' );
|
2017-05-08 16:51:42 +00:00
|
|
|
|
|
|
|
preview.el.show = this.sandbox.stub();
|
|
|
|
|
2018-03-19 19:39:41 +00:00
|
|
|
const showPreview = renderer.show(
|
2018-04-12 01:51:42 +00:00
|
|
|
preview, event, link, behavior, token, $container.get( 0 ), 'ltr' );
|
2017-05-08 16:51:42 +00:00
|
|
|
|
|
|
|
assert.notEqual(
|
|
|
|
$container.html(),
|
|
|
|
'',
|
|
|
|
'Container is not empty.'
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
preview.el.show.calledOnce,
|
|
|
|
'Preview has been shown.'
|
|
|
|
);
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
return showPreview.then( () => {
|
2017-05-08 16:51:42 +00:00
|
|
|
assert.ok(
|
|
|
|
behavior.previewShow.calledWith( token ),
|
|
|
|
'previewShow has been called with the correct token.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'hide - fade out up', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const preview = {
|
2017-05-03 00:22:14 +00:00
|
|
|
el: $( '<div>', { 'class': 'mwe-popups-fade-in-down' } ),
|
|
|
|
hasThumbnail: false,
|
|
|
|
thumbnail: null,
|
|
|
|
isTall: false
|
|
|
|
},
|
|
|
|
$container = $( '<div>' ).append( preview.el ),
|
2017-08-22 11:28:05 +00:00
|
|
|
hidePreview = renderer.hide( preview );
|
2017-05-03 00:22:14 +00:00
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
preview.el.hasClass( 'mwe-popups-fade-out-up' ),
|
|
|
|
'Thumbnail has faded out up.'
|
|
|
|
);
|
|
|
|
assert.notOk(
|
|
|
|
preview.el.hasClass( 'mwe-popups-fade-in-down' ),
|
|
|
|
'Fade-in class has been removed.'
|
|
|
|
);
|
|
|
|
assert.notEqual(
|
|
|
|
$container.html(),
|
|
|
|
'',
|
|
|
|
'Preview is still in the container.'
|
|
|
|
);
|
2018-03-14 23:50:09 +00:00
|
|
|
return hidePreview.then( () => {
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-03 00:22:14 +00:00
|
|
|
$container.html(),
|
|
|
|
'',
|
|
|
|
'Preview has been removed from the container.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'hide - fade out down', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const preview = {
|
2017-05-03 00:22:14 +00:00
|
|
|
el: $( '<div>', { 'class': 'mwe-popups-fade-in-up' } ),
|
|
|
|
hasThumbnail: false,
|
|
|
|
thumbnail: null,
|
|
|
|
isTall: false
|
|
|
|
},
|
|
|
|
$container = $( '<div>' ).append( preview.el ),
|
2017-08-22 11:28:05 +00:00
|
|
|
hidePreview = renderer.hide( preview );
|
2017-05-03 00:22:14 +00:00
|
|
|
|
|
|
|
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.'
|
|
|
|
);
|
2018-03-14 23:50:09 +00:00
|
|
|
return hidePreview.then( () => {
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-03 00:22:14 +00:00
|
|
|
$container.html(),
|
|
|
|
'',
|
|
|
|
'Preview has been removed from the container.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( '#createLayout - portrait preview, mouse event, link is on the top left of the page', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const isPreviewTall = false,
|
2017-05-05 15:57:52 +00:00
|
|
|
eventData = {
|
|
|
|
pageX: 252,
|
|
|
|
pageY: 1146,
|
|
|
|
clientY: 36
|
|
|
|
},
|
|
|
|
linkData = {
|
|
|
|
clientRects: [ {
|
|
|
|
bottom: 37,
|
|
|
|
height: 13,
|
|
|
|
left: 201,
|
|
|
|
right: 357,
|
|
|
|
top: 24,
|
|
|
|
width: 156
|
|
|
|
} ],
|
|
|
|
offset: {
|
|
|
|
top: 1134,
|
|
|
|
left: 201
|
|
|
|
},
|
|
|
|
width: 156,
|
|
|
|
height: 13
|
|
|
|
},
|
|
|
|
windowData = {
|
|
|
|
scrollTop: 1109,
|
|
|
|
width: 1239,
|
|
|
|
height: 827
|
|
|
|
},
|
2018-04-26 13:25:55 +00:00
|
|
|
pointerSize = 8;
|
2017-05-05 15:57:52 +00:00
|
|
|
|
2018-04-12 01:51:42 +00:00
|
|
|
const cases = [ { dir: 'ltr' }, { dir: 'rtl' } ];
|
2018-05-08 19:48:17 +00:00
|
|
|
cases.forEach( ( { dir }, i ) => {
|
2018-04-12 01:51:42 +00:00
|
|
|
const layout = renderer.createLayout(
|
2018-04-26 13:25:55 +00:00
|
|
|
isPreviewTall, eventData, linkData, windowData, pointerSize, dir
|
2018-04-12 01:51:42 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
layout,
|
|
|
|
{
|
|
|
|
offset: {
|
|
|
|
top: 1154,
|
|
|
|
left: 232
|
|
|
|
},
|
|
|
|
flippedX: dir !== 'ltr',
|
|
|
|
flippedY: false,
|
|
|
|
dir
|
2017-05-05 15:57:52 +00:00
|
|
|
},
|
2018-05-08 19:48:17 +00:00
|
|
|
`Case ${i}: the layout is correct.`
|
2018-04-12 01:51:42 +00:00
|
|
|
);
|
|
|
|
} );
|
2017-05-05 15:57:52 +00:00
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( '#createLayout - tall preview, mouse event, link is on the bottom center of the page', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const isPreviewTall = true,
|
2017-05-05 15:57:52 +00:00
|
|
|
eventData = {
|
|
|
|
pageX: 176,
|
|
|
|
pageY: 1252,
|
|
|
|
clientY: 628
|
|
|
|
},
|
|
|
|
linkData = {
|
|
|
|
clientRects: [ {
|
|
|
|
bottom: 640,
|
|
|
|
height: 13,
|
|
|
|
left: 177,
|
|
|
|
right: 209,
|
|
|
|
top: 627,
|
|
|
|
width: 32
|
|
|
|
} ],
|
|
|
|
offset: {
|
|
|
|
top: 1250,
|
|
|
|
left: 177
|
|
|
|
},
|
|
|
|
width: 32,
|
|
|
|
height: 13
|
|
|
|
},
|
|
|
|
windowData = {
|
|
|
|
scrollTop: 623,
|
|
|
|
width: 587,
|
|
|
|
height: 827
|
|
|
|
},
|
2018-04-26 13:25:55 +00:00
|
|
|
pointerSize = 8;
|
2017-05-05 15:57:52 +00:00
|
|
|
|
2018-04-12 01:51:42 +00:00
|
|
|
const cases = [ { dir: 'ltr' }, { dir: 'rtl' } ];
|
2018-05-08 19:48:17 +00:00
|
|
|
cases.forEach( ( { dir }, i ) => {
|
2018-04-12 01:51:42 +00:00
|
|
|
const layout = renderer.createLayout(
|
2018-04-26 13:25:55 +00:00
|
|
|
isPreviewTall, eventData, linkData, windowData, pointerSize, dir
|
2018-04-12 01:51:42 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
layout,
|
|
|
|
{
|
|
|
|
offset: {
|
|
|
|
top: 1242,
|
|
|
|
left: 156
|
|
|
|
},
|
|
|
|
flippedX: dir !== 'ltr',
|
|
|
|
flippedY: true,
|
|
|
|
dir
|
2017-05-05 15:57:52 +00:00
|
|
|
},
|
2018-05-08 19:48:17 +00:00
|
|
|
`Case ${i}: the layout is correct. Y is flipped.`
|
2018-04-12 01:51:42 +00:00
|
|
|
);
|
|
|
|
} );
|
2017-05-05 15:57:52 +00:00
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( '#createLayout - empty preview, keyboard event, link is on the center right of the page', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const isPreviewTall = false,
|
2017-05-05 15:57:52 +00:00
|
|
|
eventData = {},
|
|
|
|
linkData = {
|
|
|
|
clientRects: [ {
|
|
|
|
bottom: 442,
|
|
|
|
height: 13,
|
|
|
|
left: 654,
|
|
|
|
right: 692,
|
|
|
|
top: 430,
|
|
|
|
width: 38
|
|
|
|
} ],
|
|
|
|
offset: {
|
|
|
|
top: 1118,
|
|
|
|
left: 654
|
|
|
|
},
|
|
|
|
width: 38,
|
|
|
|
height: 13
|
|
|
|
},
|
|
|
|
windowData = {
|
|
|
|
scrollTop: 689,
|
|
|
|
width: 801,
|
|
|
|
height: 827
|
|
|
|
},
|
2018-04-26 13:25:55 +00:00
|
|
|
pointerSize = 8;
|
2017-05-05 15:57:52 +00:00
|
|
|
|
2018-04-12 01:51:42 +00:00
|
|
|
const cases = [ { dir: 'ltr' }, { dir: 'rtl' } ];
|
2018-05-08 19:48:17 +00:00
|
|
|
cases.forEach( ( { dir }, i ) => {
|
2018-04-12 01:51:42 +00:00
|
|
|
const layout = renderer.createLayout(
|
2018-04-26 13:25:55 +00:00
|
|
|
isPreviewTall, eventData, linkData, windowData, pointerSize, dir
|
2018-04-12 01:51:42 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
layout,
|
|
|
|
{
|
|
|
|
offset: {
|
|
|
|
top: 1110,
|
|
|
|
left: 372
|
|
|
|
},
|
|
|
|
flippedX: dir === 'ltr',
|
|
|
|
flippedY: true,
|
|
|
|
dir
|
2017-05-05 15:57:52 +00:00
|
|
|
},
|
2018-05-08 19:48:17 +00:00
|
|
|
`Case ${i}: the layout is correct. Both X and Y are flipped.`
|
2018-04-12 01:51:42 +00:00
|
|
|
);
|
|
|
|
} );
|
2017-05-05 15:57:52 +00:00
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( '#getClasses when no thumbnail is available', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const cases = [
|
2017-05-01 16:39:30 +00:00
|
|
|
// [ previewOptions, layoutOptions, expected, message ]
|
|
|
|
[
|
|
|
|
{
|
|
|
|
hasThumbnail: false,
|
|
|
|
isTall: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
flippedX: false,
|
|
|
|
flippedY: false
|
|
|
|
},
|
|
|
|
[
|
|
|
|
'mwe-popups-fade-in-up',
|
2018-04-26 13:25:55 +00:00
|
|
|
'mwe-popups-no-image-pointer',
|
2017-05-01 16:39:30 +00:00
|
|
|
'mwe-popups-is-not-tall'
|
|
|
|
],
|
|
|
|
'No flip.'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
hasThumbnail: false,
|
|
|
|
isTall: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
flippedX: false,
|
|
|
|
flippedY: true
|
|
|
|
},
|
|
|
|
[
|
|
|
|
'mwe-popups-fade-in-down',
|
2018-04-23 21:23:17 +00:00
|
|
|
'flipped-y',
|
2017-05-01 16:39:30 +00:00
|
|
|
'mwe-popups-is-not-tall'
|
|
|
|
],
|
|
|
|
'Y flipped.'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
hasThumbnail: false,
|
|
|
|
isTall: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
flippedX: true,
|
|
|
|
flippedY: false
|
|
|
|
},
|
|
|
|
[
|
|
|
|
'mwe-popups-fade-in-up',
|
2018-04-23 21:23:17 +00:00
|
|
|
'flipped-x',
|
2018-04-26 13:25:55 +00:00
|
|
|
'mwe-popups-no-image-pointer',
|
2017-05-01 16:39:30 +00:00
|
|
|
'mwe-popups-is-not-tall'
|
|
|
|
],
|
|
|
|
'X flipped.'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
hasThumbnail: false,
|
|
|
|
isTall: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
flippedX: true,
|
|
|
|
flippedY: true
|
|
|
|
},
|
|
|
|
[
|
|
|
|
'mwe-popups-fade-in-down',
|
2018-04-23 21:23:17 +00:00
|
|
|
'flipped-x-y',
|
2017-05-01 16:39:30 +00:00
|
|
|
'mwe-popups-is-not-tall'
|
|
|
|
],
|
|
|
|
'X and Y flipped.'
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
cases.forEach( ( case_ ) => {
|
2017-05-01 16:39:30 +00:00
|
|
|
assert.deepEqual(
|
|
|
|
renderer.getClasses( case_[ 0 ], case_[ 1 ] ),
|
|
|
|
case_[ 2 ],
|
|
|
|
case_[ 3 ]
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( '#getClasses when a non-tall thumbnail is available', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const cases = [
|
2017-05-01 16:39:30 +00:00
|
|
|
[
|
|
|
|
{
|
|
|
|
hasThumbnail: true,
|
|
|
|
isTall: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
flippedX: false,
|
|
|
|
flippedY: false
|
|
|
|
},
|
|
|
|
[
|
|
|
|
'mwe-popups-fade-in-up',
|
2018-04-26 13:25:55 +00:00
|
|
|
'mwe-popups-image-pointer',
|
2017-05-01 16:39:30 +00:00
|
|
|
'mwe-popups-is-not-tall'
|
|
|
|
],
|
|
|
|
'No flip.'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
hasThumbnail: true,
|
|
|
|
isTall: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
flippedX: false,
|
|
|
|
flippedY: true
|
|
|
|
},
|
|
|
|
[
|
|
|
|
'mwe-popups-fade-in-down',
|
2018-04-23 21:23:17 +00:00
|
|
|
'flipped-y',
|
2017-05-01 16:39:30 +00:00
|
|
|
'mwe-popups-is-not-tall'
|
|
|
|
],
|
|
|
|
'Y flipped.'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
hasThumbnail: true,
|
|
|
|
isTall: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
flippedX: true,
|
|
|
|
flippedY: false
|
|
|
|
},
|
|
|
|
[
|
|
|
|
'mwe-popups-fade-in-up',
|
2018-04-23 21:23:17 +00:00
|
|
|
'flipped-x',
|
2018-04-26 13:25:55 +00:00
|
|
|
'mwe-popups-image-pointer',
|
2017-05-01 16:39:30 +00:00
|
|
|
'mwe-popups-is-not-tall'
|
|
|
|
],
|
|
|
|
'X flipped.'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
hasThumbnail: true,
|
|
|
|
isTall: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
flippedX: true,
|
|
|
|
flippedY: true
|
|
|
|
},
|
|
|
|
[
|
|
|
|
'mwe-popups-fade-in-down',
|
2018-04-23 21:23:17 +00:00
|
|
|
'flipped-x-y',
|
2017-05-01 16:39:30 +00:00
|
|
|
'mwe-popups-is-not-tall'
|
|
|
|
],
|
|
|
|
'X and Y flipped.'
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
cases.forEach( ( case_ ) => {
|
2017-05-01 16:39:30 +00:00
|
|
|
assert.deepEqual(
|
|
|
|
renderer.getClasses( case_[ 0 ], case_[ 1 ] ),
|
|
|
|
case_[ 2 ],
|
|
|
|
case_[ 3 ]
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( '#getClasses when a tall thumbnail is available', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const cases = [
|
2017-05-01 16:39:30 +00:00
|
|
|
[
|
|
|
|
{
|
|
|
|
hasThumbnail: true,
|
|
|
|
isTall: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
flippedX: false,
|
|
|
|
flippedY: false
|
|
|
|
},
|
|
|
|
[
|
|
|
|
'mwe-popups-fade-in-up',
|
2018-04-26 13:25:55 +00:00
|
|
|
'mwe-popups-no-image-pointer',
|
2017-05-01 16:39:30 +00:00
|
|
|
'mwe-popups-is-tall'
|
|
|
|
],
|
|
|
|
'No flip.'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
hasThumbnail: true,
|
|
|
|
isTall: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
flippedX: false,
|
|
|
|
flippedY: true
|
|
|
|
},
|
|
|
|
[
|
|
|
|
'mwe-popups-fade-in-down',
|
2018-04-23 21:23:17 +00:00
|
|
|
'flipped-y',
|
2017-05-01 16:39:30 +00:00
|
|
|
'mwe-popups-is-tall'
|
|
|
|
],
|
|
|
|
'Y flipped.'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
hasThumbnail: true,
|
|
|
|
isTall: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
flippedX: true,
|
|
|
|
flippedY: false
|
|
|
|
},
|
|
|
|
[
|
|
|
|
'mwe-popups-fade-in-up',
|
2018-04-23 21:23:17 +00:00
|
|
|
'flipped-x',
|
2017-05-01 16:39:30 +00:00
|
|
|
'mwe-popups-is-tall'
|
|
|
|
],
|
|
|
|
'X flipped.'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
hasThumbnail: true,
|
|
|
|
isTall: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
flippedX: true,
|
|
|
|
flippedY: true
|
|
|
|
},
|
|
|
|
[
|
|
|
|
'mwe-popups-fade-in-down',
|
2018-04-23 21:23:17 +00:00
|
|
|
'flipped-x-y',
|
2017-05-01 16:39:30 +00:00
|
|
|
'mwe-popups-is-tall'
|
|
|
|
],
|
|
|
|
'X and Y flipped.'
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
cases.forEach( ( case_ ) => {
|
2017-05-01 16:39:30 +00:00
|
|
|
assert.deepEqual(
|
|
|
|
renderer.getClasses( case_[ 0 ], case_[ 1 ] ),
|
|
|
|
case_[ 2 ],
|
|
|
|
case_[ 3 ]
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( '#layoutPreview - no thumbnail', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const preview = createPagePreview( false, false, null ),
|
2017-05-05 19:36:04 +00:00
|
|
|
layout = {
|
|
|
|
flippedX: false,
|
|
|
|
flippedY: false,
|
|
|
|
offset: {
|
|
|
|
top: 100,
|
|
|
|
left: 200
|
2018-04-12 01:51:42 +00:00
|
|
|
},
|
|
|
|
dir: 'ltr'
|
2017-05-05 19:36:04 +00:00
|
|
|
},
|
|
|
|
classes = [ 'some-class', 'another-class' ];
|
|
|
|
|
|
|
|
renderer.layoutPreview( preview, layout, classes, 200, 8 );
|
|
|
|
|
|
|
|
assert.ok(
|
2018-09-13 13:09:43 +00:00
|
|
|
classes.every( function ( c ) {
|
|
|
|
return preview.el.hasClass( c );
|
|
|
|
} ),
|
2017-05-05 19:36:04 +00:00
|
|
|
'Classes have been added.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-05 19:36:04 +00:00
|
|
|
preview.el.css( 'top' ),
|
2018-03-20 17:01:18 +00:00
|
|
|
`${ layout.offset.top }px`,
|
2017-05-05 19:36:04 +00:00
|
|
|
'Top is correct.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-05 19:36:04 +00:00
|
|
|
preview.el.css( 'left' ),
|
2018-03-20 17:01:18 +00:00
|
|
|
`${ layout.offset.left }px`,
|
2017-05-05 19:36:04 +00:00
|
|
|
'Left is correct.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-04-12 01:51:42 +00:00
|
|
|
QUnit.test( '#layoutPreview - tall preview, flipped X, has thumbnail', function ( assert ) {
|
2018-03-19 19:39:41 +00:00
|
|
|
const preview = createPagePreview( true, true, { height: 200 } ),
|
2017-05-05 19:36:04 +00:00
|
|
|
layout = {
|
|
|
|
flippedX: true,
|
|
|
|
flippedY: false,
|
|
|
|
offset: {
|
|
|
|
top: 100,
|
|
|
|
left: 200
|
2018-04-12 01:51:42 +00:00
|
|
|
},
|
|
|
|
dir: 'ltr'
|
2017-05-05 19:36:04 +00:00
|
|
|
},
|
|
|
|
classes = [ 'some-class', 'another-class' ];
|
|
|
|
|
2018-04-12 01:51:42 +00:00
|
|
|
this.sandbox
|
|
|
|
.stub( document, 'getElementById' )
|
|
|
|
.returns( document.createElement( 'div' ) );
|
|
|
|
|
2017-05-05 19:36:04 +00:00
|
|
|
renderer.layoutPreview( preview, layout, classes, 200, 8 );
|
|
|
|
|
|
|
|
assert.ok(
|
2018-09-13 13:09:43 +00:00
|
|
|
classes.every( function ( c ) {
|
|
|
|
return preview.el.hasClass( c );
|
|
|
|
} ),
|
2017-05-05 19:36:04 +00:00
|
|
|
'Classes have been added.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-05 19:36:04 +00:00
|
|
|
preview.el.css( 'top' ),
|
2018-03-20 17:01:18 +00:00
|
|
|
`${ layout.offset.top }px`,
|
2017-05-05 19:36:04 +00:00
|
|
|
'Top is correct.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-05 19:36:04 +00:00
|
|
|
preview.el.css( 'left' ),
|
2018-03-20 17:01:18 +00:00
|
|
|
`${ layout.offset.left }px`,
|
2017-05-05 19:36:04 +00:00
|
|
|
'Left is correct.'
|
|
|
|
);
|
|
|
|
assert.notOk(
|
2018-04-26 13:25:55 +00:00
|
|
|
preview.el.hasClass( 'mwe-popups-no-image-pointer' ),
|
2017-05-05 19:36:04 +00:00
|
|
|
'A class has been removed.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-05 19:36:04 +00:00
|
|
|
preview.el.find( 'image' ).attr( 'clip-path' ),
|
|
|
|
'url(#mwe-popups-landscape-mask)',
|
|
|
|
'Image clip path is correct.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-04-12 01:51:42 +00:00
|
|
|
QUnit.test( '#layoutPreview - portrait preview, flipped X, has thumbnail, small height', function ( assert ) {
|
2018-03-19 19:39:41 +00:00
|
|
|
const preview = createPagePreview( false, true, { height: 199 } ),
|
2017-05-05 19:36:04 +00:00
|
|
|
layout = {
|
|
|
|
flippedX: true,
|
|
|
|
flippedY: false,
|
|
|
|
offset: {
|
|
|
|
top: 100,
|
|
|
|
left: 200
|
2018-04-12 01:51:42 +00:00
|
|
|
},
|
|
|
|
dir: 'ltr'
|
2017-05-05 19:36:04 +00:00
|
|
|
},
|
|
|
|
classes = [ 'some-class', 'another-class' ];
|
|
|
|
|
2018-04-12 01:51:42 +00:00
|
|
|
this.sandbox
|
|
|
|
.stub( document, 'getElementById' )
|
|
|
|
.returns( document.createElement( 'div' ) );
|
|
|
|
|
2017-05-05 19:36:04 +00:00
|
|
|
renderer.layoutPreview( preview, layout, classes, 200, 8 );
|
|
|
|
|
|
|
|
assert.ok(
|
2018-09-13 13:09:43 +00:00
|
|
|
classes.every( function ( c ) {
|
|
|
|
return preview.el.hasClass( c );
|
|
|
|
} ),
|
2017-05-05 19:36:04 +00:00
|
|
|
'Classes have been added.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-05 19:36:04 +00:00
|
|
|
preview.el.css( 'top' ),
|
2018-03-20 17:01:18 +00:00
|
|
|
`${ layout.offset.top }px`,
|
2017-05-05 19:36:04 +00:00
|
|
|
'Top is correct.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-05 19:36:04 +00:00
|
|
|
preview.el.css( 'left' ),
|
2018-03-20 17:01:18 +00:00
|
|
|
`${ layout.offset.left }px`,
|
2017-05-05 19:36:04 +00:00
|
|
|
'Left is correct.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-05 19:36:04 +00:00
|
|
|
preview.el.find( '.mwe-popups-extract' ).css( 'margin-top' ),
|
2018-04-26 13:25:55 +00:00
|
|
|
`${ 199 - 8 }px`, // thumb height - pointer size
|
2017-05-05 19:36:04 +00:00
|
|
|
'Extract margin top has been set when preview height is smaller than the predefined landscape image height.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-05 19:36:04 +00:00
|
|
|
preview.el.find( 'image' ).attr( 'clip-path' ),
|
|
|
|
'url(#mwe-popups-mask-flip)',
|
|
|
|
'Image clip path is correct.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-04-12 01:51:42 +00:00
|
|
|
QUnit.test( '#layoutPreview - portrait preview, flipped X, has thumbnail, big height', function ( assert ) {
|
2018-03-19 19:39:41 +00:00
|
|
|
const preview = createPagePreview( false, true, { height: 201 } ),
|
2017-05-05 19:36:04 +00:00
|
|
|
layout = {
|
|
|
|
flippedX: true,
|
|
|
|
flippedY: false,
|
|
|
|
offset: {
|
|
|
|
top: 100,
|
|
|
|
left: 200
|
2018-04-12 01:51:42 +00:00
|
|
|
},
|
|
|
|
dir: 'ltr'
|
2017-05-05 19:36:04 +00:00
|
|
|
},
|
|
|
|
classes = [ 'some-class', 'another-class' ];
|
|
|
|
|
2018-04-12 01:51:42 +00:00
|
|
|
this.sandbox
|
|
|
|
.stub( document, 'getElementById' )
|
|
|
|
.returns( document.createElement( 'div' ) );
|
|
|
|
|
2017-05-05 19:36:04 +00:00
|
|
|
renderer.layoutPreview( preview, layout, classes, 200, 8 );
|
|
|
|
|
|
|
|
assert.ok(
|
2018-09-13 13:09:43 +00:00
|
|
|
classes.every( function ( c ) {
|
|
|
|
return preview.el.hasClass( c );
|
|
|
|
} ),
|
2017-05-05 19:36:04 +00:00
|
|
|
'Classes have been added.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-05 19:36:04 +00:00
|
|
|
preview.el.css( 'top' ),
|
2018-03-20 17:01:18 +00:00
|
|
|
`${ layout.offset.top }px`,
|
2017-05-05 19:36:04 +00:00
|
|
|
'Top is correct.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-05 19:36:04 +00:00
|
|
|
preview.el.css( 'left' ),
|
2018-03-20 17:01:18 +00:00
|
|
|
`${ layout.offset.left }px`,
|
2017-05-05 19:36:04 +00:00
|
|
|
'Left is correct.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-05 19:36:04 +00:00
|
|
|
preview.el.find( '.mwe-popups-extract' ).attr( 'margin-top' ),
|
|
|
|
undefined,
|
|
|
|
'Extract margin top has NOT been set when preview height is bigger than the predefined landscape image height.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-05 19:36:04 +00:00
|
|
|
preview.el.find( 'image' ).attr( 'clip-path' ),
|
|
|
|
'url(#mwe-popups-mask-flip)',
|
|
|
|
'Image clip path is correct.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( '#layoutPreview - tall preview, has thumbnail, flipped Y', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const preview = createPagePreview( true, true, { height: 200 } ),
|
2017-05-05 19:36:04 +00:00
|
|
|
layout = {
|
|
|
|
flippedX: false,
|
|
|
|
flippedY: true,
|
|
|
|
offset: {
|
|
|
|
top: 100,
|
|
|
|
left: 200
|
2018-04-12 01:51:42 +00:00
|
|
|
},
|
|
|
|
dir: 'ltr'
|
2017-05-05 19:36:04 +00:00
|
|
|
},
|
|
|
|
classes = [ 'some-class', 'another-class' ];
|
|
|
|
|
2018-04-12 01:51:42 +00:00
|
|
|
preview.el.outerHeight = () => 20;
|
2017-05-05 19:36:04 +00:00
|
|
|
|
|
|
|
renderer.layoutPreview( preview, layout, classes, 200, 8 );
|
|
|
|
|
|
|
|
assert.ok(
|
2018-09-13 13:09:43 +00:00
|
|
|
classes.every( function ( c ) {
|
|
|
|
return preview.el.hasClass( c );
|
|
|
|
} ),
|
2017-05-05 19:36:04 +00:00
|
|
|
'Classes have been added.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-05 19:36:04 +00:00
|
|
|
preview.el.css( 'top' ),
|
2018-03-20 17:01:18 +00:00
|
|
|
`${ layout.offset.top - 20 }px`, // - outer height
|
2017-05-05 19:36:04 +00:00
|
|
|
'Top is correct.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-05 19:36:04 +00:00
|
|
|
preview.el.css( 'left' ),
|
2018-03-20 17:01:18 +00:00
|
|
|
`${ layout.offset.left }px`,
|
2017-05-05 19:36:04 +00:00
|
|
|
'Left is correct.'
|
|
|
|
);
|
|
|
|
assert.notOk(
|
|
|
|
preview.el.find( 'image' ).attr( 'clip-path' ),
|
|
|
|
'Image clip path is not set.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-04-12 01:51:42 +00:00
|
|
|
QUnit.test( '#layoutPreview - tall preview, has thumbnail, flipped X and Y', function ( assert ) {
|
2018-03-19 19:39:41 +00:00
|
|
|
const preview = createPagePreview( true, true, { height: 200 } ),
|
2017-05-05 19:36:04 +00:00
|
|
|
layout = {
|
|
|
|
flippedX: true,
|
|
|
|
flippedY: true,
|
|
|
|
offset: {
|
|
|
|
top: 100,
|
|
|
|
left: 200
|
2018-04-12 01:51:42 +00:00
|
|
|
},
|
|
|
|
dir: 'ltr'
|
2017-05-05 19:36:04 +00:00
|
|
|
},
|
|
|
|
classes = [ 'some-class', 'another-class' ];
|
|
|
|
|
2018-04-12 01:51:42 +00:00
|
|
|
preview.el.outerHeight = () => 20;
|
|
|
|
|
|
|
|
this.sandbox
|
|
|
|
.stub( document, 'getElementById' )
|
|
|
|
.returns( document.createElement( 'div' ) );
|
2017-05-05 19:36:04 +00:00
|
|
|
|
|
|
|
renderer.layoutPreview( preview, layout, classes, 200, 8 );
|
|
|
|
|
|
|
|
assert.ok(
|
2018-09-13 13:09:43 +00:00
|
|
|
classes.every( function ( c ) {
|
|
|
|
return preview.el.hasClass( c );
|
|
|
|
} ),
|
2017-05-05 19:36:04 +00:00
|
|
|
'Classes have been added.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-05 19:36:04 +00:00
|
|
|
preview.el.css( 'top' ),
|
2018-03-20 17:01:18 +00:00
|
|
|
`${ layout.offset.top - 20 }px`, // - outer height
|
2017-05-05 19:36:04 +00:00
|
|
|
'Top is correct.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-05 19:36:04 +00:00
|
|
|
preview.el.css( 'left' ),
|
2018-03-20 17:01:18 +00:00
|
|
|
`${ layout.offset.left }px`,
|
2017-05-05 19:36:04 +00:00
|
|
|
'Left is correct.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-05 19:36:04 +00:00
|
|
|
preview.el.find( 'image' ).attr( 'clip-path' ),
|
|
|
|
'url(#mwe-popups-landscape-mask-flip)',
|
|
|
|
'Image clip path is not set.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( '#layoutPreview - portrait preview, has thumbnail, flipped X and Y', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const preview = createPagePreview( false, true, { height: 200 } ),
|
2017-05-05 19:36:04 +00:00
|
|
|
layout = {
|
|
|
|
flippedX: true,
|
|
|
|
flippedY: true,
|
|
|
|
offset: {
|
|
|
|
top: 100,
|
|
|
|
left: 200
|
2018-04-12 01:51:42 +00:00
|
|
|
},
|
|
|
|
dir: 'ltr'
|
2017-05-05 19:36:04 +00:00
|
|
|
},
|
|
|
|
classes = [ 'some-class', 'another-class' ];
|
|
|
|
|
2018-04-12 01:51:42 +00:00
|
|
|
preview.el.outerHeight = () => 20;
|
2017-05-05 19:36:04 +00:00
|
|
|
|
|
|
|
renderer.layoutPreview( preview, layout, classes, 200, 8 );
|
|
|
|
|
|
|
|
assert.ok(
|
2018-09-13 13:09:43 +00:00
|
|
|
classes.every( function ( c ) {
|
|
|
|
return preview.el.hasClass( c );
|
|
|
|
} ),
|
2017-05-05 19:36:04 +00:00
|
|
|
'Classes have been added.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-05 19:36:04 +00:00
|
|
|
preview.el.css( 'top' ),
|
2018-03-20 17:01:18 +00:00
|
|
|
`${ layout.offset.top - 20 }px`, // - outer height
|
2017-05-05 19:36:04 +00:00
|
|
|
'Top is correct.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2017-05-05 19:36:04 +00:00
|
|
|
preview.el.css( 'left' ),
|
2018-03-20 17:01:18 +00:00
|
|
|
`${ layout.offset.left }px`,
|
2017-05-05 19:36:04 +00:00
|
|
|
'Left is correct.'
|
|
|
|
);
|
|
|
|
assert.notOk(
|
|
|
|
preview.el.find( 'image' ).attr( 'clip-path' ),
|
|
|
|
'Image clip path is not set.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-04-12 01:51:42 +00:00
|
|
|
QUnit.test( '#setThumbnailClipPath', function ( assert ) {
|
|
|
|
const cases = [
|
|
|
|
{ isTall: false, dir: 'ltr', expected: 'matrix(1 0 0 1 0 0)' },
|
|
|
|
{ isTall: true, dir: 'ltr', expected: 'matrix(1 0 0 1 0 0)' },
|
|
|
|
{ isTall: false, dir: 'rtl', expected: 'matrix(-1 0 0 1 320 0)' },
|
|
|
|
{ isTall: true, dir: 'rtl', expected: 'matrix(-1 0 0 1 203 0)' }
|
|
|
|
];
|
|
|
|
|
|
|
|
const clipPath = document.createElement( 'div' );
|
|
|
|
this.sandbox.stub( document, 'getElementById' ).returns( clipPath );
|
|
|
|
|
|
|
|
cases.forEach( ( { isTall, dir, expected } ) => {
|
|
|
|
clipPath.removeAttribute( 'transform' );
|
|
|
|
const preview = createPagePreview( isTall, true, { height: 200 } ),
|
|
|
|
layout = {
|
|
|
|
flippedX: true,
|
|
|
|
flippedY: false,
|
|
|
|
offset: {
|
|
|
|
top: 100,
|
|
|
|
left: 200
|
|
|
|
},
|
|
|
|
dir
|
|
|
|
};
|
|
|
|
|
|
|
|
// preview.el.outerHeight = () => 20;
|
|
|
|
|
|
|
|
renderer.setThumbnailClipPath( preview, layout );
|
|
|
|
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2018-04-12 01:51:42 +00:00
|
|
|
clipPath.getAttribute( 'transform' ),
|
|
|
|
expected,
|
|
|
|
`Transform is correct for: { isTall: ${isTall}, dir: ${dir} }.`
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( '#getThumbnailClipPathID', ( assert ) => {
|
|
|
|
const cases = [
|
|
|
|
{ flippedY: false, flippedX: false, isTall: false, expected: 'mwe-popups-mask' },
|
|
|
|
{ flippedY: true, flippedX: false, isTall: false, expected: undefined },
|
|
|
|
{ flippedY: false, flippedX: true, isTall: false, expected: 'mwe-popups-mask-flip' },
|
|
|
|
{ flippedY: true, flippedX: true, isTall: false, expected: undefined },
|
|
|
|
{ flippedY: false, flippedX: false, isTall: true, expected: undefined },
|
|
|
|
{ flippedY: true, flippedX: false, isTall: true, expected: undefined },
|
|
|
|
{ flippedY: false, flippedX: true, isTall: true, expected: 'mwe-popups-landscape-mask' },
|
|
|
|
{ flippedY: true, flippedX: true, isTall: true, expected: 'mwe-popups-landscape-mask-flip' }
|
|
|
|
];
|
|
|
|
cases.forEach( ( { flippedY, flippedX, isTall, expected } ) => {
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2018-04-12 01:51:42 +00:00
|
|
|
renderer.getThumbnailClipPathID( isTall, flippedY, flippedX ),
|
|
|
|
expected,
|
|
|
|
`Correct element ID is returned for: { flippedY: ${flippedY}, flippedX: ${flippedX}, isTall: ${isTall} }.`
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'getClosestYPosition', ( assert ) => {
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual( renderer.getClosestYPosition( 100, [
|
2017-04-27 16:03:44 +00:00
|
|
|
{
|
|
|
|
top: 99,
|
|
|
|
bottom: 119
|
|
|
|
},
|
|
|
|
{
|
|
|
|
top: 120,
|
|
|
|
bottom: 140
|
|
|
|
}
|
|
|
|
] ), 119, 'Correct lower Y.' );
|
|
|
|
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual( renderer.getClosestYPosition( 100, [
|
2017-04-27 16:03:44 +00:00
|
|
|
{
|
|
|
|
top: 99,
|
|
|
|
bottom: 119
|
|
|
|
},
|
|
|
|
{
|
|
|
|
top: 120,
|
|
|
|
bottom: 140
|
|
|
|
}
|
|
|
|
], true ), 99, 'Correct upper Y.' );
|
|
|
|
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual( renderer.getClosestYPosition( 135, [
|
2017-04-27 16:03:44 +00:00
|
|
|
{
|
|
|
|
top: 99,
|
|
|
|
bottom: 119
|
|
|
|
},
|
|
|
|
{
|
|
|
|
top: 120,
|
|
|
|
bottom: 140
|
|
|
|
}
|
|
|
|
], true ), 120, 'Correct upper Y 2.' );
|
|
|
|
} );
|