|
| 1 | +/** |
| 2 | + * Copyright © Magento, Inc. All rights reserved. |
| 3 | + * See COPYING.txt for license details. |
| 4 | + */ |
| 5 | + |
| 6 | +/* eslint-disable max-nested-callbacks */ |
| 7 | +/*jscs:disable jsDoc*/ |
| 8 | +define([ |
| 9 | + 'squire', 'jquery', 'ko' |
| 10 | +], function (Squire, $, ko) { |
| 11 | + 'use strict'; |
| 12 | + |
| 13 | + var injector = new Squire(), |
| 14 | + cartData = { |
| 15 | + 'subtotalAmount': 10 |
| 16 | + }, |
| 17 | + cart = ko.observable(cartData), |
| 18 | + cartDataTwo = { |
| 19 | + 'subtotalAmount': NaN |
| 20 | + }, |
| 21 | + cartTwo = ko.observable(cartDataTwo), |
| 22 | + mocks = { |
| 23 | + 'Magento_Checkout/js/model/quote': { |
| 24 | + totals: ko.observable({ |
| 25 | + 'subtotal': 4 |
| 26 | + }) |
| 27 | + }, |
| 28 | + 'Magento_Customer/js/customer-data': { |
| 29 | + get: function () { |
| 30 | + return cart; |
| 31 | + }, |
| 32 | + reload: jasmine.createSpy(), |
| 33 | + getInitCustomerData: function () {} |
| 34 | + } |
| 35 | + }, |
| 36 | + mocksTwo = { |
| 37 | + 'Magento_Checkout/js/model/quote': { |
| 38 | + totals: ko.observable({ |
| 39 | + 'subtotal': 10 |
| 40 | + }) |
| 41 | + }, |
| 42 | + 'Magento_Customer/js/customer-data': { |
| 43 | + get: function () { |
| 44 | + return cartTwo; |
| 45 | + }, |
| 46 | + reload: jasmine.createSpy(), |
| 47 | + getInitCustomerData: function () {} |
| 48 | + } |
| 49 | + }; |
| 50 | + |
| 51 | + afterEach(function () { |
| 52 | + try { |
| 53 | + injector.clean(); |
| 54 | + injector.remove(); |
| 55 | + } catch (e) {} |
| 56 | + }); |
| 57 | + |
| 58 | + describe('Test that customer data is reloaded when quote subtotal and cart subtotal are different', function () { |
| 59 | + beforeEach(function (done) { |
| 60 | + injector.mock(mocks); |
| 61 | + injector.require(['Magento_Checkout/js/model/totals'], function () { |
| 62 | + done(); |
| 63 | + }); |
| 64 | + }); |
| 65 | + it('Test that customer data is reloaded when quote subtotal and cart subtotal are different', function () { |
| 66 | + expect(mocks['Magento_Checkout/js/model/quote'].totals().subtotal).toBe(4); |
| 67 | + expect(cart().subtotalAmount).toBe(10); |
| 68 | + expect(mocks['Magento_Customer/js/customer-data'].reload).toHaveBeenCalled(); |
| 69 | + }); |
| 70 | + }); |
| 71 | + |
| 72 | + describe('Test that customer data is not reloaded when cart subtotal is NaN', function () { |
| 73 | + beforeEach(function (done) { |
| 74 | + injector.mock(mocksTwo); |
| 75 | + injector.require(['Magento_Checkout/js/model/totals'], function () { |
| 76 | + done(); |
| 77 | + }); |
| 78 | + }); |
| 79 | + it('Test that customer data is not reloaded when cart subtotal is NaN', function () { |
| 80 | + expect(mocksTwo['Magento_Checkout/js/model/quote'].totals().subtotal).toBe(10); |
| 81 | + expect(cartTwo().subtotalAmount).toBeNaN(); |
| 82 | + expect(mocksTwo['Magento_Customer/js/customer-data'].reload).not.toHaveBeenCalled(); |
| 83 | + }); |
| 84 | + }); |
| 85 | +}); |
| 86 | + |
0 commit comments