Files
zulip/frontend_tests/node_tests/lightbox.js
Marco Burstein 11cbe2bf6a lightbox: Fix a "Pan & Zoom" causing an error with thumbnailed images.
Images on the new thumbnailing system generate an error when
"Pan & Zoom" is enabled:

    Browser Error: Lightbox for unknown message undefined
    39648: http://localhost:9991/webpack/app.js
        | Object.blueslip_error [as error]
    50743: http://localhost:9991/webpack/app.js
        | Object../static/js/lightbox.js.exports.open
    50897: http://localhost:9991/webpack/app.js
        | HTMLDivElement.
    39474: http://localhost:9991/webpack/app.js
        | HTMLDivElement.blueslip_wrapper
    16299: http://localhost:9991/webpack/app.js
        | HTMLDivElement.dispatch
    16107: http://localhost:9991/webpack/app.js
        | HTMLDivElement.elemData.handle

To fix this, instead of using the `src` attribute as the key for
`asset_map`, which can be either the original or thumbnailed version
depending on the situation, always use the original version.

Also, create `frontend_tests/node_tests/lightbox.js` to test this
functionality.

Fix #9955.
2018-07-18 10:19:56 -07:00

42 lines
1.0 KiB
JavaScript

zrequire('lightbox');
set_global('blueslip', global.make_zblueslip());
set_global('message_store', {
get: () => ({}),
});
set_global('Image', class Image {});
set_global('overlays', {
close_overlay: () => {},
close_active: () => {},
open_overlay: () => {},
});
set_global('popovers', {
hide_all: () => {},
});
set_global('$', function () {
return {
hasClass: () => false,
closest: () => [],
attr: (attr) => attr,
parent: () => ({
closest: () => ({
attr: (attr) => attr,
}),
attr: (attr) => attr,
}),
html: () => ({
show: () => {},
}),
hide: () => {},
show: () => {},
text: () => '',
};
});
run_test('pan_and_zoom', () => {
lightbox.open('<img src="./image.png" data-original="./original.png">');
assert.equal(blueslip.get_test_logs('error').length, 0);
lightbox.open('<img src="./image.png">');
assert.equal(blueslip.get_test_logs('error').length, 0);
});