Skip to content

Commit 7e14680

Browse files
authored
Upgrade PhotoSwipe (#13833)
1 parent 7d951ef commit 7e14680

File tree

5 files changed

+40
-55
lines changed

5 files changed

+40
-55
lines changed

jest.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ module.exports = {
4040
// Tests can assert on the filename.
4141
'^.+\\.(jpg|jpeg|gif|png|svg)$': '<rootDir>/tests/fileTransformer',
4242
},
43-
transformIgnorePatterns: ['<rootDir>/node_modules/'],
43+
transformIgnorePatterns: [
44+
// ESM modules should be transformed.
45+
'<rootDir>/node_modules/(?!(react-photoswipe-gallery|photoswipe)/)',
46+
],
4447
watchPlugins: [
4548
'jest-watch-typeahead/filename',
4649
'jest-watch-typeahead/testname',

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
"nano-time": "1.0.0",
210210
"normalize.css": "8.0.1",
211211
"photon-colors": "3.3.2",
212-
"photoswipe": "4.1.3",
212+
"photoswipe": "5.4.4",
213213
"pino": "9.10.0",
214214
"pino-syslog": "3.1.0",
215215
"prop-types": "15.8.1",
@@ -225,7 +225,7 @@
225225
"react-keydown": "1.9.12",
226226
"react-nested-status": "0.2.1",
227227
"react-onclickoutside": "6.13.2",
228-
"react-photoswipe-gallery": "1.3.10",
228+
"react-photoswipe-gallery": "4.0.0",
229229
"react-redux": "8.1.3",
230230
"react-router": "5.3.4",
231231
"react-router-dom": "5.3.4",
@@ -333,7 +333,7 @@
333333
"bundlewatch": [
334334
{
335335
"path": "./dist/static/amo-!(i18n-)*.js",
336-
"maxSize": "369 kB"
336+
"maxSize": "371 kB"
337337
},
338338
{
339339
"path": "./dist/static/amo-i18n-*.js",

src/amo/components/ScreenShots/index.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,12 @@ import invariant from 'invariant';
33
import * as React from 'react';
44
import { Gallery, Item } from 'react-photoswipe-gallery';
55
import 'photoswipe/dist/photoswipe.css';
6-
import 'photoswipe/dist/default-skin/default-skin.css';
76

87
import type { PreviewType } from 'amo/types/addons';
98
import './styles.scss';
109

1110
export const PHOTO_SWIPE_OPTIONS = {
12-
closeEl: true,
13-
captionEl: true,
14-
fullscreenEl: false,
15-
zoomEl: false,
16-
shareEl: false,
17-
counterEl: true,
18-
arrowEl: true,
19-
preloaderEl: true,
11+
bgOpacity: 0.9,
2012
};
2113

2214
type Props = {|
@@ -35,8 +27,8 @@ export default class ScreenShots extends React.Component<Props> {
3527
// This is used to update the horizontal list of thumbnails in order to
3628
// show the last image displayed in fullscreen mode when we close the
3729
// carousel.
38-
photoswipe.listen('close', () => {
39-
const index = photoswipe.getCurrentIndex();
30+
photoswipe.on('close', () => {
31+
const { index } = photoswipe.currSlide;
4032
const currentItem = list.children[index];
4133
const offset = currentItem.getBoundingClientRect().left;
4234

@@ -59,6 +51,7 @@ export default class ScreenShots extends React.Component<Props> {
5951
<Gallery
6052
options={PHOTO_SWIPE_OPTIONS}
6153
onOpen={this.onOpenPhotoswipe}
54+
withCaption
6255
>
6356
{previews.map((preview) => (
6457
<Item
@@ -67,7 +60,7 @@ export default class ScreenShots extends React.Component<Props> {
6760
thumbnail={preview.thumbnail_src}
6861
width={preview.w}
6962
height={preview.h}
70-
title={preview.title}
63+
caption={preview.title}
7164
>
7265
{({ ref, open }) => (
7366
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions

tests/unit/amo/components/TestScreenShots.js

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* global window */
12
import * as React from 'react';
23
import userEvent from '@testing-library/user-event';
34

@@ -7,6 +8,21 @@ import { render as defaultRender, screen } from 'tests/unit/helpers';
78
const HEIGHT = 400;
89
const WIDTH = 200;
910

11+
// See: https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
12+
Object.defineProperty(window, 'matchMedia', {
13+
writable: true,
14+
value: jest.fn().mockImplementation((query) => ({
15+
matches: false,
16+
media: query,
17+
onchange: null,
18+
addListener: jest.fn(), // deprecated
19+
removeListener: jest.fn(), // deprecated
20+
addEventListener: jest.fn(),
21+
removeEventListener: jest.fn(),
22+
dispatchEvent: jest.fn(),
23+
})),
24+
});
25+
1026
describe(__filename, () => {
1127
const testPreviews = [
1228
{
@@ -53,34 +69,7 @@ describe(__filename, () => {
5369

5470
await userEvent.click(screen.getByAltText(testPreviews[0].title));
5571

56-
// Verifying the output of PHOTO_SWIPE_OPTIONS.
57-
// closeEl: true,
58-
expect(screen.getByTitle('Close (Esc)')).not.toHaveClass(
59-
'pswp__element--disabled',
60-
);
61-
// captionEl: true,
62-
expect(screen.getAllByText(testPreviews[0].title)).toHaveLength(2);
63-
// fullscreenEl: false,
64-
expect(screen.getByTitle('Toggle fullscreen')).toHaveClass(
65-
'pswp__element--disabled',
66-
);
67-
// zoomEl: false,
68-
expect(screen.getByTitle('Zoom in/out')).toHaveClass(
69-
'pswp__element--disabled',
70-
);
71-
// shareEl: false,
72-
expect(screen.getByTitle('Share')).toHaveClass('pswp__element--disabled');
73-
// counterEl: true,
74-
expect(screen.getByText('1 / 2')).toBeInTheDocument();
75-
// arrowEl: true,
76-
expect(screen.getByTitle('Previous (arrow left)')).not.toHaveClass(
77-
'pswp__element--disabled',
78-
);
79-
expect(screen.getByTitle('Next (arrow right)')).not.toHaveClass(
80-
'pswp__element--disabled',
81-
);
82-
// preloaderEl: true,
83-
expect(screen.getByClassName('pswp__preloader')).toBeInTheDocument();
72+
expect(screen.getByText(testPreviews[0].title)).toBeInTheDocument();
8473
});
8574

8675
// eslint-disable-next-line jest/no-commented-out-tests
@@ -98,11 +87,11 @@ describe(__filename, () => {
9887
9988
it('scrolls to the active item on close', async () => {
10089
const { unmount } = render();
101-
90+
10291
// eslint-disable-next-line testing-library/no-node-access
10392
const list = document.querySelector('.ScreenShots-list');
10493
const scrollLeft = jest.spyOn(list, 'scrollLeft', 'set');
105-
94+
10695
// This clicks the Escape key.
10796
fireEvent.keyDown(screen.getByAltText(testPreviews[0].title), {
10897
key: 'Escape',
@@ -113,7 +102,7 @@ describe(__filename, () => {
113102
await userEvent.keyboard('[Escape]');
114103
await userEvent.keyboard('{esc}');
115104
unmount();
116-
105+
117106
await waitFor(() => expect(scrollLeft).toHaveBeenCalled());
118107
});
119108
*/

yarn.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8196,10 +8196,10 @@ [email protected]:
81968196
resolved "https://registry.yarnpkg.com/photon-colors/-/photon-colors-3.3.2.tgz#eaf2e5a8ba9368fcdee0607cc86a9f613e6d3417"
81978197
integrity sha512-xCeL7J2F8cjM00zQZEZawHAGnrSOM509RbanL4c8hvrV8n19V/wwdzydX6rSUEtLYj4nx4OvhmKC4/vujo9f/Q==
81988198

8199-
photoswipe@4.1.3:
8200-
version "4.1.3"
8201-
resolved "https://registry.yarnpkg.com/photoswipe/-/photoswipe-4.1.3.tgz#59f49494eeb9ddab5888d03392926a19bc197550"
8202-
integrity sha512-89Z43IRUyw7ycTolo+AaiDn3W1EEIfox54hERmm9bI12IB9cvRfHSHez3XhAyU8XW2EAFrC+2sKMhh7SJwn0bA==
8199+
photoswipe@5.4.4:
8200+
version "5.4.4"
8201+
resolved "https://registry.yarnpkg.com/photoswipe/-/photoswipe-5.4.4.tgz#e045dc036453493188d5c8665b0e8f1000ac4d6e"
8202+
integrity sha512-WNFHoKrkZNnvFFhbHL93WDkW3ifwVOXSW3w1UuZZelSmgXpIGiZSNlZJq37rR8YejqME2rHs9EhH9ZvlvFH2NA==
82038203

82048204
picocolors@^1.0.0, picocolors@^1.1.0, picocolors@^1.1.1:
82058205
version "1.1.1"
@@ -8979,10 +8979,10 @@ [email protected]:
89798979
resolved "https://registry.yarnpkg.com/react-onclickoutside/-/react-onclickoutside-6.13.2.tgz#caa6df2c0cfe017506548fa810303fb85d13fb7c"
89808980
integrity sha512-h6Hbf1c8b7tIYY4u90mDdBLY4+AGQVMFtIE89HgC0DtVCh/JfKl477gYqUtGLmjZBKK3MJxomP/lFiLbz4sq9A==
89818981

8982-
react-photoswipe-gallery@1.3.10:
8983-
version "1.3.10"
8984-
resolved "https://registry.yarnpkg.com/react-photoswipe-gallery/-/react-photoswipe-gallery-1.3.10.tgz#82d87c3a435bf8eddce69f17f2d9ecf54e203312"
8985-
integrity sha512-KIfhIjdqutX+FHEXw06gFsLgbBMSUW9Y5qAW+bI3deTNiSDmF1Sgfh/sKJF+gNkFZTWbmnhG2g7BsrjC7T9etg==
8982+
react-photoswipe-gallery@4.0.0:
8983+
version "4.0.0"
8984+
resolved "https://registry.yarnpkg.com/react-photoswipe-gallery/-/react-photoswipe-gallery-4.0.0.tgz#a96d3c91871a3b92d89ee1b09ab1ead72241b407"
8985+
integrity sha512-rpvGSBddLp1hZfTZgi3UFLJKlupHfDhW6e7w6jUUr5bagTWfrxJ7nB8yzNkx+BaoiMyy4FvJBwc4n/+QW2ft4g==
89868986

89878987
89888988
version "8.1.3"

0 commit comments

Comments
 (0)