Skip to content

Commit 873e608

Browse files
committed
MC-1263: Buttons of Image Content Block are not aligned correctly
- Added unit tests for the responsive class behavior
1 parent e03368b commit 873e608

File tree

1 file changed

+118
-0
lines changed
  • dev/tests/js/jasmine/tests/app/code/Magento/PageBuilder/view/adminhtml/web/js/form/element

1 file changed

+118
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/**
2+
*
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/* eslint-disable max-nested-callbacks */
8+
define([
9+
'Magento_PageBuilder/js/form/element/image-uploader',
10+
'jquery'
11+
], function (ImageUploader, $) {
12+
'use strict';
13+
14+
var uploader,
15+
modifierClassSet1 = {
16+
'foo': {
17+
minWidth: 1000
18+
},
19+
'bar': {
20+
minWidth: 3000
21+
},
22+
'baz': {
23+
minWidth: 100,
24+
maxWidth: 200
25+
},
26+
'bash': {
27+
maxWidth: 50
28+
}
29+
},
30+
scenarios = [
31+
{
32+
config: modifierClassSet1,
33+
elementWidth: 1000,
34+
expectedClasses: 'foo'
35+
},
36+
{
37+
config: modifierClassSet1,
38+
elementWidth: 1500,
39+
expectedClasses: 'foo'
40+
},
41+
{
42+
config: modifierClassSet1,
43+
elementWidth: 3100,
44+
expectedClasses: 'foo bar'
45+
},
46+
{
47+
config: modifierClassSet1,
48+
elementWidth: 100,
49+
expectedClasses: 'baz'
50+
},
51+
{
52+
config: modifierClassSet1,
53+
elementWidth: 200,
54+
expectedClasses: 'baz'
55+
},
56+
{
57+
config: modifierClassSet1,
58+
elementWidth: 10,
59+
expectedClasses: 'bash'
60+
},
61+
{
62+
config: modifierClassSet1,
63+
elementWidth: 50,
64+
expectedClasses: 'bash'
65+
}
66+
];
67+
68+
beforeEach(function () {
69+
var MockUploader = function () {};
70+
71+
// Bypass the original constructor
72+
MockUploader.prototype = Object.create(ImageUploader.prototype);
73+
MockUploader.prototype.constructor = function () {};
74+
uploader = new MockUploader();
75+
uploader.$uploadArea = $('<div/>');
76+
});
77+
78+
describe('Magento_PageBuilder/js/form/element/image-uploader', function () {
79+
describe('updateResponsiveClasses', function () {
80+
it('Should do nothing when element is not visible', function () {
81+
spyOn(uploader.$uploadArea, 'is').and.returnValue(false);
82+
spyOn(uploader.$uploadArea, 'removeClass');
83+
spyOn(uploader.$uploadArea, 'addClass');
84+
85+
uploader.updateResponsiveClasses();
86+
87+
// None of the algorithm should have been attempted
88+
expect(uploader.$uploadArea.addClass).not.toHaveBeenCalled();
89+
expect(uploader.$uploadArea.removeClass).not.toHaveBeenCalled();
90+
});
91+
it('Attempts to remove all defined modifier classes', function () {
92+
uploader.elementWidthModifierClasses = {
93+
'foo': {},
94+
'bar': {}
95+
};
96+
spyOn(uploader.$uploadArea, 'is').and.returnValue(true);
97+
spyOn(uploader.$uploadArea, 'removeClass');
98+
99+
uploader.updateResponsiveClasses();
100+
101+
expect(uploader.$uploadArea.removeClass).toHaveBeenCalledWith('foo bar');
102+
});
103+
104+
$.each(scenarios, function (i, scenario) {
105+
it('Should add modifier classes if configuration is met in scenario ' + i, function () {
106+
uploader.elementWidthModifierClasses = scenario.config;
107+
spyOn(uploader.$uploadArea, 'is').and.returnValue(true);
108+
spyOn(uploader.$uploadArea, 'width').and.returnValue(scenario.elementWidth);
109+
spyOn(uploader.$uploadArea, 'addClass');
110+
111+
uploader.updateResponsiveClasses();
112+
113+
expect(uploader.$uploadArea.addClass).toHaveBeenCalledWith(scenario.expectedClasses);
114+
});
115+
});
116+
});
117+
});
118+
});

0 commit comments

Comments
 (0)