Canh Ngo pushed to branch feature/cmng-psp1-CHANNELMGR-598 at cms-community / hippo-addon-channel-manager
Commits: 51c17ae2 by Canh Ngo at 2016-04-29T12:30:44+02:00 CHANNELMGR-598: improved unit-tests with simulated click events - - - - - 2 changed files: - frontend-ng/src/angularjs/channel/actions/channelActions.spec.js - frontend-ng/src/angularjs/channel/actions/edit/edit.spec.js Changes: ===================================== frontend-ng/src/angularjs/channel/actions/channelActions.spec.js ===================================== --- a/frontend-ng/src/angularjs/channel/actions/channelActions.spec.js +++ b/frontend-ng/src/angularjs/channel/actions/channelActions.spec.js @@ -20,6 +20,7 @@ describe('ChannelActions', () => { let $rootScope; let $compile; let $scope; + let $element; beforeEach(() => { module('hippo-cm'); @@ -33,7 +34,7 @@ describe('ChannelActions', () => { function compileDirectiveAndGetController() { $scope = $rootScope.$new(); $scope.onActionSelected = jasmine.createSpy('onActionSelected'); - const $element = angular.element('<channel-actions on-action-selected="onActionSelected(subpage)"></channel-actions>'); + $element = angular.element('<channel-actions on-action-selected="onActionSelected(subpage)"></channel-actions>'); $compile($element)($scope); $scope.$digest(); @@ -41,9 +42,10 @@ describe('ChannelActions', () => { } it('calls the on-action-selected callback when clicking the button', () => { - const ChannelActionsCtrl = compileDirectiveAndGetController(); + compileDirectiveAndGetController(); + + $element.find('.qa-button-channel').click(); - ChannelActionsCtrl.edit(); expect($scope.onActionSelected).toHaveBeenCalledWith('channel-edit'); }); }); ===================================== frontend-ng/src/angularjs/channel/actions/edit/edit.spec.js ===================================== --- a/frontend-ng/src/angularjs/channel/actions/edit/edit.spec.js +++ b/frontend-ng/src/angularjs/channel/actions/edit/edit.spec.js @@ -21,6 +21,7 @@ describe('ChannelActionEdit', () => { let $rootScope; let $compile; let $translate; + let $element; let ChannelService; beforeEach(() => { @@ -40,7 +41,7 @@ describe('ChannelActionEdit', () => { function compileDirectiveAndGetController() { $scope = $rootScope.$new(); $scope.onDone = jasmine.createSpy('onDone'); - const $element = angular.element('<channel-edit on-done="onDone()"> </channel-edit>'); + $element = angular.element('<channel-edit on-done="onDone()"></channel-edit>'); $compile($element)($scope); $scope.$digest(); @@ -54,17 +55,19 @@ describe('ChannelActionEdit', () => { expect($translate.instant).toHaveBeenCalledWith('SUBPAGE_CHANNEL_EDIT_TITLE', { channelName: 'test-name' }); }); - it('returns to the main page when clicking the back button', () => { - const ChannelEditCtrl = compileDirectiveAndGetController(); + it('notifies the event "on-done" when clicking the back button', () => { + compileDirectiveAndGetController(); + + $element.find('.qa-button-back').click(); - ChannelEditCtrl.back(); expect($scope.onDone).toHaveBeenCalled(); }); - it('returns to the main page when clicking the save button', () => { - const ChannelEditCtrl = compileDirectiveAndGetController(); + it('notifies the event "on-done" when clicking the save button', () => { + compileDirectiveAndGetController(); + + $element.find('.qa-save').click(); - ChannelEditCtrl.save(); expect($scope.onDone).toHaveBeenCalled(); }); }); View it on GitLab: https://code.onehippo.org/cms-community/hippo-addon-channel-manager/commit/51c17ae28e72d46d40338d780f9cbc161db4d86e
_______________________________________________ Hippocms-svn mailing list Hippocms-svn@lists.onehippo.org https://lists.onehippo.org/mailman/listinfo/hippocms-svn