Skip to content

Commit f953f35

Browse files
committed
Cover changes with jasmine tests
1 parent d06fd27 commit f953f35

File tree

1 file changed

+68
-24
lines changed

1 file changed

+68
-24
lines changed

dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/grid/masonry.test.js

Lines changed: 68 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,80 @@
55

66
/*eslint max-nested-callbacks: 0*/
77
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) {
1112
'use strict';
1213

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+
];
2648

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+
}
2955
});
3056

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();
3773
});
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();
3882
});
3983
});
4084
});

0 commit comments

Comments
 (0)