Skip to content

Commit

Permalink
AC-2558: Upgraded grunt-contrib-jasmine to the latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
anzin committed Apr 29, 2022
1 parent 07d15f8 commit a706ccd
Show file tree
Hide file tree
Showing 19 changed files with 84 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ define(
*/
execute: function () {
fullScreenLoader.startLoader();
this.reloadPage();
},

/**
* Method to reload page
*/
reloadPage: function () {
window.location.replace(url.build(this.redirectUrl));
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ define([
messageContainer = messageContainer || globalMessageList;

if (response.status == 401) { //eslint-disable-line eqeqeq
window.location.replace(url.build('customer/account/login/'));
this.reloadPage(url.build('customer/account/login/'));
} else {
try {
error = JSON.parse(response.responseText);
Expand All @@ -35,6 +35,13 @@ define([
}
messageContainer.addErrorMessage(error);
}
},

/**
* Method to reload page
*/
reloadPage: function (redirectUrl) {
window.location.replace(redirectUrl);
}
};
});
11 changes: 11 additions & 0 deletions dev/tests/js/jasmine/spec_runner/jasmine-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

(function() {
var env = jasmine.getEnv(),
config = {random: false};

env.configure(config);
})();
7 changes: 6 additions & 1 deletion dev/tests/js/jasmine/spec_runner/tasks/jasmine.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ function init(config) {
/**
* @todo rename "helpers" to "specs" (implies overriding grunt-contrib-jasmine code)
*/
helpers: specs
helpers: specs,
sandboxArgs: {
args: ['--no-sandbox', '--disable-setuid-sandbox'],
defaultViewport: {width: 400, height: 400, hasTouch: true},
slowMo: 10000
}
}
};
});
Expand Down
2 changes: 1 addition & 1 deletion dev/tests/js/jasmine/spec_runner/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</script>
<% }); %>
<% with (scripts) { %>
<% [].concat(polyfills, jasmine, boot, vendor, src, reporters).forEach(function (script) { %>
<% [].concat(polyfills, jasmine, '.grunt/grunt-contrib-jasmine/boot0.js', 'dev/tests/js/jasmine/spec_runner/jasmine-config.js', '.grunt/grunt-contrib-jasmine/boot1.js', vendor, src, reporters).forEach(function (script) { %>
<script type="text/javascript" src="<%= script %>"></script>
<% }); %>
<% } %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ define([
});

it('Checks if loader is called before redirect to success page.', function () {
spyOn(window.location, 'replace').and.returnValue(false);

spyOn(RedirectOnSuccess, 'reloadPage').and.callFake(function () {});
RedirectOnSuccess.execute();

expect(FullScreenLoader.startLoader).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ define([
it('check on failed status', function () {
var messageContainer = jasmine.createSpyObj('globalMessageList', ['addErrorMessage']);

spyOn(window.location, 'replace').and.callFake(function () {});
spyOn(model, 'reloadPage').and.callFake(function () {});
model.process({
status: 401,
responseText: ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ define([
});

it('Check on empty object.', function () {
var expected = {
countryId: 'US',
regionCode: null,
region: null
};
var result = newCustomerAddress({}),
expected = {
countryId: 'US',
regionCode: null,
region: null
};

expect(JSON.stringify(newCustomerAddress({}))).toEqual(JSON.stringify(expected));
result.postcode = undefined;
expect(JSON.stringify(result)).toEqual(JSON.stringify(expected));
});

it('Check on function call with empty address data.', function () {
Expand All @@ -57,6 +59,7 @@ define([
regionId: 1
};

result.postcode = undefined;
expect(JSON.stringify(result)).toEqual(JSON.stringify(expected));
});
it('Check on regionId with countryId in address data.', function () {
Expand All @@ -69,6 +72,7 @@ define([
region: null
};

result.postcode = undefined;
expect(JSON.stringify(result)).toEqual(JSON.stringify(expected));
});
it('Check that extensionAttributes property exists if defined', function () {
Expand All @@ -86,6 +90,7 @@ define([
}
};

result.postcode = undefined;
expect(JSON.stringify(result)).toEqual(JSON.stringify(expected));
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,26 @@ define(['squire'], function (Squire) {
it('Product is not configurable by default', function () {
var component = new Component(params);

expect(component.disabled()).toBeFalsy();
expect(component.disabled()).toBeFalse();
expect(component.value()).toEqual(1000);
});

it('State of component does not changed', function () {
var component = new Component(params);

expect(component.disabled()).toBeFalsy();
expect(component.disabled()).toBeFalse();

component.value(99);
component.handleQtyValue(false);

expect(component.disabled()).toBeFalsy();
expect(component.disabled()).toBeFalse();
expect(component.value()).toEqual(99);
});

it('Product changed to configurable', function () {
var component = new Component(params);

expect(component.disabled()).toBeFalsy();
expect(component.disabled()).toBeFalse();
expect(component.value()).toEqual(1000);

component.handleQtyValue(true);
Expand Down Expand Up @@ -100,7 +100,7 @@ define(['squire'], function (Squire) {
component.value(100);
component.handleQtyValue(false);

expect(component.disabled()).toBeFalsy();
expect(component.disabled()).toBeFalse();
expect(component.value()).toEqual(100);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ define(['Magento_Customer/js/form/components/insert-listing'], function (Constr)
};

beforeEach(function () {
obj = new Constr({
name: 'content_name',
selections: function () {
return selectionsProvider;
}
});
obj = new Constr({ name: 'content_name' });
});

describe('Check delete massaction process', function () {
Expand All @@ -45,6 +40,10 @@ define(['Magento_Customer/js/form/components/insert-listing'], function (Constr)

it('Check ids are retrieved from selections provider if they are NOT in data', function () {
obj._delete = jasmine.createSpy();
obj.selections = jasmine.createSpy().and.callFake(function () {
return selectionsProvider;
});

obj.onMassAction({
action: 'delete',
data: {}
Expand All @@ -60,6 +59,10 @@ define(['Magento_Customer/js/form/components/insert-listing'], function (Constr)
get: jasmine.createSpy().and.returnValues(2, 3),
set: jasmine.createSpy()
};
obj.selections = jasmine.createSpy().and.callFake(function () {
return selectionsProvider;
});

obj.onMassAction(data);

expect(selectionsProvider.selected).not.toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ define([
});

it('Check it requests sections from the server if there are expired sections', function () {
clearLocalStorage();
setupLocalStorage({
'customer': {
'data_id': Math.floor(Date.now() / 1000) + 60 // invalidated,
Expand Down Expand Up @@ -279,6 +280,7 @@ define([
});

it('Check that result contains invalidated section names', function () {
clearLocalStorage();
setupLocalStorage({
'cart': { // without storage content
'data_id': Math.floor(Date.now() / 1000) + 60 // in 1 minute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ define([
var escapedMessage = 'escaped message';

// eslint-disable-next-line max-nested-callbacks
spyOn(escaperInstance, 'escapeHtml').and.callFake(function () {
escaperInstance.escapeHtml = jasmine.createSpy().and.callFake(function () {
return escapedMessage;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ define([
result = obj.defaultCallback(action, data);

expect(typeof result).toBe('object');
spyOn(utils, 'submit').and.callThrough();
utils.submit = jasmine.createSpy().and.callThrough();
utils.submit({
url: action.url,
data: data.selected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,18 @@ define([
$(document.body).append(htmlContainer);
});

afterEach(function () {
window.navigator = navigator;
});

it('defines cookieStatus widget', function () {
expect($.fn.cookieStatus).toBeDefined();
});

it('does not show a modal when cookies are supported', function () {
window.navigator = {
cookieEnabled: true
};
Object.defineProperty(navigator,'cookieEnabled',{value: true, configurable: true});
widget._init();
expect($(document.body).html()).not.toContain('<aside role="dialog" class="modal-popup');
});

it('shows the modal when cookies are not supported', function () {
window.navigator = {
cookieEnabled: false
};
Object.defineProperty(navigator,'cookieEnabled',{value: false, configurable: true});
widget._init();
expect($(document.body).html()).toContain('<aside role="dialog" class="modal-popup');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ define([
});
it('Check call "beforeSave" method without parameters', function () {
$.ajax = jasmine.createSpy();
utils.submit = jasmine.createSpy();
obj.urls.beforeSave = null;
obj.save();

Expand All @@ -113,6 +114,7 @@ define([
$.ajax = jasmine.createSpy().and.callFake(function (req) {
request = req.success;
});
utils.submit = jasmine.createSpy();
jQueryMethods.notification = $.fn.notification;
$.fn.notification = jasmine.createSpy();
obj.urls.beforeSave = 'requestPath';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ define([
id: 3
});

expect(multiSelect.allSelected()).toBeFalsy();
expect(multiSelect.allSelected()).toBeFalse();
expect(multiSelect.excluded().toString()).toEqual('');
expect(multiSelect.selected().toString()).toEqual('');
});
Expand All @@ -51,7 +51,7 @@ define([
multiSelect.selected.push(4);
multiSelect.selected.push(5);

expect(multiSelect.allSelected()).toBeFalsy();
expect(multiSelect.allSelected()).toBeUndefined();
expect(multiSelect.excluded().toString()).toEqual('');
expect(multiSelect.selected().toString()).toEqual('4,5');
});
Expand All @@ -70,7 +70,7 @@ define([
}]);
multiSelect.selectPage();

expect(multiSelect.allSelected()).toBeFalsy();
expect(multiSelect.allSelected()).toBeUndefined();
expect(multiSelect.excluded().toString()).toEqual('');
expect(multiSelect.selected().toString()).toEqual('1,2,3,4');
});
Expand All @@ -93,7 +93,7 @@ define([
id: 6
}]);
multiSelect.selected.push(6);
expect(multiSelect.allSelected()).toBeFalsy();
expect(multiSelect.allSelected()).toBeUndefined();
expect(multiSelect.excluded().toString()).toEqual('5');
expect(multiSelect.selected().toString()).toEqual('3,4,6');
});
Expand All @@ -112,7 +112,7 @@ define([
multiSelect.selectPage();
multiSelect.selected.remove(4); // remove second

expect(multiSelect.allSelected()).toBeFalsy();
expect(multiSelect.allSelected()).toBeUndefined();
expect(multiSelect.excluded().toString()).toEqual('4');
expect(multiSelect.selected().toString()).toEqual('3');
});
Expand All @@ -130,7 +130,7 @@ define([
id: 4
}]);

expect(multiSelect.allSelected()).toBeFalsy();
expect(multiSelect.allSelected()).toBeUndefined();
expect(multiSelect.excluded().toString()).toEqual('');
expect(multiSelect.selected().toString()).toEqual('3,4,1,2');
});
Expand Down Expand Up @@ -168,7 +168,7 @@ define([
id: 6
}]);

expect(multiSelect.allSelected()).toBeFalsy();
expect(multiSelect.allSelected()).toBeUndefined();
expect(multiSelect.excluded().toString()).toEqual('3,4');
expect(multiSelect.selected().toString()).toEqual('5,6');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ define([
Component = new Masonry({
defaults: {
containerId: '#masonry_grid'
}
},
container: {}
});
});

Expand All @@ -62,6 +63,7 @@ define([
it('verify setLayoutstyles called and grid iniztilized', function () {
var setlayoutStyles = spyOn(Component, 'setLayoutStyles');

Object.defineProperty(Component.container, 'clientWidth', {value: '', configurable: true});
expect(Component).toBeDefined();
Component.containerId = 'masonry_grid';
Component.initComponent(rows);
Expand All @@ -75,6 +77,8 @@ define([
var setLayoutStyles = spyOn(Component, 'setLayoutStyles');

Component.initComponent(rows);
Component.container = {};
Object.defineProperty(Component.container, 'clientWidth', {value: '', configurable: true});
window.dispatchEvent(new Event('resize'));
expect(setLayoutStyles).toHaveBeenCalled();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* See COPYING.txt for license details.
*/

/* eslint-disable max-nested-callbacks */
define([
'underscore',
'Magento_Ui/js/grid/sticky/sticky'
Expand Down Expand Up @@ -46,6 +47,7 @@ define([
expect(stickyObj.initListeners).toHaveBeenCalled();
});
it('has initOnScroll method', function () {
spyOn(document, 'addEventListener').and.callFake(function () {});
stickyObj.initOnScroll();
expect(stickyObj.lastHorizontalScrollPos).toBeDefined();
});
Expand Down
Loading

0 comments on commit a706ccd

Please sign in to comment.