@@ -3,6 +3,7 @@ import * as vanilla from "../src/vanilla";
3
3
import { StateRegistry } from "../src/state/stateRegistry" ;
4
4
import { UrlRouter } from "../src/url/urlRouter" ;
5
5
import { UIRouterPlugin } from "../src/interface" ;
6
+ import { isArray } from "../src/common/predicates" ;
6
7
7
8
describe ( 'plugin api' , function ( ) {
8
9
let router : UIRouter ;
@@ -23,23 +24,25 @@ describe('plugin api', function () {
23
24
} ) ;
24
25
25
26
class FancyPluginClass implements UIRouterPlugin {
27
+ name = "fancypluginclass" ;
26
28
constructor ( public router : UIRouter ) { }
27
- name = "fancyplugin"
28
29
}
29
30
30
31
function FancyPluginConstructor ( router : UIRouter , options : any ) {
31
- this . name = "fancyplugin " ;
32
+ this . name = "fancypluginconstructor " ;
32
33
}
33
34
34
35
describe ( 'initialization' , ( ) => {
35
36
it ( 'should accept a plugin class' , ( ) => {
36
37
let plugin = router . plugin ( FancyPluginClass ) ;
37
38
expect ( plugin instanceof FancyPluginClass ) . toBeTruthy ( ) ;
39
+ expect ( plugin . name ) . toBe ( 'fancypluginclass' ) ;
38
40
} ) ;
39
41
40
42
it ( 'should accept a constructor function' , ( ) => {
41
43
let plugin = router . plugin ( FancyPluginConstructor ) ;
42
44
expect ( plugin instanceof FancyPluginConstructor ) . toBeTruthy ( ) ;
45
+ expect ( plugin . name ) . toBe ( 'fancypluginconstructor' ) ;
43
46
} ) ;
44
47
45
48
it ( 'should accept a factory function' , ( ) => {
@@ -48,6 +51,7 @@ describe('plugin api', function () {
48
51
}
49
52
let plugin = router . plugin ( factoryFn ) ;
50
53
expect ( plugin instanceof FancyPluginClass ) . toBeTruthy ( ) ;
54
+ expect ( plugin . name ) . toBe ( 'fancypluginclass' ) ;
51
55
} ) ;
52
56
53
57
it ( 'should return an instance of the plugin' , ( ) => {
@@ -77,9 +81,24 @@ describe('plugin api', function () {
77
81
78
82
describe ( 'getPlugin' , ( ) => {
79
83
it ( 'should return the plugin instance' , ( ) => {
80
- router . plugin ( ( ) => new FancyPluginClass ( router ) ) ;
81
- let plugin = router . getPlugin ( 'fancyplugin ' ) ;
84
+ router . plugin ( FancyPluginClass ) ;
85
+ let plugin = router . getPlugin ( 'fancypluginclass ' ) ;
82
86
expect ( plugin instanceof FancyPluginClass ) . toBeTruthy ( ) ;
83
87
} ) ;
88
+
89
+ it ( 'should return undefined if no pluginName is registered' , ( ) => {
90
+ router . plugin ( FancyPluginClass ) ;
91
+ let plugin = router . getPlugin ( 'notexists' ) ;
92
+ expect ( plugin ) . toBeUndefined ( ) ;
93
+ } ) ;
94
+
95
+ it ( 'should return all registered plugins when no pluginName is specified' , ( ) => {
96
+ router . plugin ( FancyPluginClass ) ;
97
+ router . plugin ( FancyPluginConstructor ) ;
98
+ let plugins = router . getPlugin ( ) ;
99
+ expect ( isArray ( plugins ) ) . toBeTruthy ( ) ;
100
+ expect ( plugins . pop ( ) instanceof FancyPluginConstructor ) . toBeTruthy ( ) ;
101
+ expect ( plugins . pop ( ) instanceof FancyPluginClass ) . toBeTruthy ( ) ;
102
+ } ) ;
84
103
} )
85
104
} ) ;
0 commit comments