Skip to content

Commit 46b07d5

Browse files
committed
Merge branch 'ACP2E-1852' of https://github.com/magento-l3/magento2ce into PR-05242023
2 parents 3466c46 + 9c4f976 commit 46b07d5

File tree

2 files changed

+63
-8
lines changed

2 files changed

+63
-8
lines changed

app/code/Magento/Ui/view/base/web/js/form/element/file-uploader.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,14 @@ define([
7575
* @returns {FileUploader} Chainable.
7676
*/
7777
setInitialValue: function () {
78-
var value = this.getInitialValue();
78+
var value = this.getInitialValue(),
79+
imageSize = this.setImageSize;
80+
81+
_.each(value, function (val) {
82+
if (val.type !== undefined && val.type.indexOf('image') >= 0) {
83+
imageSize(val);
84+
}
85+
}, this);
7986

8087
value = value.map(this.processFile, this);
8188

@@ -88,6 +95,19 @@ define([
8895
return this;
8996
},
9097

98+
/**
99+
* Set image size for already loaded image
100+
*
101+
* @param value
102+
* @returns {Promise<void>}
103+
*/
104+
async setImageSize(value) {
105+
let response = await fetch(value.url),
106+
blob = await response.blob();
107+
108+
value.size = blob.size;
109+
},
110+
91111
/**
92112
* Empties files list.
93113
*

dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/form/element/file-uploader.test.js

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,21 @@ define([
3333
},
3434
component,
3535
dataScope = 'dataScope',
36-
originalJQuery = jQuery.fn;
36+
originalJQuery = jQuery.fn,
37+
params = {
38+
provider: 'provName',
39+
name: '',
40+
index: '',
41+
dataScope: dataScope
42+
};
3743

3844
beforeEach(function (done) {
3945
injector.mock(mocks);
4046
injector.require([
4147
'Magento_Ui/js/form/element/file-uploader',
4248
'knockoutjs/knockout-es5'
4349
], function (Constr) {
44-
component = new Constr({
45-
provider: 'provName',
46-
name: '',
47-
index: '',
48-
dataScope: dataScope
49-
});
50+
component = new Constr(params);
5051

5152
done();
5253
});
@@ -69,6 +70,40 @@ define([
6970
});
7071
});
7172

73+
describe('setInitialValue method', function () {
74+
75+
it('check for chainable', function () {
76+
expect(component.setInitialValue()).toEqual(component);
77+
});
78+
it('check for set value', function () {
79+
var initialValue = [
80+
{
81+
'name': 'test.png',
82+
'size': 0,
83+
'type': 'image/png',
84+
'url': 'http://localhost:8000/media/wysiwyg/test.png'
85+
}
86+
], expectedValue = [
87+
{
88+
'name': 'test.png',
89+
'size': 2000,
90+
'type': 'image/png',
91+
'url': 'http://localhost:8000/media/wysiwyg/test.png'
92+
}
93+
];
94+
95+
spyOn(component, 'setImageSize').and.callFake(function () {
96+
component.value().size = 2000;
97+
});
98+
spyOn(component, 'getInitialValue').and.returnValue(initialValue);
99+
component.service = true;
100+
expect(component.setInitialValue()).toEqual(component);
101+
expect(component.getInitialValue).toHaveBeenCalled();
102+
component.setImageSize(initialValue);
103+
expect(component.value().size).toEqual(expectedValue[0].size);
104+
});
105+
});
106+
72107
describe('isFileAllowed method', function () {
73108
var invalidFile,
74109
validFile;

0 commit comments

Comments
 (0)