Skip to content

Commit b412a5c

Browse files
committed
Merge remote-tracking branch 'origin/ACP2E-4231' into PR_2025_10_01_flowers
2 parents ba9cc9d + 6a51acc commit b412a5c

File tree

2 files changed

+1354
-1050
lines changed

2 files changed

+1354
-1050
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/**
2+
* Copyright 2025 Adobe
3+
* All Rights Reserved.
4+
*/
5+
/**
6+
* Verifies fotorama stopEvent behavior on mobile vs desktop interactions.
7+
*/
8+
define([
9+
'jquery',
10+
'text!/lib/web/fotorama/fotorama.js'
11+
], function ($, fotoramaSource) {
12+
'use strict';
13+
14+
describe('lib/web/fotorama/fotorama.js stopEvent', function () {
15+
var originalMatchMedia, originalModernizr, stopEventFn;
16+
17+
function extractStopEvent(source) {
18+
let start = source.indexOf('function stopEvent'),
19+
braceStart,
20+
depth,
21+
i,
22+
end,
23+
ch;
24+
25+
if (start === -1) {
26+
return undefined;
27+
}
28+
braceStart = source.indexOf('{', start);
29+
depth = 0, i = braceStart, end = -1;
30+
for (; i < source.length; i++) {
31+
ch = source[i];
32+
if (ch === '{') {
33+
depth++;
34+
} else if (ch === '}') {
35+
depth--;
36+
// eslint-disable-next-line max-depth
37+
if (depth === 0) {
38+
end = i + 1;
39+
break;
40+
}
41+
}
42+
}
43+
if (end === -1) {
44+
return undefined;
45+
}
46+
// eslint-disable-next-line no-new-func
47+
return new Function('return (' + source.slice(start, end) + ');')();
48+
}
49+
50+
beforeAll(function () {
51+
originalMatchMedia = window.matchMedia;
52+
originalModernizr = window.Modernizr;
53+
});
54+
55+
afterAll(function () {
56+
window.matchMedia = originalMatchMedia;
57+
window.Modernizr = originalModernizr;
58+
});
59+
60+
beforeEach(function () {
61+
// Ensure Modernizr exists; the function references it
62+
window.Modernizr = window.Modernizr || { touch: false };
63+
stopEventFn = extractStopEvent(fotoramaSource);
64+
});
65+
66+
function mockEvent(type) {
67+
return {
68+
type: type,
69+
preventDefault: jasmine.createSpy('preventDefault'),
70+
stopPropagation: jasmine.createSpy('stopPropagation'),
71+
returnValue: true
72+
};
73+
}
74+
75+
it('prevents default and stops propagation on mobile touchend', function () {
76+
var e = mockEvent('touchend');
77+
78+
window.matchMedia = function () { return { matches: true }; };
79+
stopEventFn(e);
80+
expect(e.preventDefault).toHaveBeenCalled();
81+
expect(e.stopPropagation).toHaveBeenCalled();
82+
});
83+
84+
it('prevents default on desktop click when Modernizr.touch is false', function () {
85+
var e = mockEvent('click');
86+
87+
window.matchMedia = function () { return { matches: false }; };
88+
window.Modernizr.touch = false;
89+
stopEventFn(e);
90+
expect(e.preventDefault).toHaveBeenCalled();
91+
});
92+
93+
it('does not prevent default on desktop click when Modernizr.touch is true', function () {
94+
var e = mockEvent('click');
95+
96+
window.matchMedia = function () { return { matches: false }; };
97+
window.Modernizr.touch = true;
98+
stopEventFn(e);
99+
expect(e.preventDefault).not.toHaveBeenCalled();
100+
});
101+
102+
it('stops propagation when second argument is true', function () {
103+
var e = mockEvent('click');
104+
105+
window.matchMedia = function () { return { matches: false }; };
106+
window.Modernizr.touch = false;
107+
stopEventFn(e, true);
108+
expect(e.stopPropagation).toHaveBeenCalled();
109+
});
110+
});
111+
});
112+
113+

0 commit comments

Comments
 (0)