|
5 | 5 |
|
6 | 6 | /*eslint max-nested-callbacks: 0*/
|
7 | 7 | define([
|
8 |
| - 'Magento_Ui/js/grid/masonry', |
9 |
| - 'jquery' |
10 |
| -], function (Masonry, $) { |
| 8 | + 'jquery', |
| 9 | + 'ko', |
| 10 | + 'Magento_Ui/js/grid/masonry' |
| 11 | +], function ($, ko, Masonry) { |
11 | 12 | 'use strict';
|
12 | 13 |
|
13 |
| - describe('Magento_Ui/js/grid/masonry', function () { |
14 |
| - var model; |
15 |
| - |
16 |
| - beforeEach(function () { |
17 |
| - $(document.body).append( |
18 |
| - $('<div id="masonry_grid"><div class="masonry-image-column"></div></div>') |
19 |
| - ); |
20 |
| - model = new Masonry({ |
21 |
| - defaults: { |
22 |
| - containerId: '#masonry_grid' |
23 |
| - } |
24 |
| - }); |
25 |
| - }); |
| 14 | + var Component, |
| 15 | + rows, |
| 16 | + params; |
| 17 | + |
| 18 | + beforeEach(function () { |
| 19 | + rows = [ |
| 20 | + { |
| 21 | + _rowIndex: 0, |
| 22 | + category: {}, |
| 23 | + 'category_id': 695, |
| 24 | + 'category_name': 'People', |
| 25 | + 'comp_url': 'https://stock.adobe.com/Rest/Libraries/Watermarked/Download/327515738/2', |
| 26 | + 'content_type': 'image/jpeg', |
| 27 | + 'country_name': 'Malaysia', |
| 28 | + 'creation_date': '2020-03-02 10:41:51', |
| 29 | + 'creator_id': 208217780, |
| 30 | + 'creator_name': 'NajmiArif', |
| 31 | + height: 3264, |
| 32 | + id: 327515738, |
| 33 | + 'id_field_name': 'id', |
| 34 | + 'is_downloaded': 0, |
| 35 | + 'is_licensed_locally': 0, |
| 36 | + keywords: [], |
| 37 | + 'media_type_id': 1, |
| 38 | + overlay: '', |
| 39 | + path: '', |
| 40 | + 'premium_level_id': 0, |
| 41 | + 'thumbnail_240_url': 'https://t4.ftcdn.net/jpg/03/27/51/57/240_F_327515738_nA3ke9EPgwmuH60oZrqZV4Fe5r9M6ndj.jpg', |
| 42 | + 'thumbnail_500_ur': 'https://as2.ftcdn.net/jpg/03/27/51/57/500_F_327515738_nA3ke9EPgwmuH60oZrqZV4Fe5r9M6ndj.jpg', |
| 43 | + title: 'Neon effect picture of man wearing medical mask for viral or pandemic disease', |
| 44 | + width: 4896 |
| 45 | + } |
| 46 | + |
| 47 | + ]; |
26 | 48 |
|
27 |
| - afterEach(function () { |
28 |
| - $('#masonry_grid').remove(); |
| 49 | + $('<div data-id="masonry_grid" id="masonry_grid"><div class="masonry-image-column"></div></div>').appendTo('body'); |
| 50 | + |
| 51 | + Component = new Masonry({ |
| 52 | + defaults: { |
| 53 | + rows: ko.observable() |
| 54 | + } |
29 | 55 | });
|
30 | 56 |
|
31 |
| - describe('check initComponent', function () { |
32 |
| - it('verify setLayoutstyles called and grid iniztilized', function () { |
33 |
| - expect(model).toBeDefined(); |
34 |
| - }); |
35 |
| - it('verify events triggered', function () { |
36 |
| - expect(model).toBeDefined(); |
| 57 | + }); |
| 58 | + |
| 59 | + afterEach(function () { |
| 60 | + $('#masonry_grid').remove(); |
| 61 | + }); |
| 62 | + |
| 63 | + describe('check initComponent', function () { |
| 64 | + it('verify setLayoutstyles called and grid iniztilized', function () { |
| 65 | + var setlayoutStyles = spyOn(Component, 'setLayoutStyles'); |
| 66 | + |
| 67 | + expect(Component).toBeDefined(); |
| 68 | + Component.containerId = 'masonry_grid'; |
| 69 | + Component.initComponent(rows); |
| 70 | + Component.rows().forEach(function (image) { |
| 71 | + expect(image.styles).toBeDefined(); |
| 72 | + expect(image.css).toBeDefined(); |
37 | 73 | });
|
| 74 | + expect(setlayoutStyles).toHaveBeenCalled(); |
| 75 | + }); |
| 76 | + it('verify events triggered', function () { |
| 77 | + var setLayoutStyles = spyOn(Component, 'setLayoutStyles'); |
| 78 | + |
| 79 | + Component.initComponent(rows); |
| 80 | + window.dispatchEvent(new Event('resize')); |
| 81 | + expect(setLayoutStyles).toHaveBeenCalled(); |
38 | 82 | });
|
39 | 83 | });
|
40 | 84 | });
|
0 commit comments