From 47edeb9f2e43bd28b6573bb314e5d689752f2ac8 Mon Sep 17 00:00:00 2001 From: plondon Date: Fri, 22 Jan 2016 11:24:38 -0500 Subject: [PATCH] test(bcAsyncInput): add tests for cancel and save --- tests/directives/bc-async-input_spec.coffee | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/directives/bc-async-input_spec.coffee b/tests/directives/bc-async-input_spec.coffee index ee2b9209eb..de3321aaa8 100644 --- a/tests/directives/bc-async-input_spec.coffee +++ b/tests/directives/bc-async-input_spec.coffee @@ -117,3 +117,26 @@ describe 'bcAsyncInput Directive', -> it 'should return true if the view is equal to the model', -> isoScope.bcAsyncForm.input.$setViewValue('oldValue') expect(isoScope.bcAsyncForm.$valid).toBe(false) + + describe 'cancel', -> + + beforeEach -> + isoScope.bcAsyncForm.input.$setViewValue('newValue') + isoScope.cancel() + + it 'should not save if cancelled', -> + expect(isoScope.form.newValue).toBe('oldValue') + + it 'should be pristine', -> + expect(isoScope.bcAsyncForm.$pristine).toBe(true) + + describe 'save', -> + + beforeEach -> + isoScope.onSave = (newValue, success, error) -> + success() + + it 'should validate when save() is called', -> + spyOn(isoScope, 'validate').and.callThrough() + isoScope.save() + expect(isoScope.validate).toHaveBeenCalled()