From 20d82cde5077356bf02b409e93165478f7cebabc Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 30 Aug 2017 12:30:48 +0200 Subject: [PATCH] checkPaymentChanges unit test --- .../src/billing-data/billing-data.spec.js | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/client/client/src/billing-data/billing-data.spec.js b/client/client/src/billing-data/billing-data.spec.js index e6984da89..b6adf57d5 100644 --- a/client/client/src/billing-data/billing-data.spec.js +++ b/client/client/src/billing-data/billing-data.spec.js @@ -11,9 +11,12 @@ describe('Component vnClientBillingData', () => { beforeEach(angular.mock.inject(function(_$componentController_, $rootScope) { $componentController = _$componentController_; $scope = $rootScope.$new(); - // try to instanciate the actual watcher instead of submit spy usage. + // should add instanciate of actual watcher instead of submit() spy usage. let submit = jasmine.createSpy('submit').and.returnValue(Promise.resolve()); + // should add instanciate of actual sendMail instead of show() spy usage. + let show = jasmine.createSpy('show'); $scope.watcher = {submit}; + $scope.sendMail = {show}; })); describe('copyData()', () => { @@ -45,4 +48,23 @@ describe('Component vnClientBillingData', () => { }); }); }); + + describe('checkPaymentChanges()', () => { + it(`should not call sendMail.show() if there are no changes on billing data`, () => { + let controller = $componentController('vnClientBillingData', {$scope: $scope}); + controller.billData = {marvelHero: 'Silver Surfer'}; + controller.client = {marvelHero: 'Silver Surfer'}; + controller.checkPaymentChanges(); + expect(controller.$.sendMail.show).not.toHaveBeenCalled(); + }); + + it(`should call sendMail.show() if there are changes on billing data`, () => { + let controller = $componentController('vnClientBillingData', {$scope: $scope}); + controller.billData = {marvelHero: 'Silver Surfer'}; + controller.client = {marvelHero: 'Spider-Man'}; + controller.checkPaymentChanges(); + expect(controller.$.sendMail.show).toHaveBeenCalled(); + }); + }); }); +