Skip to content

Commit 0ed2bcd

Browse files
committed
Cover changes with jasmine test
1 parent ab7c9dc commit 0ed2bcd

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

app/code/Magento/Theme/view/frontend/web/js/cookie-status.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
define([
22
'jquery',
33
'Magento_Ui/js/modal/modal',
4-
'mage/translate',
5-
], function($, modal){
4+
'mage/translate'
5+
], function ($, modal) {
66
'use strict';
77

88
$.widget('mage.cookieStatus', {
@@ -14,6 +14,10 @@ define([
1414
buttons: [{
1515
text: $.mage.__('Close'),
1616
class: 'cookie-status',
17+
18+
/**
19+
* Callback for click event
20+
*/
1721
click: function () {
1822
this.closeModal();
1923
}
@@ -26,11 +30,11 @@ define([
2630
*/
2731
_init: function () {
2832

29-
if(!navigator.cookieEnabled) {
33+
if (!navigator.cookieEnabled) {
3034
modal(this.options, $('#cookie-status'));
3135
}
3236
}
3337
});
34-
38+
3539
return $.mage.cookieStatus;
36-
});
40+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
define([
8+
'jquery',
9+
'cookieStatus'
10+
], function ($, Cookie) {
11+
'use strict';
12+
13+
describe('Magento_Theme/js/cookie-status', function () {
14+
var widget,
15+
htmlContainer = '<div id="cookie-status" style="display: none"></div>',
16+
navigator;
17+
18+
beforeEach(function () {
19+
$(document.body).append(htmlContainer);
20+
widget = new Cookie();
21+
navigator = window.navigator;
22+
});
23+
24+
afterEach(function () {
25+
window.navigator = navigator;
26+
});
27+
28+
it('verify cookie-status initialization', function () {
29+
expect($.fn.cookieStatus).toBeDefined();
30+
window.navigator = {
31+
cookieEnabled: false
32+
};
33+
widget._init();
34+
expect($('.cookie-status').length).toBe(1);
35+
expect($(document.body).html()).toContain('<aside role="dialog" class="modal-popup');
36+
});
37+
38+
});
39+
});

0 commit comments

Comments
 (0)