|
| 1 | +/** |
| 2 | + * Copyright © Magento, Inc. All rights reserved. |
| 3 | + * See COPYING.txt for license details. |
| 4 | + */ |
| 5 | + |
| 6 | +define([ |
| 7 | + 'squire', |
| 8 | + 'ko' |
| 9 | +], function (Squire, ko) { |
| 10 | + 'use strict'; |
| 11 | + |
| 12 | + var injector = new Squire(), |
| 13 | + vault, |
| 14 | + mocks = { |
| 15 | + 'Magento_Checkout/js/model/checkout-data-resolver': { |
| 16 | + resolveBillingAddress: jasmine.createSpy().and.returnValue(true) |
| 17 | + }, |
| 18 | + 'Magento_Checkout/js/checkout-data': { |
| 19 | + setSelectedPaymentMethod: jasmine.createSpy().and.returnValue(false) |
| 20 | + }, |
| 21 | + 'Magento_Checkout/js/model/quote': { |
| 22 | + billingAddress: ko.observable(null), |
| 23 | + shippingAddress: ko.observable(null), |
| 24 | + paymentMethod: ko.observable(null), |
| 25 | + totals: ko.observable({}) |
| 26 | + } |
| 27 | + }, |
| 28 | + billingAddress = { |
| 29 | + city: 'Culver City', |
| 30 | + company: 'Magento', |
| 31 | + country_id: 'US',// jscs:ignore requireCamelCaseOrUpperCaseIdentifiers |
| 32 | + firstname: 'John', |
| 33 | + lastname: 'Doe', |
| 34 | + postcode: '90230', |
| 35 | + region: '', |
| 36 | + region_id: '12',// jscs:ignore requireCamelCaseOrUpperCaseIdentifiers |
| 37 | + street: { |
| 38 | + 0: '6161 West Centinela Avenue', |
| 39 | + 1: '' |
| 40 | + }, |
| 41 | + telephone: '+15555555555' |
| 42 | + }; |
| 43 | + |
| 44 | + beforeEach(function (done) { |
| 45 | + window.checkoutConfig = { |
| 46 | + quoteData: { |
| 47 | + /* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */ |
| 48 | + entity_Id: 1 |
| 49 | + }, |
| 50 | + formKey: 'formKey' |
| 51 | + }; |
| 52 | + injector.mock(mocks); |
| 53 | + injector.require(['Magento_Vault/js/view/payment/method-renderer/vault'], function (Constr) { |
| 54 | + var params = { |
| 55 | + index: 'vaultIndex', |
| 56 | + item: { |
| 57 | + method: 'vault' |
| 58 | + } |
| 59 | + }; |
| 60 | + |
| 61 | + vault = new Constr(params); |
| 62 | + // eslint-disable-next-line max-nested-callbacks |
| 63 | + /** Stub */ |
| 64 | + vault.isChecked = function () { |
| 65 | + return mocks['Magento_Checkout/js/model/quote'].paymentMethod() ? |
| 66 | + mocks['Magento_Checkout/js/model/quote'].paymentMethod().method : null; |
| 67 | + }; |
| 68 | + done(); |
| 69 | + }); |
| 70 | + }); |
| 71 | + |
| 72 | + afterEach(function () { |
| 73 | + try { |
| 74 | + injector.remove(); |
| 75 | + injector.clean(); |
| 76 | + } catch (e) { |
| 77 | + } |
| 78 | + mocks['Magento_Checkout/js/model/quote'].billingAddress(null); |
| 79 | + mocks['Magento_Checkout/js/model/quote'].paymentMethod(null); |
| 80 | + }); |
| 81 | + |
| 82 | + describe('Magento_Vault/js/view/payment/method-renderer/vault', function () { |
| 83 | + |
| 84 | + it('There is no payment method and billing address', function () { |
| 85 | + expect(vault.isButtonActive()).toBeFalsy(); |
| 86 | + |
| 87 | + expect(vault.isActive()).toBeFalsy(); |
| 88 | + expect(vault.isPlaceOrderActionAllowed()).toBeFalsy(); |
| 89 | + }); |
| 90 | + |
| 91 | + it('Payment method exist but place order action is not allowed', function () { |
| 92 | + vault.selectPaymentMethod(); |
| 93 | + expect(mocks['Magento_Checkout/js/model/quote'].paymentMethod().method).toEqual('vaultIndex'); |
| 94 | + |
| 95 | + expect(vault.isButtonActive()).toBeFalsy(); |
| 96 | + |
| 97 | + expect(vault.isActive()).toBeTruthy(); |
| 98 | + expect(vault.isPlaceOrderActionAllowed()).toBeFalsy(); |
| 99 | + |
| 100 | + }); |
| 101 | + |
| 102 | + it('Billing address exist but there is no selected payment method', function () { |
| 103 | + mocks['Magento_Checkout/js/model/quote'].billingAddress(billingAddress); |
| 104 | + |
| 105 | + expect(vault.isButtonActive()).toBeFalsy(); |
| 106 | + |
| 107 | + expect(vault.isActive()).toBeFalsy(); |
| 108 | + expect(vault.isPlaceOrderActionAllowed).toBeTruthy(); |
| 109 | + }); |
| 110 | + |
| 111 | + it('Button is active', function () { |
| 112 | + vault.selectPaymentMethod(); |
| 113 | + expect(mocks['Magento_Checkout/js/model/quote'].paymentMethod().method).toEqual('vaultIndex'); |
| 114 | + |
| 115 | + mocks['Magento_Checkout/js/model/quote'].billingAddress(billingAddress); |
| 116 | + |
| 117 | + expect(vault.isButtonActive()).toBeTruthy(); |
| 118 | + |
| 119 | + expect(vault.isActive()).toBeTruthy(); |
| 120 | + expect(vault.isPlaceOrderActionAllowed()).toBeTruthy(); |
| 121 | + }); |
| 122 | + }); |
| 123 | +}); |
0 commit comments