2017-07-28 17:32:46 +00:00
|
|
|
import * as renderer from '../../../src/ui/renderer';
|
2019-02-08 17:21:30 +00:00
|
|
|
import * as pagePreview from '../../../src/ui/templates/pagePreview/pagePreview';
|
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
|
|
|
|
2020-11-24 14:33:42 +00:00
|
|
|
const windowHeight = 400;
|
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 {
|
2019-02-01 11:48:18 +00:00
|
|
|
el: $( '<div>' ).append(
|
|
|
|
hasThumbnail ? $( '<image>' ) : '',
|
|
|
|
$( '<a>' ).addClass( 'mwe-popups-extract' ).text( 'extract' ),
|
2023-07-07 17:59:15 +00:00
|
|
|
$( '<a>' ).addClass( 'mwe-popups-settings-button' )
|
2023-05-12 21:12:16 +00:00
|
|
|
)[ 0 ],
|
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
|
|
|
|
2024-01-11 09:43:59 +00:00
|
|
|
mw.msg = ( key ) => `<${ key }>`;
|
2021-05-07 10:09:32 +00:00
|
|
|
mw.message = ( key ) => {
|
2024-01-11 09:43:59 +00:00
|
|
|
return { exists: () => !key.endsWith( 'generic' ), text: () => `<${ key }>` };
|
2021-05-07 10:09:32 +00:00
|
|
|
};
|
2017-05-02 20:09:54 +00:00
|
|
|
|
2019-10-17 08:51:49 +00:00
|
|
|
mw.html = {
|
2019-01-28 07:54:49 +00:00
|
|
|
escape: ( str ) => str && str.replace( /'/g, ''' ).replace( /</g, '<' )
|
|
|
|
};
|
2018-04-12 01:51:42 +00:00
|
|
|
|
2019-10-17 08:51:49 +00:00
|
|
|
mw.track = () => {};
|
2019-09-23 15:26:58 +00:00
|
|
|
|
|
|
|
global.navigator = {
|
|
|
|
sendBeacon() {}
|
|
|
|
};
|
|
|
|
|
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;
|
2019-10-17 08:51:49 +00:00
|
|
|
mw.msg = null;
|
2021-05-07 10:09:32 +00:00
|
|
|
mw.message = null;
|
2019-10-17 08:51:49 +00:00
|
|
|
mw.html = null;
|
2022-07-12 22:48:46 +00:00
|
|
|
renderer.test.reset();
|
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
|
2024-01-11 09:43:59 +00:00
|
|
|
}, `${ pagePreview.defaultExtractWidth + 10 }px` ],
|
2018-06-26 20:47:10 +00:00
|
|
|
[ {
|
|
|
|
// Fall back to css stylesheet for non-narrow thumbs.
|
|
|
|
isNarrow: false, offset: 100
|
|
|
|
}, '' ]
|
|
|
|
];
|
|
|
|
|
|
|
|
cases.forEach( ( case_, i ) => {
|
|
|
|
assert.strictEqual(
|
2019-02-08 17:21:30 +00:00
|
|
|
pagePreview.getExtractWidth( case_[ 0 ] ),
|
2018-06-26 20:47:10 +00:00
|
|
|
case_[ 1 ],
|
2024-01-11 09:43:59 +00:00
|
|
|
`Case ${ i }: the expected extract width matches.`
|
2018-06-26 20:47:10 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
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 = [
|
2019-02-13 22:23:00 +00:00
|
|
|
[ '#mwe-popups-mask', 'M0 8h10l8-8 8 8h974v992H0z' ],
|
|
|
|
[ '#mwe-popups-mask-flip', 'M0 8h294l8-8 8 8h690v992H0z' ],
|
|
|
|
[ '#mwe-popups-landscape-mask', 'M0 8h174l8-8 8 8h810v992H0z' ],
|
|
|
|
[ '#mwe-popups-landscape-mask-flip', 'M0 0h1000v242H190l-8 8-8-8H0z' ]
|
2017-04-27 19:55:43 +00:00
|
|
|
];
|
|
|
|
|
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(
|
2024-01-11 09:43:59 +00:00
|
|
|
$container.find( `${ case_[ 0 ] } path` ).attr( 'd' ),
|
2018-05-08 19:48:17 +00:00
|
|
|
case_[ 1 ],
|
2024-01-11 09:43:59 +00:00
|
|
|
`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 ) => {
|
2022-07-12 22:48:46 +00:00
|
|
|
renderer.registerPreviewUI(
|
|
|
|
previewTypes.TYPE_PAGE,
|
|
|
|
renderer.createPagePreview
|
|
|
|
);
|
2018-03-19 19:39:41 +00:00
|
|
|
const model = {
|
2017-05-02 21:30:30 +00:00
|
|
|
title: 'Test',
|
2019-01-28 08:07:26 +00:00
|
|
|
url: 'https://en.wikipedia.org/wiki/Test <"\'>',
|
|
|
|
languageCode: 'en <"\'>',
|
|
|
|
languageDirection: 'ltr <"\'>',
|
2017-05-02 21:30:30 +00:00
|
|
|
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(
|
2023-05-12 21:01:23 +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(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).find( '.mwe-popups-extract' ).text(),
|
2017-05-02 21:30:30 +00:00
|
|
|
'This is a test page.',
|
|
|
|
'Preview extract is correct.'
|
|
|
|
);
|
2019-01-28 08:07:26 +00:00
|
|
|
|
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).find( '.mwe-popups-extract' ).attr( 'href' ),
|
2019-01-28 08:07:26 +00:00
|
|
|
'https://en.wikipedia.org/wiki/Test <"\'>',
|
|
|
|
'URL is safely espaced'
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).find( '.mwe-popups-extract' ).attr( 'lang' ),
|
2019-01-28 08:07:26 +00:00
|
|
|
'en <"\'>',
|
|
|
|
'Language code is safely espaced'
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).find( '.mwe-popups-extract' ).attr( 'dir' ),
|
2019-01-28 08:07:26 +00:00
|
|
|
'ltr <"\'>',
|
|
|
|
'Language direction is safely espaced'
|
|
|
|
);
|
2021-03-31 02:22:42 +00:00
|
|
|
assert.strictEqual(
|
2023-07-07 17:59:15 +00:00
|
|
|
$( preview.el ).find( '.mwe-popups-settings-button' ).attr( 'title' ),
|
2021-03-31 02:22:42 +00:00
|
|
|
'<popups-settings-icon-gear-title>',
|
|
|
|
'Title attribute is correct.'
|
|
|
|
);
|
2017-05-02 21:30:30 +00:00
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'createEmptyPreview(model)', ( assert ) => {
|
2022-07-12 22:48:46 +00:00
|
|
|
renderer.registerPreviewUI(
|
|
|
|
previewTypes.TYPE_GENERIC,
|
|
|
|
renderer.createEmptyPreview
|
|
|
|
);
|
2018-03-19 19:39:41 +00:00
|
|
|
const model = {
|
2017-05-02 20:09:54 +00:00
|
|
|
title: 'Test',
|
2019-01-28 08:07:26 +00:00
|
|
|
url: 'https://en.wikipedia.org/wiki/Test <"\'>',
|
2019-01-28 09:17:07 +00:00
|
|
|
type: previewTypes.TYPE_GENERIC
|
2017-05-02 20:09:54 +00:00
|
|
|
},
|
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(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( emptyPreview.el ).find( '.mwe-popups-title' ).text().trim(),
|
2023-08-15 18:19:56 +00:00
|
|
|
'<popups-preview-no-preview>',
|
2018-03-13 22:03:49 +00:00
|
|
|
'Empty preview title is hidden.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2023-08-15 18:19:56 +00:00
|
|
|
$( emptyPreview.el ).find( '.mwe-popups-message' ).length,
|
|
|
|
0,
|
|
|
|
'No preview message text.'
|
2018-03-13 22:03:49 +00:00
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( emptyPreview.el ).find( '.mwe-popups-read-link' ).text().trim(),
|
2019-01-29 10:38:50 +00:00
|
|
|
'<popups-preview-footer-read>',
|
2018-03-13 22:03:49 +00:00
|
|
|
'Empty preview link text is correct.'
|
2017-05-02 20:09:54 +00:00
|
|
|
);
|
2019-01-28 08:07:26 +00:00
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( emptyPreview.el ).find( '.mwe-popups-read-link' ).attr( 'href' ),
|
2019-01-28 08:07:26 +00:00
|
|
|
'https://en.wikipedia.org/wiki/Test <"\'>',
|
|
|
|
'URL is safely espaced'
|
|
|
|
);
|
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(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( emptyPreview.el ).find( '.mwe-popups-title' ).text().trim(),
|
2023-08-15 18:19:56 +00:00
|
|
|
'<popups-preview-no-preview>',
|
2018-03-13 22:03:49 +00:00
|
|
|
'Empty preview title is hidden.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2023-08-15 18:19:56 +00:00
|
|
|
$( emptyPreview.el ).find( '.mwe-popups-message' ).length,
|
|
|
|
0,
|
|
|
|
'No preview message text.'
|
2018-03-13 22:03:49 +00:00
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( emptyPreview.el ).find( '.mwe-popups-read-link' ).text().trim(),
|
2019-01-29 10:38:50 +00:00
|
|
|
'<popups-preview-footer-read>',
|
2018-03-13 22:03:49 +00:00
|
|
|
'Empty preview link text is correct.'
|
2018-03-07 11:10:53 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2019-01-28 08:07:26 +00:00
|
|
|
QUnit.test( 'createPreviewWithType(model with unknown type)', ( assert ) => {
|
|
|
|
const model = {
|
|
|
|
url: '/wiki/Unknown <"\'>',
|
2023-05-12 23:12:48 +00:00
|
|
|
type: 'unknown'
|
2019-01-28 08:07:26 +00:00
|
|
|
},
|
|
|
|
emptyPreview = renderer.createPreviewWithType( model );
|
|
|
|
|
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( emptyPreview.el ).find( '.mwe-popups-extract' ).attr( 'href' ),
|
2019-01-28 08:07:26 +00:00
|
|
|
'/wiki/Unknown <"\'>',
|
|
|
|
'URL is safely espaced'
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( emptyPreview.el ).attr( 'class' ),
|
2023-05-12 23:12:48 +00:00
|
|
|
'mwe-popups mwe-popups-type-unknown',
|
2019-01-28 08:07:26 +00:00
|
|
|
'Popup type is safely espaced'
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
2023-08-15 18:19:56 +00:00
|
|
|
$( emptyPreview.el ).find( '.popups-icon' ).attr( 'class' ),
|
2023-09-01 16:24:11 +00:00
|
|
|
'popups-icon popups-icon--preview-unknown',
|
2019-01-28 08:07:26 +00:00
|
|
|
'Icon type is safely espaced'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'createDisambiguationPreview(model)', ( assert ) => {
|
2022-07-12 22:48:46 +00:00
|
|
|
renderer.registerPreviewUI(
|
|
|
|
previewTypes.TYPE_DISAMBIGUATION,
|
|
|
|
renderer.createDisambiguationPreview
|
|
|
|
);
|
2018-03-19 19:39:41 +00:00
|
|
|
const model = {
|
2018-03-07 11:10:53 +00:00
|
|
|
title: 'Barack (disambiguation)',
|
2019-01-28 08:07:26 +00:00
|
|
|
url: 'url/Barack (disambiguation) <"\'>',
|
2018-03-07 11:10:53 +00:00
|
|
|
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(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).find( '.mwe-popups-title' ).text().trim(),
|
2018-03-13 22:03:49 +00:00
|
|
|
'Barack (disambiguation)',
|
|
|
|
'Preview title is show.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2023-08-15 18:19:56 +00:00
|
|
|
$( preview.el ).find( '.mwe-popups-message' ).text().trim(),
|
2019-01-29 10:38:50 +00:00
|
|
|
'<popups-preview-disambiguation>',
|
2023-08-15 18:19:56 +00:00
|
|
|
'Preview message is correct.'
|
2018-03-13 22:03:49 +00:00
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).find( '.mwe-popups-read-link' ).text().trim(),
|
2019-01-29 10:38:50 +00:00
|
|
|
'<popups-preview-disambiguation-link>',
|
2018-03-13 22:03:49 +00:00
|
|
|
'Preview link text is correct.'
|
2018-01-11 03:23:28 +00:00
|
|
|
);
|
2019-01-28 08:07:26 +00:00
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).find( '.mwe-popups-read-link' ).attr( 'href' ),
|
2019-01-28 08:07:26 +00:00
|
|
|
'url/Barack (disambiguation) <"\'>',
|
|
|
|
'URL is safely espaced'
|
|
|
|
);
|
2018-01-11 03:23:28 +00:00
|
|
|
} );
|
|
|
|
|
2019-01-24 14:06:21 +00:00
|
|
|
QUnit.test( 'createReferencePreview(model)', ( assert ) => {
|
2022-07-12 22:48:46 +00:00
|
|
|
renderer.registerPreviewUI(
|
|
|
|
previewTypes.TYPE_REFERENCE,
|
|
|
|
renderer.createReferencePreview
|
|
|
|
);
|
2019-01-24 14:06:21 +00:00
|
|
|
const model = {
|
2019-03-22 16:21:16 +00:00
|
|
|
url: '#custom_id',
|
2019-11-26 13:19:35 +00:00
|
|
|
extract: 'Custom <i>extract</i> with an <a href="/wiki/Internal">internal</a> and an <a href="//wikipedia.de" class="external">external</a> link',
|
2019-02-16 09:13:23 +00:00
|
|
|
type: previewTypes.TYPE_REFERENCE,
|
|
|
|
referenceType: 'web'
|
2019-01-24 14:06:21 +00:00
|
|
|
},
|
|
|
|
preview = renderer.createPreviewWithType( model );
|
|
|
|
|
|
|
|
assert.strictEqual( preview.hasThumbnail, false );
|
|
|
|
assert.strictEqual( preview.isTall, false );
|
|
|
|
|
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).find( '.mwe-popups-title' ).text().trim(),
|
2019-02-16 09:13:23 +00:00
|
|
|
'<popups-refpreview-web>'
|
2019-01-24 14:06:21 +00:00
|
|
|
);
|
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).find( '.mw-parser-output' ).text().trim(),
|
2019-11-26 13:19:35 +00:00
|
|
|
'Custom extract with an internal and an external link'
|
2019-01-24 14:31:36 +00:00
|
|
|
);
|
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).find( 'a[target="_blank"]' ).length,
|
2019-01-24 13:48:18 +00:00
|
|
|
1,
|
2019-11-26 13:19:35 +00:00
|
|
|
'only external links open in new tabs'
|
2019-01-24 14:06:21 +00:00
|
|
|
);
|
2019-03-22 16:21:16 +00:00
|
|
|
} );
|
|
|
|
|
2020-10-25 18:22:09 +00:00
|
|
|
QUnit.test( 'createReferencePreview collapsible/sortable handling', ( assert ) => {
|
2022-07-12 22:48:46 +00:00
|
|
|
renderer.registerPreviewUI(
|
|
|
|
previewTypes.TYPE_REFERENCE,
|
|
|
|
renderer.createReferencePreview
|
|
|
|
);
|
2020-10-25 18:22:09 +00:00
|
|
|
const model = {
|
|
|
|
url: '',
|
|
|
|
extract: '<table class="mw-collapsible"></table>' +
|
|
|
|
'<table class="sortable"><th class="headerSort" tabindex="1" title="Click here"></th></table>',
|
|
|
|
type: previewTypes.TYPE_REFERENCE
|
|
|
|
},
|
|
|
|
preview = renderer.createPreviewWithType( model );
|
|
|
|
|
2023-05-12 21:12:16 +00:00
|
|
|
assert.strictEqual( $( preview.el ).find( '.mw-collapsible, .sortable, .headerSort' ).length, 0 );
|
|
|
|
assert.strictEqual( $( preview.el ).find( 'th' ).attr( 'tabindex' ), undefined );
|
|
|
|
assert.strictEqual( $( preview.el ).find( 'th' ).attr( 'title' ), undefined );
|
2020-10-25 18:22:09 +00:00
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).find( '.mwe-collapsible-placeholder' ).text(),
|
2020-10-25 18:22:09 +00:00
|
|
|
'<popups-refpreview-collapsible-placeholder>'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2019-01-24 18:24:36 +00:00
|
|
|
QUnit.test( 'createReferencePreview default title', ( assert ) => {
|
2022-07-12 22:48:46 +00:00
|
|
|
renderer.registerPreviewUI(
|
|
|
|
previewTypes.TYPE_REFERENCE,
|
|
|
|
renderer.createReferencePreview
|
|
|
|
);
|
2019-01-24 18:24:36 +00:00
|
|
|
const model = {
|
|
|
|
url: '',
|
|
|
|
extract: '',
|
|
|
|
type: previewTypes.TYPE_REFERENCE
|
|
|
|
},
|
|
|
|
preview = renderer.createPreviewWithType( model );
|
|
|
|
|
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).find( '.mwe-popups-title' ).text().trim(),
|
2019-03-12 16:23:46 +00:00
|
|
|
'<popups-refpreview-reference>'
|
2019-01-24 18:24:36 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2019-03-26 15:54:17 +00:00
|
|
|
QUnit.test( 'createReferencePreview updates fade-out effect on scroll', ( assert ) => {
|
2022-07-12 22:48:46 +00:00
|
|
|
renderer.registerPreviewUI(
|
|
|
|
previewTypes.TYPE_REFERENCE,
|
|
|
|
renderer.createReferencePreview
|
|
|
|
);
|
2019-03-26 15:54:17 +00:00
|
|
|
const model = {
|
|
|
|
url: '',
|
|
|
|
extract: '',
|
|
|
|
type: previewTypes.TYPE_REFERENCE
|
|
|
|
},
|
|
|
|
preview = renderer.createPreviewWithType( model ),
|
2023-05-12 21:12:16 +00:00
|
|
|
$extract = $( preview.el ).find( '.mwe-popups-extract' );
|
2019-03-26 15:54:17 +00:00
|
|
|
|
2023-05-12 21:12:16 +00:00
|
|
|
$extract.children()[ 0 ].dispatchEvent( new Event( 'scroll' ) );
|
2019-03-26 15:54:17 +00:00
|
|
|
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.false( $extract.children()[ 0 ].isScrolling );
|
|
|
|
assert.false( $extract.hasClass( 'mwe-popups-fade-out' ) );
|
2019-03-26 15:54:17 +00:00
|
|
|
} );
|
|
|
|
|
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 );
|
2023-05-12 21:12:16 +00:00
|
|
|
preview.el.dispatchEvent( new Event( 'mouseenter' ) );
|
2017-05-03 14:50:44 +00:00
|
|
|
|
2018-04-24 22:03:32 +00:00
|
|
|
assert.strictEqual( behavior.previewDwell.callCount, 1, 'Preview dwell is called.' );
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.false(
|
2018-01-18 18:48:16 +00:00
|
|
|
behavior.previewAbandon.called, 'Preview abandon is NOT called.' );
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.false( behavior.click.called, 'Click is NOT called.' );
|
|
|
|
assert.false( behavior.showSettings.called, 'Show settings is NOT called.' );
|
2017-05-03 14:50:44 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
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 );
|
2023-05-12 21:12:16 +00:00
|
|
|
preview.el.dispatchEvent( new Event( 'mouseleave' ) );
|
2017-05-03 14:50:44 +00:00
|
|
|
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.false( 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.' );
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.false( behavior.click.called, 'Click is NOT called.' );
|
|
|
|
assert.false( behavior.showSettings.called, 'Show settings is NOT called.' );
|
2017-05-03 14:50:44 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
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 );
|
2023-05-12 21:12:16 +00:00
|
|
|
preview.el.dispatchEvent( new Event( 'click' ) );
|
2017-05-03 14:50:44 +00:00
|
|
|
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.false( behavior.previewDwell.called, 'Preview dwell is NOT called.' );
|
|
|
|
assert.false(
|
2018-01-18 18:48:16 +00:00
|
|
|
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.' );
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.false( behavior.showSettings.called,
|
2018-01-18 18:48:16 +00:00
|
|
|
'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 );
|
2023-07-07 17:59:15 +00:00
|
|
|
preview.el.querySelector( '.mwe-popups-settings-button' ).dispatchEvent( new Event( 'click' ) );
|
2017-05-03 14:50:44 +00:00
|
|
|
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.false( behavior.previewDwell.called, 'Preview dwell is NOT called.' );
|
|
|
|
assert.false(
|
2018-01-18 18:48:16 +00:00
|
|
|
behavior.previewAbandon.called, 'Preview abandon is NOT called.' );
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.false( behavior.click.called, 'Click is NOT called.' );
|
|
|
|
assert.true(
|
2018-01-18 18:48:16 +00:00
|
|
|
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(
|
2023-07-07 17:59:15 +00:00
|
|
|
$( preview.el ).find( '.mwe-popups-settings-button' ).attr( 'href' ),
|
2017-05-03 14:50:44 +00:00
|
|
|
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(),
|
2020-11-24 14:33:42 +00:00
|
|
|
measures = {
|
2017-05-08 16:51:42 +00:00
|
|
|
pageX: 252,
|
|
|
|
pageY: 1146,
|
2020-11-24 14:33:42 +00:00
|
|
|
clientY: 36,
|
|
|
|
clientRects: [ {
|
|
|
|
bottom: 37,
|
|
|
|
height: 13,
|
|
|
|
left: 201,
|
|
|
|
right: 357,
|
|
|
|
top: 24,
|
|
|
|
width: 156
|
|
|
|
} ],
|
|
|
|
offset: { top: 1134, left: 201 },
|
|
|
|
width: 156,
|
|
|
|
height: 13,
|
|
|
|
scrollTop: 0,
|
|
|
|
windowWidth: 800,
|
|
|
|
windowHeight: 600
|
2017-05-08 16:51:42 +00:00
|
|
|
},
|
|
|
|
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
|
|
|
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).show = this.sandbox.stub();
|
2017-05-08 16:51:42 +00:00
|
|
|
|
2018-03-19 19:39:41 +00:00
|
|
|
const showPreview = renderer.show(
|
2020-11-24 14:33:42 +00:00
|
|
|
preview, measures, {}, behavior, token, $container.get( 0 ), 'ltr' );
|
2017-05-08 16:51:42 +00:00
|
|
|
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.notStrictEqual(
|
2017-05-08 16:51:42 +00:00
|
|
|
$container.html(),
|
|
|
|
'',
|
|
|
|
'Container is not empty.'
|
|
|
|
);
|
2023-05-12 21:12:16 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
preview.el.style.display,
|
|
|
|
'block',
|
2017-05-08 16:51:42 +00:00
|
|
|
'Preview has been shown.'
|
|
|
|
);
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
return showPreview.then( () => {
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.true(
|
2017-05-08 16:51:42 +00:00
|
|
|
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 = {
|
2023-05-12 21:12:16 +00:00
|
|
|
el: $( '<div>' ).addClass( 'mwe-popups-fade-in-down' )[ 0 ],
|
2017-05-03 00:22:14 +00:00
|
|
|
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
|
|
|
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.true(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).hasClass( 'mwe-popups-fade-out-up' ),
|
2017-05-03 00:22:14 +00:00
|
|
|
'Thumbnail has faded out up.'
|
|
|
|
);
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.false(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).hasClass( 'mwe-popups-fade-in-down' ),
|
2017-05-03 00:22:14 +00:00
|
|
|
'Fade-in class has been removed.'
|
|
|
|
);
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.notStrictEqual(
|
2017-05-03 00:22:14 +00:00
|
|
|
$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 = {
|
2023-05-12 21:12:16 +00:00
|
|
|
el: $( '<div>' ).addClass( 'mwe-popups-fade-in-up' )[ 0 ],
|
2017-05-03 00:22:14 +00:00
|
|
|
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
|
|
|
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.true(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).hasClass( 'mwe-popups-fade-out-down' ),
|
2017-05-03 00:22:14 +00:00
|
|
|
'Thumbnail has faded out down.'
|
|
|
|
);
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.false(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).hasClass( 'mwe-popups-fade-in-up' ),
|
2017-05-03 00:22:14 +00:00
|
|
|
'Fade-in class has been removed.'
|
|
|
|
);
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.notStrictEqual(
|
2017-05-03 00:22:14 +00:00
|
|
|
$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,
|
2020-11-24 14:33:42 +00:00
|
|
|
measures = {
|
2017-05-05 15:57:52 +00:00
|
|
|
pageX: 252,
|
|
|
|
pageY: 1146,
|
2020-11-24 14:33:42 +00:00
|
|
|
clientY: 36,
|
2017-05-05 15:57:52 +00:00
|
|
|
clientRects: [ {
|
|
|
|
bottom: 37,
|
|
|
|
height: 13,
|
|
|
|
left: 201,
|
|
|
|
right: 357,
|
|
|
|
top: 24,
|
|
|
|
width: 156
|
|
|
|
} ],
|
|
|
|
offset: {
|
|
|
|
top: 1134,
|
|
|
|
left: 201
|
|
|
|
},
|
|
|
|
width: 156,
|
2020-11-24 14:33:42 +00:00
|
|
|
height: 13,
|
2017-05-05 15:57:52 +00:00
|
|
|
scrollTop: 1109,
|
2020-11-24 14:33:42 +00:00
|
|
|
windowWidth: 1239,
|
|
|
|
windowHeight: 827
|
2017-05-05 15:57:52 +00:00
|
|
|
},
|
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(
|
2020-11-24 14:33:42 +00:00
|
|
|
isPreviewTall, measures, pointerSize, dir
|
2018-04-12 01:51:42 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
layout,
|
|
|
|
{
|
|
|
|
offset: {
|
|
|
|
top: 1154,
|
2019-03-15 12:40:38 +00:00
|
|
|
left: 234
|
2018-04-12 01:51:42 +00:00
|
|
|
},
|
|
|
|
flippedX: dir !== 'ltr',
|
|
|
|
flippedY: false,
|
|
|
|
dir
|
2017-05-05 15:57:52 +00:00
|
|
|
},
|
2024-01-11 09:43:59 +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,
|
2020-11-24 14:33:42 +00:00
|
|
|
measures = {
|
2017-05-05 15:57:52 +00:00
|
|
|
pageX: 176,
|
|
|
|
pageY: 1252,
|
2020-11-24 14:33:42 +00:00
|
|
|
clientY: 628,
|
2017-05-05 15:57:52 +00:00
|
|
|
clientRects: [ {
|
|
|
|
bottom: 640,
|
|
|
|
height: 13,
|
|
|
|
left: 177,
|
|
|
|
right: 209,
|
|
|
|
top: 627,
|
|
|
|
width: 32
|
|
|
|
} ],
|
|
|
|
offset: {
|
|
|
|
top: 1250,
|
|
|
|
left: 177
|
|
|
|
},
|
|
|
|
width: 32,
|
2020-11-24 14:33:42 +00:00
|
|
|
height: 13,
|
2017-05-05 15:57:52 +00:00
|
|
|
scrollTop: 623,
|
2020-11-24 14:33:42 +00:00
|
|
|
windowWidth: 587,
|
|
|
|
windowHeight: 827
|
2017-05-05 15:57:52 +00:00
|
|
|
},
|
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(
|
2020-11-24 14:33:42 +00:00
|
|
|
isPreviewTall, measures, pointerSize, dir
|
2018-04-12 01:51:42 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
layout,
|
|
|
|
{
|
|
|
|
offset: {
|
|
|
|
top: 1242,
|
2019-03-15 12:40:38 +00:00
|
|
|
left: 158
|
2018-04-12 01:51:42 +00:00
|
|
|
},
|
|
|
|
flippedX: dir !== 'ltr',
|
|
|
|
flippedY: true,
|
|
|
|
dir
|
2017-05-05 15:57:52 +00:00
|
|
|
},
|
2024-01-11 09:43:59 +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,
|
2020-11-24 14:33:42 +00:00
|
|
|
measures = {
|
2017-05-05 15:57:52 +00:00
|
|
|
clientRects: [ {
|
|
|
|
bottom: 442,
|
|
|
|
height: 13,
|
|
|
|
left: 654,
|
|
|
|
right: 692,
|
|
|
|
top: 430,
|
|
|
|
width: 38
|
|
|
|
} ],
|
|
|
|
offset: {
|
|
|
|
top: 1118,
|
|
|
|
left: 654
|
|
|
|
},
|
|
|
|
width: 38,
|
2020-11-24 14:33:42 +00:00
|
|
|
height: 13,
|
2017-05-05 15:57:52 +00:00
|
|
|
scrollTop: 689,
|
2020-11-24 14:33:42 +00:00
|
|
|
windowWidth: 801,
|
|
|
|
windowHeight: 827
|
2017-05-05 15:57:52 +00:00
|
|
|
},
|
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(
|
2020-11-24 14:33:42 +00:00
|
|
|
isPreviewTall, measures, 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
|
|
|
},
|
2024-01-11 09:43:59 +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
|
|
|
} );
|
|
|
|
|
2019-03-15 12:40:38 +00:00
|
|
|
QUnit.test( '#createLayout - empty preview, mouse event, popup pointer is in the correct position', ( assert ) => {
|
|
|
|
const isPreviewTall = false,
|
2020-11-24 14:33:42 +00:00
|
|
|
measures = {
|
2019-03-15 12:40:38 +00:00
|
|
|
pageX: 205,
|
|
|
|
pageY: 1146,
|
2020-11-24 14:33:42 +00:00
|
|
|
clientY: 36,
|
2019-03-15 12:40:38 +00:00
|
|
|
clientRects: [ {
|
|
|
|
bottom: 37,
|
|
|
|
height: 13,
|
|
|
|
left: 201,
|
|
|
|
right: 227,
|
|
|
|
top: 24,
|
|
|
|
width: 26
|
|
|
|
} ],
|
|
|
|
offset: {
|
|
|
|
top: 1134,
|
|
|
|
left: 201
|
|
|
|
},
|
|
|
|
width: 26,
|
2020-11-24 14:33:42 +00:00
|
|
|
height: 13,
|
2019-03-15 12:40:38 +00:00
|
|
|
scrollTop: 1109,
|
2020-11-24 14:33:42 +00:00
|
|
|
windowWidth: 1239,
|
|
|
|
windowHeight: 827
|
2019-03-15 12:40:38 +00:00
|
|
|
},
|
|
|
|
pointerSize = 8;
|
|
|
|
|
|
|
|
const cases = [ { dir: 'ltr' }, { dir: 'rtl' } ];
|
|
|
|
cases.forEach( ( { dir }, i ) => {
|
|
|
|
const layout = renderer.createLayout(
|
2020-11-24 14:33:42 +00:00
|
|
|
isPreviewTall, measures, pointerSize, dir
|
2019-03-15 12:40:38 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
layout,
|
|
|
|
{
|
|
|
|
offset: {
|
|
|
|
top: 1154,
|
|
|
|
left: 196
|
|
|
|
},
|
|
|
|
flippedX: dir !== 'ltr',
|
|
|
|
flippedY: false,
|
|
|
|
dir
|
|
|
|
},
|
2024-01-11 09:43:59 +00:00
|
|
|
`Case ${ i }: the layout is correct.`
|
2019-03-15 12:40:38 +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',
|
2021-08-04 20:33:54 +00:00
|
|
|
'mwe-popups-no-image-pointer',
|
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',
|
2021-08-04 20:33:54 +00:00
|
|
|
'mwe-popups-no-image-pointer',
|
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',
|
2021-08-04 20:33:54 +00:00
|
|
|
'mwe-popups-no-image-pointer',
|
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',
|
2021-08-04 20:33:54 +00:00
|
|
|
'mwe-popups-no-image-pointer',
|
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',
|
2021-08-04 20:33:54 +00:00
|
|
|
'mwe-popups-no-image-pointer',
|
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',
|
2021-08-04 20:33:54 +00:00
|
|
|
'mwe-popups-image-pointer',
|
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',
|
2021-08-04 20:33:54 +00:00
|
|
|
'mwe-popups-image-pointer',
|
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' ];
|
|
|
|
|
2020-11-24 14:33:42 +00:00
|
|
|
renderer.layoutPreview( preview, layout, classes, 200, 8, windowHeight );
|
2017-05-05 19:36:04 +00:00
|
|
|
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.true(
|
2023-05-12 21:12:16 +00:00
|
|
|
classes.every( ( c ) => $( preview.el ).hasClass( c ) ),
|
2017-05-05 19:36:04 +00:00
|
|
|
'Classes have been added.'
|
|
|
|
);
|
2023-05-12 21:12:16 +00:00
|
|
|
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).css( 'top' ),
|
2024-01-11 09:43:59 +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(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).css( 'left' ),
|
2024-01-11 09:43:59 +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' ) );
|
|
|
|
|
2020-11-24 14:33:42 +00:00
|
|
|
renderer.layoutPreview( preview, layout, classes, 200, 8, windowHeight );
|
2017-05-05 19:36:04 +00:00
|
|
|
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.true(
|
2023-05-12 21:12:16 +00:00
|
|
|
classes.every( ( c ) => $( 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(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).css( 'top' ),
|
2024-01-11 09:43:59 +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(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).css( 'left' ),
|
2024-01-11 09:43:59 +00:00
|
|
|
`${ layout.offset.left }px`,
|
2017-05-05 19:36:04 +00:00
|
|
|
'Left is correct.'
|
|
|
|
);
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.false(
|
2023-05-12 21:12:16 +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(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).find( 'image' ).attr( 'clip-path' ),
|
2017-05-05 19:36:04 +00:00
|
|
|
'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' ) );
|
|
|
|
|
2020-11-24 14:33:42 +00:00
|
|
|
renderer.layoutPreview( preview, layout, classes, 200, 8, windowHeight );
|
2017-05-05 19:36:04 +00:00
|
|
|
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.true(
|
2023-05-12 21:12:16 +00:00
|
|
|
classes.every( ( c ) => $( 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(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).css( 'top' ),
|
2024-01-11 09:43:59 +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(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).css( 'left' ),
|
2024-01-11 09:43:59 +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(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).find( '.mwe-popups-extract' ).css( 'margin-top' ),
|
2024-01-11 09:43:59 +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(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).find( 'image' ).attr( 'clip-path' ),
|
2017-05-05 19:36:04 +00:00
|
|
|
'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' ) );
|
|
|
|
|
2020-11-24 14:33:42 +00:00
|
|
|
renderer.layoutPreview( preview, layout, classes, 200, 8, windowHeight );
|
2017-05-05 19:36:04 +00:00
|
|
|
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.true(
|
2023-05-12 21:12:16 +00:00
|
|
|
classes.every( ( c ) => $( 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(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).css( 'top' ),
|
2024-01-11 09:43:59 +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(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).css( 'left' ),
|
2024-01-11 09:43:59 +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(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).find( '.mwe-popups-extract' ).attr( 'margin-top' ),
|
2017-05-05 19:36:04 +00:00
|
|
|
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(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).find( 'image' ).attr( 'clip-path' ),
|
2017-05-05 19:36:04 +00:00
|
|
|
'url(#mwe-popups-mask-flip)',
|
|
|
|
'Image clip path is correct.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2021-08-04 20:33:54 +00:00
|
|
|
QUnit.test( '#hasPointerOnImage', ( assert ) => {
|
|
|
|
const cases = [
|
|
|
|
{
|
|
|
|
preview: {
|
|
|
|
hasThumbnail: false
|
|
|
|
},
|
|
|
|
layout: {},
|
|
|
|
expected: false,
|
|
|
|
reason: 'If no thumbnails no chance pointer will be on image'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
preview: {
|
|
|
|
isTall: true,
|
|
|
|
hasThumbnail: true
|
|
|
|
},
|
|
|
|
layout: {
|
|
|
|
flippedX: false,
|
|
|
|
flippedY: false
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
reason: '(landscape) Pointer on left, image on right'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
preview: {
|
|
|
|
isTall: true,
|
|
|
|
hasThumbnail: true
|
|
|
|
},
|
|
|
|
layout: {
|
|
|
|
flippedX: false,
|
|
|
|
flippedY: true
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
reason: '(landscape) Pointer on left, image on right'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
preview: {
|
|
|
|
isTall: true,
|
|
|
|
hasThumbnail: true
|
|
|
|
},
|
|
|
|
layout: {
|
|
|
|
flippedX: true,
|
|
|
|
flippedY: true
|
|
|
|
},
|
|
|
|
expected: true,
|
|
|
|
reason: '(landscape) Pointer on bottom right, image on right'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
preview: {
|
|
|
|
isTall: false,
|
|
|
|
hasThumbnail: true
|
|
|
|
},
|
|
|
|
layout: {
|
|
|
|
flippedX: false,
|
|
|
|
flippedY: false
|
|
|
|
},
|
|
|
|
expected: true,
|
|
|
|
reason: '(portrait) Pointer on top left, image on top'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
preview: {
|
|
|
|
isTall: false,
|
|
|
|
hasThumbnail: true
|
|
|
|
},
|
|
|
|
layout: {
|
|
|
|
flippedX: true,
|
|
|
|
flippedY: false
|
|
|
|
},
|
|
|
|
expected: true,
|
|
|
|
reason: '(portrait) Pointer on top right, image on top'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
preview: {
|
|
|
|
isTall: false,
|
|
|
|
hasThumbnail: true
|
|
|
|
},
|
|
|
|
layout: {
|
|
|
|
flippedX: false,
|
|
|
|
flippedY: true
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
reason: '(portrait) Pointer on bottom left, image on top'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
preview: {
|
|
|
|
isTall: false,
|
|
|
|
hasThumbnail: true
|
|
|
|
},
|
|
|
|
layout: {
|
|
|
|
flippedX: true,
|
|
|
|
flippedY: true
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
reason: '(portrait) Pointer on bottom right, image on top'
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
preview: {
|
|
|
|
isTall: true,
|
|
|
|
hasThumbnail: true
|
|
|
|
},
|
|
|
|
layout: {
|
|
|
|
flippedX: true,
|
|
|
|
flippedY: false
|
|
|
|
},
|
|
|
|
expected: true,
|
|
|
|
reason: '(landscape) Pointer on top right, image on right'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
cases.forEach( ( testCase ) => {
|
|
|
|
assert.strictEqual(
|
|
|
|
renderer.hasPointerOnImage( testCase.preview, testCase.layout ),
|
|
|
|
testCase.expected,
|
|
|
|
testCase.reason
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
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' ];
|
|
|
|
|
2020-11-24 14:33:42 +00:00
|
|
|
renderer.layoutPreview( preview, layout, classes, 200, 8, windowHeight );
|
2017-05-05 19:36:04 +00:00
|
|
|
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.true(
|
2023-05-12 21:12:16 +00:00
|
|
|
classes.every( ( c ) => $( preview.el ).hasClass( c ) ),
|
2017-05-05 19:36:04 +00:00
|
|
|
'Classes have been added.'
|
|
|
|
);
|
2020-11-24 14:33:42 +00:00
|
|
|
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).css( 'bottom' ),
|
2024-01-11 09:43:59 +00:00
|
|
|
`${ windowHeight - layout.offset.top }px`,
|
2020-11-24 14:33:42 +00:00
|
|
|
'Bottom is correct.'
|
2017-05-05 19:36:04 +00:00
|
|
|
);
|
2020-11-24 14:33:42 +00:00
|
|
|
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).css( 'left' ),
|
2024-01-11 09:43:59 +00:00
|
|
|
`${ layout.offset.left }px`,
|
2017-05-05 19:36:04 +00:00
|
|
|
'Left is correct.'
|
|
|
|
);
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).find( 'image' ).attr( 'clip-path' ),
|
2022-02-09 15:09:19 +00:00
|
|
|
undefined,
|
2017-05-05 19:36:04 +00:00
|
|
|
'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
|
|
|
this.sandbox
|
|
|
|
.stub( document, 'getElementById' )
|
|
|
|
.returns( document.createElement( 'div' ) );
|
2017-05-05 19:36:04 +00:00
|
|
|
|
2020-11-24 14:33:42 +00:00
|
|
|
renderer.layoutPreview( preview, layout, classes, 200, 8, windowHeight );
|
2017-05-05 19:36:04 +00:00
|
|
|
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.true(
|
2023-05-12 21:12:16 +00:00
|
|
|
classes.every( ( c ) => $( 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(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).css( 'left' ),
|
2024-01-11 09:43:59 +00:00
|
|
|
`${ layout.offset.left }px`,
|
2017-05-05 19:36:04 +00:00
|
|
|
'Left is correct.'
|
|
|
|
);
|
2020-11-24 14:33:42 +00:00
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).css( 'bottom' ),
|
2024-01-11 09:43:59 +00:00
|
|
|
`${ windowHeight - layout.offset.top }px`,
|
2020-11-24 14:33:42 +00:00
|
|
|
'Bottom is correct.'
|
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).find( 'image' ).attr( 'clip-path' ),
|
2017-05-05 19:36:04 +00:00
|
|
|
'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' ];
|
|
|
|
|
2020-11-24 14:33:42 +00:00
|
|
|
renderer.layoutPreview( preview, layout, classes, 200, 8, windowHeight );
|
2017-05-05 19:36:04 +00:00
|
|
|
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.true(
|
2023-05-12 21:12:16 +00:00
|
|
|
classes.every( ( c ) => $( 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(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).css( 'left' ),
|
2024-01-11 09:43:59 +00:00
|
|
|
`${ layout.offset.left }px`,
|
2017-05-05 19:36:04 +00:00
|
|
|
'Left is correct.'
|
|
|
|
);
|
2020-11-24 14:33:42 +00:00
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).css( 'bottom' ),
|
2024-01-11 09:43:59 +00:00
|
|
|
`${ windowHeight - layout.offset.top }px`,
|
2020-11-24 14:33:42 +00:00
|
|
|
'Bottom is correct.'
|
|
|
|
);
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.strictEqual(
|
2023-05-12 21:12:16 +00:00
|
|
|
$( preview.el ).find( 'image' ).attr( 'clip-path' ),
|
2022-02-09 15:09:19 +00:00
|
|
|
undefined,
|
2017-05-05 19:36:04 +00:00
|
|
|
'Image clip path is not set.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-04-12 01:51:42 +00:00
|
|
|
QUnit.test( '#setThumbnailClipPath', function ( assert ) {
|
|
|
|
const cases = [
|
2019-03-14 13:15:19 +00:00
|
|
|
// standard thumbnail sizes
|
|
|
|
{ isTall: false, dir: 'ltr', thumbnail: { height: 200, width: 320 }, expected: 'matrix(1 0 0 1 0 0)' },
|
|
|
|
{ isTall: true, dir: 'ltr', thumbnail: { height: 200, width: 320 }, expected: 'matrix(1 0 0 1 0 0)' },
|
|
|
|
{ isTall: false, dir: 'rtl', thumbnail: { height: 200, width: 320 }, expected: 'matrix(-1 0 0 1 320 0)' },
|
|
|
|
{ isTall: true, dir: 'rtl', thumbnail: { height: 200, width: 302 }, expected: 'matrix(-1 0 0 1 203 0)' },
|
|
|
|
// portrait-mode thumbnail, wider than max width - mask should not shift
|
|
|
|
{ isTall: true, dir: 'ltr', thumbnail: { height: 200, width: 400 }, expected: 'matrix(1 0 0 1 0 0)' },
|
|
|
|
// portrait-mode thumbnail, narrower than max width - mask x-offset should shift
|
|
|
|
{ isTall: true, dir: 'ltr', thumbnail: { height: 200, width: 100 }, expected: 'matrix(1 0 0 1 -103 0)' },
|
|
|
|
// in RTL-mode, wide/narrow thumbnails - mask should not shift
|
|
|
|
{ isTall: true, dir: 'rtl', thumbnail: { height: 200, width: 400 }, expected: 'matrix(-1 0 0 1 203 0)' },
|
|
|
|
{ isTall: true, dir: 'rtl', thumbnail: { height: 200, width: 100 }, expected: 'matrix(-1 0 0 1 203 0)' }
|
2018-04-12 01:51:42 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
const clipPath = document.createElement( 'div' );
|
|
|
|
this.sandbox.stub( document, 'getElementById' ).returns( clipPath );
|
|
|
|
|
2019-03-14 13:15:19 +00:00
|
|
|
cases.forEach( ( { isTall, dir, thumbnail, expected } ) => {
|
2018-04-12 01:51:42 +00:00
|
|
|
clipPath.removeAttribute( 'transform' );
|
2019-03-14 13:15:19 +00:00
|
|
|
const preview = createPagePreview( isTall, true, thumbnail ),
|
2018-04-12 01:51:42 +00:00
|
|
|
layout = {
|
|
|
|
flippedX: true,
|
|
|
|
flippedY: false,
|
|
|
|
offset: {
|
|
|
|
top: 100,
|
|
|
|
left: 200
|
|
|
|
},
|
|
|
|
dir
|
|
|
|
};
|
|
|
|
|
|
|
|
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,
|
2024-01-11 09:43:59 +00:00
|
|
|
`Transform is correct for: { isTall: ${ isTall }, dir: ${ dir } }.`
|
2018-04-12 01:51:42 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
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,
|
2024-01-11 09:43:59 +00:00
|
|
|
`Correct element ID is returned for: { flippedY: ${ flippedY }, flippedX: ${ flippedX }, isTall: ${ isTall } }.`
|
2018-04-12 01:51:42 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
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.' );
|
|
|
|
} );
|