-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MC-34415: Shopping Cart is not empty after removing item
- Loading branch information
Showing
6 changed files
with
262 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/empty-cart.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
/* eslint-disable max-nested-callbacks */ | ||
/*jscs:disable jsDoc*/ | ||
define([ | ||
'squire', 'jquery', 'ko' | ||
], function (Squire, $, ko) { | ||
'use strict'; | ||
|
||
describe('Magento_Checkout/js/empty-cart', function () { | ||
var injector = new Squire(), | ||
cartData = ko.observable({}), | ||
mocks = { | ||
'Magento_Customer/js/customer-data': { | ||
get: jasmine.createSpy('get', function () { | ||
return cartData; | ||
}).and.callThrough(), | ||
reload: jasmine.createSpy(), | ||
getInitCustomerData: function () {} | ||
} | ||
}, | ||
deferred, | ||
emptyCart; | ||
|
||
beforeEach(function (done) { | ||
injector.mock(mocks); | ||
injector.require(['Magento_Checkout/js/empty-cart'], function (instance) { | ||
emptyCart = instance; | ||
done(); | ||
}); | ||
}); | ||
|
||
afterEach(function () { | ||
try { | ||
injector.clean(); | ||
injector.remove(); | ||
} catch (e) {} | ||
|
||
cartData({}); | ||
}); | ||
|
||
describe('Check Cart data preparation process', function () { | ||
it('Tests that Cart data is NOT checked before initialization', function () { | ||
spyOn(mocks['Magento_Customer/js/customer-data'], 'getInitCustomerData').and.callFake(function () { | ||
deferred = $.Deferred(); | ||
|
||
return deferred.promise(); | ||
}); | ||
expect(emptyCart()).toBe(undefined); | ||
|
||
expect(mocks['Magento_Customer/js/customer-data'].get).toHaveBeenCalledWith('cart'); | ||
expect(mocks['Magento_Customer/js/customer-data'].getInitCustomerData).toHaveBeenCalled(); | ||
expect(mocks['Magento_Customer/js/customer-data'].reload).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('Tests that Cart data does NOT reload if there are no items in it', function () { | ||
spyOn(mocks['Magento_Customer/js/customer-data'], 'getInitCustomerData').and.callFake(function () { | ||
deferred = $.Deferred(); | ||
|
||
deferred.resolve(); | ||
|
||
return deferred.promise(); | ||
}); | ||
cartData({ | ||
items: [] | ||
}); | ||
emptyCart(); | ||
|
||
expect(mocks['Magento_Customer/js/customer-data'].get).toHaveBeenCalledWith('cart'); | ||
expect(mocks['Magento_Customer/js/customer-data'].reload).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('Tests that Cart data is checked only after initialization', function () { | ||
spyOn(mocks['Magento_Customer/js/customer-data'], 'getInitCustomerData').and.callFake(function () { | ||
deferred = $.Deferred(); | ||
|
||
return deferred.promise(); | ||
}); | ||
cartData({ | ||
items: [1] | ||
}); | ||
emptyCart(); | ||
|
||
expect(mocks['Magento_Customer/js/customer-data'].get).toHaveBeenCalledWith('cart'); | ||
expect(mocks['Magento_Customer/js/customer-data'].reload).not.toHaveBeenCalled(); | ||
|
||
deferred.resolve(); | ||
|
||
expect(mocks['Magento_Customer/js/customer-data'].reload).toHaveBeenCalledWith(['cart'], false); | ||
}); | ||
|
||
it('Tests that Cart data reloads if it has items', function () { | ||
spyOn(mocks['Magento_Customer/js/customer-data'], 'getInitCustomerData').and.callFake(function () { | ||
deferred = $.Deferred(); | ||
|
||
deferred.resolve(); | ||
|
||
return deferred.promise(); | ||
}); | ||
cartData({ | ||
items: [1] | ||
}); | ||
emptyCart(); | ||
|
||
expect(mocks['Magento_Customer/js/customer-data'].get).toHaveBeenCalledWith('cart'); | ||
expect(mocks['Magento_Customer/js/customer-data'].reload).toHaveBeenCalledWith(['cart'], false); | ||
}); | ||
}); | ||
}); | ||
}); |
110 changes: 110 additions & 0 deletions
110
dev/tests/js/jasmine/tests/app/code/Magento/Multishipping/frontend/js/multi-shipping.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
/* eslint-disable max-nested-callbacks */ | ||
define([ | ||
'squire', | ||
'jquery', | ||
'ko', | ||
'multiShipping' | ||
], function (Squire, $, ko, MultiShipping) { | ||
'use strict'; | ||
|
||
describe('Magento_Multishipping/js/multi-shipping', function () { | ||
var injector = new Squire(), | ||
Obj; | ||
|
||
describe('Check Cart data preparation process', function () { | ||
var customerData = ko.observable({}), | ||
mocks = { | ||
'Magento_Customer/js/customer-data': { | ||
get: jasmine.createSpy('get', function () { | ||
return customerData; | ||
}).and.callThrough(), | ||
reload: jasmine.createSpy() | ||
} | ||
}, | ||
summaryCount = {}; | ||
|
||
beforeEach(function (done) { | ||
injector.mock(mocks); | ||
injector.require(['multiShipping'], function (Instance) { | ||
Obj = Instance; | ||
done(); | ||
}); | ||
}); | ||
|
||
afterEach(function () { | ||
try { | ||
injector.clean(); | ||
injector.remove(); | ||
} catch (e) {} | ||
|
||
customerData({}); | ||
}); | ||
|
||
it('Prepare Cart data with the same items qty', function () { | ||
summaryCount['summary_count'] = 0; | ||
customerData(summaryCount); | ||
new Obj({}); | ||
|
||
expect(mocks['Magento_Customer/js/customer-data'].get).toHaveBeenCalledWith('cart'); | ||
expect(mocks['Magento_Customer/js/customer-data'].reload).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('Prepare Cart data with different items qty', function () { | ||
summaryCount['summary_count'] = 1; | ||
customerData(summaryCount); | ||
new Obj({}); | ||
|
||
expect(mocks['Magento_Customer/js/customer-data'].get).toHaveBeenCalledWith('cart'); | ||
expect(mocks['Magento_Customer/js/customer-data'].reload).toHaveBeenCalledWith(['cart'], false); | ||
}); | ||
}); | ||
|
||
describe('Check Multishipping events', function () { | ||
var addNewAddressBtn, | ||
addressflag, | ||
canContinueBtn, | ||
canContinueFlag; | ||
|
||
beforeEach(function () { | ||
addNewAddressBtn = $('<button type="button" data-role="add-new-address"/>'); | ||
addressflag = $('<input type="hidden" value="0" id="add_new_address_flag"/>'); | ||
canContinueBtn = $('<button type="submit" data-role="can-continue" data-flag="1"/>'); | ||
canContinueFlag = $('<input type="hidden" value="0" id="can_continue_flag"/>'); | ||
$(document.body).append(addNewAddressBtn) | ||
.append(addressflag) | ||
.append(canContinueBtn) | ||
.append(canContinueFlag); | ||
}); | ||
|
||
afterEach(function () { | ||
addNewAddressBtn.remove(); | ||
addressflag.remove(); | ||
canContinueBtn.remove(); | ||
canContinueFlag.remove(); | ||
}); | ||
|
||
it('Check add new address event', function () { | ||
Obj = new MultiShipping({}); | ||
Obj.element = jasmine.createSpyObj('element', ['submit']); | ||
addNewAddressBtn.click(); | ||
|
||
expect(Obj.element.submit).toHaveBeenCalled(); | ||
expect(addressflag.val()).toBe('1'); | ||
}); | ||
|
||
it('Check can continue event', function () { | ||
Obj = new MultiShipping({}); | ||
Obj.element = jasmine.createSpyObj('element', ['submit']); | ||
canContinueBtn.click(); | ||
|
||
expect(Obj.element.submit).not.toHaveBeenCalled(); | ||
expect(canContinueFlag.val()).toBe('1'); | ||
}); | ||
}); | ||
}); | ||
}); |