Skip to content

Commit 50bd8ac

Browse files
committed
maint(pat-gallery): Fix tests for Jest 30.
1 parent eb70099 commit 50bd8ac

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

src/pat/gallery/gallery.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ export default Base.extend({
6565
return template;
6666
},
6767

68+
pswp_options() {
69+
return {
70+
scaleMode: this.options.scaleMethod,
71+
loop: this.options.loop,
72+
slideshowDelay: this.options.delay,
73+
hideAnimationDuration: this.options.effectDuration,
74+
showAnimationDuration: this.options.effectDuration,
75+
pinchToClose: false,
76+
closeOnScroll: false,
77+
// Fix reload on gallery close which was induced by a history back call.
78+
history: false,
79+
};
80+
},
81+
6882
initialize_trigger() {
6983
const image_wrapper_els = dom.querySelectorAllAndMe(
7084
this.el,
@@ -108,28 +122,18 @@ export default Base.extend({
108122
// Now - when all is set - prevent default action.
109123
e.preventDefault();
110124

125+
// Get the index of the clicked gallery item in the list of images.
111126
const index =
112127
this.images
113128
.map((it) => it.src)
114129
.indexOf(
115130
trigger_el.getAttribute("href") || trigger_el.getAttribute("src")
116131
) || 0;
117132

118-
const options = {
119-
// Get the index of the clicked gallery item in the list of images.
120-
index: index,
121-
scaleMode: this.options.scaleMethod,
122-
loop: this.options.loop,
123-
slideshowDelay: this.options.delay,
124-
hideAnimationDuration: this.options.effectDuration,
125-
showAnimationDuration: this.options.effectDuration,
126-
pinchToClose: false,
127-
closeOnScroll: false,
128-
// Fix reload on gallery close which was induced by a history back call.
129-
history: false,
130-
};
133+
const pswp_options = this.pswp_options();
134+
pswp_options.index = index; // start at clicked image
131135

132-
const gallery = new PhotoSwipe(pswp_el, PhotoSwipeUI, this.images, options);
136+
const gallery = new PhotoSwipe(pswp_el, PhotoSwipeUI, this.images, pswp_options);
133137

134138
const gallery_reinit_sizes_debouncer = utils.debounce(() => {
135139
gallery.updateSize(true); // reinit Items

src/pat/gallery/gallery.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ describe("pat-gallery", function () {
3333
const spy_init_trigger = jest.spyOn(instance, "initialize_trigger");
3434
const spy_init_gallery = jest.spyOn(instance, "initialize_gallery");
3535

36+
jest.spyOn(instance, "pswp_options").mockImplementation(function () {
37+
return { getThumbBoundsFn: () => ({ x:0, y:0, w:100 }) };
38+
});
39+
3640
await utils.timeout(1);
3741

3842
expect(spy_init_trigger).toHaveBeenCalled();
@@ -65,6 +69,10 @@ describe("pat-gallery", function () {
6569
const spy_init_trigger = jest.spyOn(instance, "initialize_trigger");
6670
const spy_init_gallery = jest.spyOn(instance, "initialize_gallery");
6771

72+
jest.spyOn(instance, "pswp_options").mockImplementation(function () {
73+
return { getThumbBoundsFn: () => ({ x:0, y:0, w:100 }) };
74+
});
75+
6876
await utils.timeout(1);
6977

7078
expect(spy_init_trigger).toHaveBeenCalledTimes(1);

0 commit comments

Comments
 (0)