Skip to content

Commit 143b7e2

Browse files
committed
ACP2E-4222: Investigate if AC-8008 can be automated
1 parent 588eac3 commit 143b7e2

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* Copyright 2025 Adobe
3+
* All Rights Reserved.
4+
*/
5+
6+
/**
7+
* Jasmine tests for magnifier.js
8+
*/
9+
describe('Magnifier', function () {
10+
'use strict';
11+
let $, configMagnify, $container, $thumb, $preview;
12+
13+
beforeAll(function (done) {
14+
require(['/lib/web/magnifier/magnifier.js'], function () {
15+
$ = window.jQuery;
16+
configMagnify = $.fn.magnify;
17+
done();
18+
});
19+
});
20+
21+
beforeEach(function () {
22+
$container = $('<div></div>');
23+
const dataUri = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==';
24+
25+
$thumb = $('<img id="test-thumb" src="' + dataUri + '" />');
26+
$preview = $('<div class="magnifier-preview"></div>');
27+
$container.append($thumb);
28+
$('body').append($container).append($preview);
29+
});
30+
31+
afterEach(function () {
32+
$container.remove();
33+
$preview.remove();
34+
});
35+
36+
it('should not throw error if data is empty', function () {
37+
expect(function () {
38+
$container.magnify({ thumb: '#test-thumb', largeWrapper: '.magnifier-preview' });
39+
}).not.toThrow();
40+
});
41+
42+
it('should show magnifier for valid image', function (done) {
43+
const configMagnifier = $container.magnify({thumb: '#test-thumb', largeWrapper: '.magnifier-preview'});
44+
45+
setTimeout(function () {
46+
expect($('.magnifier-preview').length).toBe(1);
47+
done();
48+
}, 100);
49+
});
50+
51+
it('should not break when navigating from PLP to PDP', function () {
52+
$container.magnify({ thumb: '#test-thumb', largeWrapper: '.magnifier-preview' });
53+
expect(function () {
54+
$container.magnify({ thumb: '#test-thumb', largeWrapper: '.magnifier-preview' });
55+
}).not.toThrow();
56+
});
57+
58+
it('should not throw error if large image is missing', function (done) {
59+
$thumb.attr('src', '/404-image.jpg');
60+
expect(function () {
61+
$container.magnify({ thumb: '#test-thumb', largeWrapper: '.magnifier-preview' });
62+
}).not.toThrow();
63+
setTimeout(function () {
64+
expect($('.magnifier-preview').length).toBe(1);
65+
done();
66+
}, 100);
67+
});
68+
69+
it('should not throw error if thumb image has zero width/height', function (done) {
70+
$thumb.css({ width: 0, height: 0 });
71+
$thumb.attr('src', 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==');
72+
expect(function () {
73+
$container.magnify({ thumb: '#test-thumb', largeWrapper: '.magnifier-preview' });
74+
}).not.toThrow();
75+
setTimeout(function () {
76+
expect($('.magnifier-preview').length).toBe(1);
77+
done();
78+
}, 100);
79+
});
80+
});

0 commit comments

Comments
 (0)