From f070206da28f41814f6677ecee9ef4d84105338d Mon Sep 17 00:00:00 2001 From: Nazarn96 Date: Tue, 12 Nov 2019 11:05:27 +0200 Subject: [PATCH 1/8] The image details are not hidden when click on same image in the search result --- .../Ui/view/base/web/js/grid/columns/image-preview.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js b/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js index 1ef2ebf6594fa..8a22b06d53dc5 100644 --- a/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js +++ b/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js @@ -100,6 +100,12 @@ define([ */ show: function (record) { var img; + + if (record._rowIndex === this.lastOpenedImage() + && this.isVisible(record)) { + this.hide(); + return; + } this.hide(); this.displayedRecord(record); From c23393d20e9e3e6493f6326a2cc80c4e36cdf86d Mon Sep 17 00:00:00 2001 From: Nazarn96 Date: Tue, 12 Nov 2019 16:34:02 +0200 Subject: [PATCH 2/8] Fix error when open grid with opened preview --- .../Magento/Ui/view/base/web/js/grid/columns/image-preview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js b/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js index 8a22b06d53dc5..cc637d8a3c4d1 100644 --- a/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js +++ b/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js @@ -101,7 +101,7 @@ define([ show: function (record) { var img; - if (record._rowIndex === this.lastOpenedImage() + if (record._rowIndex === this.visibleRecord() && this.isVisible(record)) { this.hide(); return; From aa7195afb7fcab4a4984d9eb703643cc9d5a6be2 Mon Sep 17 00:00:00 2001 From: Nazarn96 Date: Thu, 14 Nov 2019 10:34:46 +0200 Subject: [PATCH 3/8] Fix static tests --- .../Ui/view/base/web/js/grid/columns/image-preview.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js b/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js index cc637d8a3c4d1..1da19a3645e4a 100644 --- a/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js +++ b/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js @@ -100,10 +100,11 @@ define([ */ show: function (record) { var img; - - if (record._rowIndex === this.visibleRecord() - && this.isVisible(record)) { + + if (record._rowIndex === this.visibleRecord() && + this.isVisible(record)) { this.hide(); + return; } From e29914e4581d5f14c6a4dcd5fdf4f4799c8df64c Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Thu, 14 Nov 2019 12:56:04 +0200 Subject: [PATCH 4/8] Update image-preview.js --- .../Magento/Ui/view/base/web/js/grid/columns/image-preview.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js b/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js index 1da19a3645e4a..cf597f8d3a543 100644 --- a/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js +++ b/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js @@ -101,8 +101,7 @@ define([ show: function (record) { var img; - if (record._rowIndex === this.visibleRecord() && - this.isVisible(record)) { + if (record._rowIndex === this.visibleRecord()) { this.hide(); return; From a565ee001e76ed3b5d53b7b21ed8dd637c1fb71b Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Fri, 15 Nov 2019 15:57:23 +0200 Subject: [PATCH 5/8] Remove duplicated hide() method --- .../Ui/view/base/web/js/grid/columns/image-preview.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js b/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js index cf597f8d3a543..372ab0e093727 100644 --- a/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js +++ b/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js @@ -101,13 +101,12 @@ define([ show: function (record) { var img; + this.hide(); + if (record._rowIndex === this.visibleRecord()) { - this.hide(); - return; } - - this.hide(); + this.displayedRecord(record); this._selectRow(record.rowNumber || null); this.visibleRecord(record._rowIndex); From b30b855668313aa55c00156927e9392723795195 Mon Sep 17 00:00:00 2001 From: Nazarn96 Date: Fri, 15 Nov 2019 16:33:16 +0200 Subject: [PATCH 6/8] Fix static test --- .../Magento/Ui/view/base/web/js/grid/columns/image-preview.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js b/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js index 372ab0e093727..57f16dc0c1a02 100644 --- a/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js +++ b/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js @@ -102,11 +102,11 @@ define([ var img; this.hide(); - + if (record._rowIndex === this.visibleRecord()) { return; } - + this.displayedRecord(record); this._selectRow(record.rowNumber || null); this.visibleRecord(record._rowIndex); From a7ffbd6842a0e4e243a014b8ceb8d197fca83f2e Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Mon, 18 Nov 2019 10:32:38 +0200 Subject: [PATCH 7/8] Move hide() method to if statement --- .../Ui/view/base/web/js/grid/columns/image-preview.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js b/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js index 57f16dc0c1a02..cf597f8d3a543 100644 --- a/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js +++ b/app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js @@ -101,12 +101,13 @@ define([ show: function (record) { var img; - this.hide(); - if (record._rowIndex === this.visibleRecord()) { + this.hide(); + return; } + this.hide(); this.displayedRecord(record); this._selectRow(record.rowNumber || null); this.visibleRecord(record._rowIndex); From e5d143d8d968bf5a71429677015be4ae36196a74 Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Sun, 24 Nov 2019 18:59:53 +0200 Subject: [PATCH 8/8] Cover changes with jasmnine test --- .../js/grid/columns/image-preview.test.js | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/grid/columns/image-preview.test.js diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/grid/columns/image-preview.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/grid/columns/image-preview.test.js new file mode 100644 index 0000000000000..b5c6e75248bfa --- /dev/null +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/grid/columns/image-preview.test.js @@ -0,0 +1,50 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +/* eslint-disable max-nested-callbacks, no-undef */ + +define([ + 'Magento_Ui/js/grid/columns/image-preview', + 'ko', + 'jquery' +], function (Preview, ko, $) { + 'use strict'; + + describe('Ui/js/grid/columns/image-preview', function () { + var record = { + _rowIndex: 1, + rowNumber: 1 + }, + imagePreview; + + beforeEach(function () { + imagePreview = new Preview(); + + /** + * @return {Object} + */ + function getThumbnail() { + return { + previewRowId: ko.observable() + }; + } + + imagePreview.thumbnailComponent = getThumbnail; + + imagePreview.visibleRecord = ko.observable(1); + }); + + describe('show method', function () { + it('show image', function () { + var mockImg = document.createElement('img'), + hide = spyOn(imagePreview, 'hide'); + + spyOn($.fn, 'get').and.returnValue(mockImg); + imagePreview.show(record); + expect(hide).toHaveBeenCalledTimes(1); + }); + + }); + }); +});