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(); + }); +});