|
| 1 | +/** |
| 2 | + * Copyright © 2013-2017 Magento, Inc. All rights reserved. |
| 3 | + * See COPYING.txt for license details. |
| 4 | + */ |
| 5 | + |
| 6 | +/* eslint-disable max-nested-callbacks */ |
| 7 | +define([ |
| 8 | + 'jquery', |
| 9 | + 'squire', |
| 10 | + 'ko', |
| 11 | + 'Magento_Ui/js/model/messages' |
| 12 | +], function ($, Squire, ko, Messages) { |
| 13 | + 'use strict'; |
| 14 | + |
| 15 | + describe('Magento_Braintree/js/view/payment/method-renderer/cc-form', function () { |
| 16 | + var injector = new Squire(), |
| 17 | + mocks = { |
| 18 | + 'Magento_Checkout/js/model/quote': { |
| 19 | + billingAddress: ko.observable(), |
| 20 | + shippingAddress: ko.observable(), |
| 21 | + paymentMethod: ko.observable() |
| 22 | + }, |
| 23 | + 'Magento_Braintree/js/view/payment/validator-handler': jasmine.createSpyObj( |
| 24 | + 'validator-handler', |
| 25 | + ['initialize'] |
| 26 | + ), |
| 27 | + 'Magento_Braintree/js/view/payment/adapter': jasmine.createSpyObj( |
| 28 | + 'adapter', |
| 29 | + ['setup', 'setConfig'] |
| 30 | + ) |
| 31 | + }, |
| 32 | + braintreeCcForm; |
| 33 | + |
| 34 | + beforeAll(function (done) { |
| 35 | + window.checkoutConfig = { |
| 36 | + quoteData: {}, |
| 37 | + payment: { |
| 38 | + braintree: { |
| 39 | + hasFraudProtection: true |
| 40 | + } |
| 41 | + } |
| 42 | + }; |
| 43 | + injector.mock(mocks); |
| 44 | + injector.require( |
| 45 | + ['Magento_Braintree/js/view/payment/method-renderer/cc-form'], |
| 46 | + function (Constr) { |
| 47 | + braintreeCcForm = new Constr({ |
| 48 | + provider: 'provName', |
| 49 | + name: 'test', |
| 50 | + index: 'test' |
| 51 | + }); |
| 52 | + |
| 53 | + done(); |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + it('Check if payment code and message container are restored after onActiveChange call.', function () { |
| 58 | + var expectedMessageContainer = braintreeCcForm.messageContainer; |
| 59 | + |
| 60 | + braintreeCcForm.code = 'braintree-vault'; |
| 61 | + braintreeCcForm.messageContainer = new Messages(); |
| 62 | + |
| 63 | + braintreeCcForm.onActiveChange(true); |
| 64 | + |
| 65 | + expect(braintreeCcForm.getCode()).toEqual('braintree'); |
| 66 | + expect(braintreeCcForm.messageContainer).toEqual(expectedMessageContainer); |
| 67 | + }); |
| 68 | + }); |
| 69 | +}); |
0 commit comments