|
4 | 4 | */
|
5 | 5 |
|
6 | 6 | define([
|
7 |
| - 'Magento_Checkout/js/checkout-data', |
8 |
| - 'Magento_Customer/js/customer-data' |
9 |
| -], function (checkoutData, storage) { |
| 7 | + 'squire' |
| 8 | +], function (Squire) { |
10 | 9 | 'use strict';
|
11 | 10 |
|
12 | 11 | describe('Magento_Checkout/js/checkout-data', function () {
|
13 |
| - let cacheKey = 'checkout-data', |
| 12 | + let checkoutData, |
| 13 | + cacheKey = 'checkout-data', |
14 | 14 | testData = {
|
15 | 15 | shippingAddressFromData: {base: {address1: 'address1'}}
|
16 | 16 | },
|
17 | 17 |
|
18 | 18 | /** Stub */
|
19 | 19 | getStorageData = function () {
|
20 |
| - return testData; |
| 20 | + return function () { |
| 21 | + return testData; |
| 22 | + }; |
| 23 | + }, |
| 24 | + injector = new Squire(), |
| 25 | + mocks = { |
| 26 | + 'Magento_Customer/js/customer-data': { |
| 27 | + /** Method stub. */ |
| 28 | + set: jasmine.createSpy(), |
| 29 | + get: jasmine.createSpy().and.callFake(getStorageData) |
| 30 | + }, |
| 31 | + 'jquery/jquery-storageapi': jasmine.createSpy(), |
| 32 | + 'mageUtils': jasmine.createSpy() |
21 | 33 | };
|
22 | 34 |
|
23 | 35 | window.checkoutConfig = {
|
24 | 36 | websiteCode: 'base'
|
25 | 37 | };
|
26 | 38 |
|
27 |
| - beforeEach(function () { |
28 |
| - spyOn(storage, 'set'); |
| 39 | + beforeEach(function (done) { |
| 40 | + injector.mock(mocks); |
| 41 | + injector.require([ |
| 42 | + 'Magento_Checkout/js/checkout-data' |
| 43 | + ], function (Constructor) { |
| 44 | + checkoutData = Constructor; |
| 45 | + done(); |
| 46 | + }); |
29 | 47 | });
|
30 | 48 |
|
31 | 49 | it('should save selected shipping address per website', function () {
|
32 | 50 | checkoutData.setShippingAddressFromData({address1: 'address1'});
|
33 |
| - expect(storage.set).toHaveBeenCalledWith(cacheKey, jasmine.objectContaining(testData)); |
34 |
| - }); |
35 |
| - |
36 |
| - it('should return null if no shipping address data exists', function () { |
37 |
| - expect(checkoutData.getShippingAddressFromData()).toBeNull(); |
| 51 | + expect(mocks['Magento_Customer/js/customer-data'].set). |
| 52 | + toHaveBeenCalledWith(cacheKey, jasmine.objectContaining(testData)); |
38 | 53 | });
|
39 | 54 |
|
40 | 55 | it('should get shipping address from data per website', function () {
|
41 |
| - spyOn(storage, 'get').and.returnValue(getStorageData); |
42 | 56 | let address = checkoutData.getShippingAddressFromData();
|
43 | 57 |
|
44 | 58 | expect(address).toEqual(testData.shippingAddressFromData.base);
|
|
0 commit comments