From 4e1d2db3cb607d94c924aa929922919b555ba187 Mon Sep 17 00:00:00 2001 From: Carlos Date: Mon, 23 Oct 2017 10:47:56 +0200 Subject: [PATCH] unit test for dialog directive plus small refactors --- client/core/src/dialog/dialog.spec.js | 2 - client/core/src/directives/dialog.js | 3 +- .../core/src/directives/specs/dialog.spec.js | 37 +++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 client/core/src/directives/specs/dialog.spec.js diff --git a/client/core/src/dialog/dialog.spec.js b/client/core/src/dialog/dialog.spec.js index c595f37f6..e13242d6b 100644 --- a/client/core/src/dialog/dialog.spec.js +++ b/client/core/src/dialog/dialog.spec.js @@ -1,5 +1,3 @@ -import './dialog.js'; - describe('Component vnDialog', () => { let $componentController; let $element; diff --git a/client/core/src/directives/dialog.js b/client/core/src/directives/dialog.js index d4ac65b45..5ee10258e 100644 --- a/client/core/src/directives/dialog.js +++ b/client/core/src/directives/dialog.js @@ -11,7 +11,8 @@ export function directive() { restrict: 'A', link: function($scope, $element, $attrs) { $element.on('click', function(event) { - let dialog = $scope[kebabToCamel($attrs.vnDialog)]; + let dialogKey = kebabToCamel($attrs.vnDialog); + let dialog = $scope[dialogKey]; if (dialog instanceof Dialog) dialog.show(); event.preventDefault(); diff --git a/client/core/src/directives/specs/dialog.spec.js b/client/core/src/directives/specs/dialog.spec.js new file mode 100644 index 000000000..38d4ed9e2 --- /dev/null +++ b/client/core/src/directives/specs/dialog.spec.js @@ -0,0 +1,37 @@ +describe('Directive dialog', () => { + let $scope; + let $element; + let element; + let compile; + let $componentController; + let controller; + + beforeEach(() => { + angular.mock.module('client'); + }); + + compile = _element => { + inject(($compile, $rootScope) => { + $scope = $rootScope.$new(); + $scope.myDialog = controller; + element = angular.element(_element); + $compile(element)($scope); + $scope.$digest(); + }); + }; + + beforeEach(angular.mock.inject(_$componentController_ => { + $componentController = _$componentController_; + $element = angular.element('
'); + controller = $componentController('vnDialog', {$element}); + })); + + it('should call show() function if dialog is a instance of vnDialog', () => { + let html = `
`; + spyOn(controller, 'show'); + compile(html); + element[0].click(); + + expect(controller.show).toHaveBeenCalledWith(); + }); +});