-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #387 - Configuration of default directive behaviour
- Loading branch information
1 parent
5c1d0bd
commit daf9be9
Showing
5 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Permission module configuration provider | ||
* | ||
* @name permission.permissionConfigProvider | ||
*/ | ||
function permissionConfig() { | ||
'ngInject'; | ||
|
||
this.defaultOnAuthorizedMethod = 'showElement'; | ||
this.defaultOnUnauthorizedMethod = 'hideElement'; | ||
|
||
/** | ||
* Methods allowing to alter default directive onAuthorized behaviour in permission directive | ||
* | ||
* @param onAuthorizedMethod {String} One of permission.PermPermissionStrategies method names | ||
*/ | ||
this.setDefaultOnAuthorizedMethod = function (onAuthorizedMethod) { | ||
this.defaultOnAuthorizedMethod = onAuthorizedMethod; | ||
}; | ||
|
||
/** | ||
* Methods allowing to alter default directive onUnauthorized behaviour in permission directive | ||
* | ||
* @param onUnauthorizedMethod {String} One of permission.PermPermissionStrategies method names | ||
*/ | ||
this.setDefaultOnUnauthorizedMethod = function (onUnauthorizedMethod) { | ||
this.defaultOnUnauthorizedMethod = onUnauthorizedMethod; | ||
}; | ||
|
||
this.$get = function () { | ||
return this; | ||
} | ||
} | ||
|
||
angular | ||
.module('permission') | ||
.provider('permissionConfig', permissionConfig); |
61 changes: 61 additions & 0 deletions
61
test/unit/permission/configuration/permissionConfig.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
describe('permission', function () { | ||
'use strict'; | ||
|
||
describe('configuration', function () { | ||
describe('provider: permissionConfig', function () { | ||
var permissionConfigProvider; | ||
|
||
beforeEach(function () { | ||
module('permission'); | ||
}); | ||
|
||
beforeEach(function () { | ||
module(['permissionConfigProvider', function (_permissionConfigProvider) { | ||
permissionConfigProvider = _permissionConfigProvider; | ||
}]); | ||
}); | ||
|
||
beforeEach(inject()); | ||
|
||
describe('method: setDefaultOnAuthorizedMethod', function () { | ||
it('should have default authorized method set to showElement', function () { | ||
// GIVEN | ||
// WHEN | ||
//THEN | ||
expect(permissionConfigProvider.$get().defaultOnAuthorizedMethod).toBe('showElement'); | ||
}); | ||
|
||
it('should set custom default authorized method when provided', function () { | ||
// GIVEN | ||
var onAuthorizedMethodName = 'customOnAuthorizedMethod'; | ||
|
||
// WHEN | ||
permissionConfigProvider.setDefaultOnAuthorizedMethod(onAuthorizedMethodName); | ||
|
||
//THEN | ||
expect(permissionConfigProvider.$get().defaultOnAuthorizedMethod).toBe(onAuthorizedMethodName); | ||
}); | ||
}); | ||
|
||
describe('method: setDefaultOnUnauthorizedMethod', function () { | ||
it('should have default unauthorized method set to hideElement', function () { | ||
// GIVEN | ||
// WHEN | ||
//THEN | ||
expect(permissionConfigProvider.$get().defaultOnUnauthorizedMethod).toBe('hideElement'); | ||
}); | ||
|
||
it('should set custom default unauthorized method when provided', function () { | ||
// GIVEN | ||
var onUnauthorizedMethodName = 'customOnUnauthorizedMethod'; | ||
|
||
// WHEN | ||
permissionConfigProvider.setDefaultOnUnauthorizedMethod(onUnauthorizedMethodName); | ||
|
||
//defaultOnUnauthorizedMethod | ||
expect(permissionConfigProvider.$get().defaultOnUnauthorizedMethod).toBe(onUnauthorizedMethodName); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |