Skip to content

Commit d24d07d

Browse files
author
joweecaquicla
committed
magento/adobe-stock-integration#1387: Uncaught TypeError: Cannot read property 'complete' of undefined appears in dev console if save Previewed image as a new View and open this View on another page - fix static test and unit test
1 parent e2e6b3e commit d24d07d

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,18 @@ define([
5050
$(document).on('keydown', this.handleKeyDown.bind(this));
5151

5252
this.lastOpenedImage.subscribe(function (newValue) {
53+
5354
if (newValue === false && _.isNull(this.visibleRecord())) {
5455
return;
5556
}
57+
5658
if (newValue === this.visibleRecord()) {
5759
return;
5860
}
5961

6062
if (newValue === false) {
6163
this.hide();
64+
6265
return;
6366
}
6467

@@ -170,16 +173,14 @@ define([
170173
setTimeout(function () {
171174
this.updateImageData();
172175
}.bind(this), 100);
176+
} else if (img.get(0).complete) {
177+
this.updateHeight();
178+
this.scrollToPreview();
173179
} else {
174-
if (img.get(0).complete) {
180+
img.load(function () {
175181
this.updateHeight();
176182
this.scrollToPreview();
177-
} else {
178-
img.load(function () {
179-
this.updateHeight();
180-
this.scrollToPreview();
181-
}.bind(this));
182-
}
183+
}.bind(this));
183184
}
184185
},
185186

dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/grid/columns/image-preview.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ define([
7474
originMock = $.fn.get;
7575

7676
spyOn($.fn, 'get').and.returnValue(imageMock);
77+
imagePreview.lastOpenedImage = jasmine.createSpy().and.returnValue(2);
7778
imagePreview.visibleRecord = jasmine.createSpy().and.returnValue(2);
7879
imagePreview.displayedRecord = ko.observable();
7980
imagePreview.displayedRecord(recordMock);

0 commit comments

Comments
 (0)