Skip to content

Commit

Permalink
Merge pull request magento#5231 from magento-obsessive-owls/MC-30414
Browse files Browse the repository at this point in the history
[Owls] Fix flaky unit tests
  • Loading branch information
omiroshnichenko authored Jan 21, 2020
2 parents c2e2646 + a03804d commit 189dc56
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,24 @@ require.config({
}
});

define(['squire', 'ko', 'jquery', 'uiRegistry', 'jquery/validate'], function (Squire, ko, $, registry) {
define(['squire', 'ko', 'jquery', 'jquery/validate'], function (Squire, ko, $) {
'use strict';

var injector = new Squire(),
modalStub = {
openModal: jasmine.createSpy(),
closeModal: jasmine.createSpy()
},
country = {
/** Stub */
on: function () {},

/** Stub */
get: function () {},

/** Stub */
set: function () {}
},
mocks = {
'Magento_Customer/js/model/customer': {
isLoggedIn: ko.observable()
Expand All @@ -28,17 +38,7 @@ define(['squire', 'ko', 'jquery', 'uiRegistry', 'jquery/validate'], function (Sq
'Magento_Checkout/js/model/address-converter': jasmine.createSpy(),
'Magento_Checkout/js/model/quote': {
isVirtual: jasmine.createSpy(),
shippingMethod: ko.observable(),

/**
* Stub
*/
shippingAddress: function () {

return {
'countryId': 'AD'
};
}
shippingMethod: ko.observable()
},
'Magento_Checkout/js/action/create-shipping-address': jasmine.createSpy().and.returnValue(
jasmine.createSpyObj('newShippingAddress', ['getKey'])
Expand All @@ -62,7 +62,18 @@ define(['squire', 'ko', 'jquery', 'uiRegistry', 'jquery/validate'], function (Sq
'checkoutData',
['setSelectedShippingAddress', 'setNewCustomerShippingAddress', 'setSelectedShippingRate']
),
'Magento_Ui/js/lib/registry/registry': registry,
'Magento_Ui/js/lib/registry/registry': {
async: jasmine.createSpy().and.returnValue(function () {}),
create: jasmine.createSpy(),
set: jasmine.createSpy(),
get: jasmine.createSpy().and.callFake(function (query) {
if (query === 'test.shippingAddress.shipping-address-fieldset.country_id') {
return country;
} else if (query === 'checkout.errors') {
return {};
}
})
},
'Magento_Checkout/js/model/shipping-rate-service': jasmine.createSpy()
},
obj;
Expand All @@ -73,7 +84,6 @@ define(['squire', 'ko', 'jquery', 'uiRegistry', 'jquery/validate'], function (Sq
obj = new Constr({
provider: 'provName',
name: '',
parentName: 'test',
index: '',
popUpForm: {
options: {
Expand Down Expand Up @@ -174,16 +184,6 @@ define(['squire', 'ko', 'jquery', 'uiRegistry', 'jquery/validate'], function (Sq

describe('"validateShippingInformation" method', function () {
it('Check method call on negative cases.', function () {
/* jscs:disable */
var country = {
on: function () {},
get: function () {},
set: function () {}
};
/* jscs:enable */

registry.set('test.shippingAddress.shipping-address-fieldset.country_id', country);
registry.set('checkout.errors', {});
obj.source = {
get: jasmine.createSpy().and.returnValue(true),
set: jasmine.createSpy(),
Expand All @@ -199,20 +199,10 @@ define(['squire', 'ko', 'jquery', 'uiRegistry', 'jquery/validate'], function (Sq
expect(obj.validateShippingInformation()).toBeFalsy();
});
it('Check method call on positive case.', function () {
/* jscs:disable */
var country = {
on: function () {},
get: function () {},
set: function () {}
};
/* jscs:enable */

$('body').append('<form data-role="email-with-possible-login">' +
'<input type="text" name="username" />' +
'</form>');

registry.set('test.shippingAddress.shipping-address-fieldset.country_id', country);
registry.set('checkout.errors', {});
obj.source = {
get: jasmine.createSpy().and.returnValue(true),
set: jasmine.createSpy(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ define([

/*eslint max-nested-callbacks: ["error", 5]*/
describe('Signifyd device fingerprint client script', function () {
var originalTimeout;

beforeEach(function () {
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 12000;
});

afterEach(function () {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});

it('SIGNIFYD_GLOBAL object initialization check', function (done) {
var script = document.createElement('script');
Expand All @@ -32,7 +42,6 @@ define([
expect(signifyd.scriptTagHasLoaded()).toBe(true);
done();
}, 10000);

}, 12000);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,50 @@
* See COPYING.txt for license details.
*/

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

define([
'underscore',
'uiRegistry',
'Magento_Ui/js/form/form'
], function (_, registry, Constr) {
'squire'
], function (Squire) {
'use strict';

describe('Magento_Ui/js/form/form', function () {

var obj = new Constr({
provider: 'provName',
name: '',
index: ''
});

registry.set('provName', {
/** Stub */
on: function () {},

/** Stub */
get: function () {},

/** Stub */
set: function () {}
var injector = new Squire(),
mocks = {
'Magento_Ui/js/lib/registry/registry': {
/** Method stub. */
get: function () {
return {
get: jasmine.createSpy(),
set: jasmine.createSpy()
};
},
options: jasmine.createSpy(),
create: jasmine.createSpy(),
set: jasmine.createSpy(),
async: jasmine.createSpy()
}
},
obj,
dataScope = 'dataScope';

beforeEach(function (done) {
injector.mock(mocks);
injector.require([
'Magento_Ui/js/form/form'
], function (Constr) {
obj = new Constr({
provider: 'provName',
name: '',
index: '',
dataScope: dataScope
});

done();
});
});

describe('"initAdapter" method', function () {
Expand Down

0 comments on commit 189dc56

Please sign in to comment.