From cf3f511f4d4c3682dca6e7789c219a5d23ea511c Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 1 Oct 2020 23:04:11 +0100 Subject: [PATCH] Add directive spec to validate the dialog template is loaded on element click --- .../terms_and_conditions_warning.js.coffee | 5 +++-- ...terms_and_conditions_warning_spec.js.coffee | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 spec/javascripts/unit/admin/enterprises/directives/terms_and_conditions_warning_spec.js.coffee diff --git a/app/assets/javascripts/admin/enterprises/directives/terms_and_conditions_warning.js.coffee b/app/assets/javascripts/admin/enterprises/directives/terms_and_conditions_warning.js.coffee index 1072839def..d8aafe113d 100644 --- a/app/assets/javascripts/admin/enterprises/directives/terms_and_conditions_warning.js.coffee +++ b/app/assets/javascripts/admin/enterprises/directives/terms_and_conditions_warning.js.coffee @@ -7,8 +7,9 @@ angular.module("admin.enterprises").directive 'termsAndConditionsWarning', ($com scope.hold_file_input_and_show_warning_modal = (event) -> event.preventDefault() scope.template = $compile($templateCache.get('admin/modals/terms_and_conditions_warning.html'))(scope) - scope.template.dialog(DialogDefaults) - scope.template.dialog('open') + if scope.template.dialog + scope.template.dialog(DialogDefaults) + scope.template.dialog('open') scope.$apply() element.bind 'click', scope.hold_file_input_and_show_warning_modal diff --git a/spec/javascripts/unit/admin/enterprises/directives/terms_and_conditions_warning_spec.js.coffee b/spec/javascripts/unit/admin/enterprises/directives/terms_and_conditions_warning_spec.js.coffee new file mode 100644 index 0000000000..b7647024e2 --- /dev/null +++ b/spec/javascripts/unit/admin/enterprises/directives/terms_and_conditions_warning_spec.js.coffee @@ -0,0 +1,18 @@ +describe "termsAndConditionsWarning", -> + element = null + templatecache = null + + beforeEach -> + module('admin.enterprises') + + inject ($rootScope, $compile, $templateCache) -> + templatecache = $templateCache + el = angular.element("") + element = $compile(el)($rootScope) + $rootScope.$digest() + + describe "terms and conditions warning", -> + it "should load template", -> + spyOn(templatecache, 'get') + element.triggerHandler('click'); + expect(templatecache.get).toHaveBeenCalledWith('admin/modals/terms_and_conditions_warning.html')