11describe ( 'Module: angularjs-input-tags -' , ( ) => {
22 let $componentController ;
3- const locals = {
4- $element : angular . element ( '<div></div>' )
5- } ;
63
74 beforeEach ( angular . mock . module ( 'angularjs-input-tags' ) ) ;
85 beforeEach ( angular . mock . inject ( _$componentController_ => {
96 $componentController = _$componentController_ ;
107 } ) ) ;
118
129 describe ( 'Component: inputTags -' , ( ) => {
10+ let ctrl ;
11+
12+ beforeEach ( ( ) => {
13+ ctrl = $componentController ( 'inputTags' , {
14+ $element : angular . element ( '<div></div>' )
15+ } , {
16+ onTagAdding : jasmine . createSpy ( 'onTagAdding' ) ,
17+ onTagRemoving : jasmine . createSpy ( 'onTagRemoving' )
18+ } ) ;
19+ } ) ;
1320 describe ( 'Event: onTagAdding' , ( ) => {
1421 it ( 'should be emit' , ( ) => {
15- const onTagAdding = jasmine . createSpy ( 'onTagAdding' ) ;
16- const bindings = { onTagAdding} ;
17- const ctrl = $componentController ( 'inputTags' , locals , bindings ) ;
1822 ctrl . $onInit ( ) ;
1923 ctrl . addTag ( { code : 1 , text : '1' } ) ;
20- expect ( onTagAdding ) . toHaveBeenCalled ( ) ;
24+ console . log ( ctrl ) ;
25+ expect ( ctrl . onTagAdding ) . toHaveBeenCalled ( ) ;
2126 } ) ;
2227
2328 it ( 'should be emit with formatted tag value' , ( ) => {
24- const onTagAdding = jasmine . createSpy ( 'onTagAdding' ) ;
25- const bindings = { onTagAdding} ;
26- const ctrl = $componentController ( 'inputTags' , locals , bindings ) ;
2729 ctrl . $onInit ( ) ;
2830 ctrl . addTag ( { code : 1 , text : '1' } ) ;
29- expect ( onTagAdding ) . toHaveBeenCalledWith ( { code : 1 , text : '1' } ) ;
31+ expect ( ctrl . onTagAdding ) . toHaveBeenCalledWith ( { code : 1 , text : '1' } ) ;
3032 } ) ;
3133 } ) ;
3234
3335 it ( 'should add tag on list' , ( ) => {
34- const ctrl = $componentController ( 'inputTags' , locals ) ;
3536 ctrl . $onInit ( ) ;
3637 ctrl . addTag ( { code : 1 , text : '1' } ) ;
3738 expect ( ctrl . tags ) . toContain ( { code : 1 , text : '1' } ) ;
3839 } ) ;
3940
4041 it ( 'should update tag list' , ( ) => {
41- const ctrl = $componentController ( 'inputTags' , locals ) ;
4242 ctrl . $onInit ( ) ;
4343 ctrl . addTag ( { code : 1 , text : '1' } ) ;
4444 ctrl . addTag ( { code : 1 , text : '1' } ) ;
@@ -47,79 +47,65 @@ describe('Module: angularjs-input-tags -', () => {
4747 } ) ;
4848
4949 it ( 'should ' , ( ) => {
50- const ctrl = $componentController ( 'inputTags' , locals ) ;
5150 ctrl . $onInit ( ) ;
5251 ctrl . triggerFocus ( ) ;
5352 expect ( ctrl . autocompleteVisible ) . toBe ( true ) ;
5453 } ) ;
5554
5655 it ( 'should ' , ( ) => {
57- const ctrl = $componentController ( 'inputTags' , locals ) ;
5856 ctrl . $onInit ( ) ;
5957 ctrl . triggerBlur ( ) ;
6058 expect ( ctrl . autocompleteVisible ) . toBe ( false ) ;
6159 } ) ;
6260
6361 it ( 'should ' , ( ) => {
64- const ctrl = $componentController ( 'inputTags' , locals ) ;
6562 ctrl . $onInit ( ) ;
6663 ctrl . getTagText ( { text : 'test' } ) ;
6764 expect ( ctrl . autocompleteVisible ) . toBe ( false ) ;
6865 } ) ;
6966
7067 it ( 'should ' , ( ) => {
71- const ctrl = $componentController ( 'inputTags' , locals ) ;
7268 ctrl . $onInit ( ) ;
7369 const result = ctrl . track ( { text : '1' } ) ;
7470 expect ( result ) . toBe ( '1' ) ;
7571 } ) ;
7672
7773 it ( 'should emit `onTagRemoving` event' , ( ) => {
78- const onTagRemoving = jasmine . createSpy ( 'onTagRemoving' ) ;
79- const bindings = {
80- onTagRemoving,
81- tags : [ 'Demo' ]
82- } ;
83- const ctrl = $componentController ( 'inputTags' , locals , bindings ) ;
8474 ctrl . $onInit ( ) ;
75+ ctrl . tags = [ 'Demo' ] ;
8576 ctrl . removeTag ( { code : 1 , text : '1' } ) ;
86- expect ( onTagRemoving ) . toHaveBeenCalled ( ) ;
87- expect ( onTagRemoving ) . toHaveBeenCalledWith ( { code : 1 , text : '1' } ) ;
77+ expect ( ctrl . onTagRemoving ) . toHaveBeenCalled ( ) ;
78+ expect ( ctrl . onTagRemoving ) . toHaveBeenCalledWith ( { code : 1 , text : '1' } ) ;
8879 } ) ;
8980
9081 it ( 'should remove matching element by code' , ( ) => {
91- const ctrl = $componentController ( 'inputTags' , locals ) ;
9282 ctrl . $onInit ( ) ;
93- ctrl . tags = [ ] ;
83+ ctrl . tags . length = 0 ;
9484 ctrl . addTag ( { code : 1 , text : '1' } ) ;
9585 ctrl . removeTag ( { code : 1 } ) ;
9686 expect ( ctrl . tags . length ) . toBe ( 0 ) ;
9787 } ) ;
9888
9989 it ( 'should reset the tag list' , ( ) => {
100- const ctrl = $componentController ( 'inputTags' , locals ) ;
10190 ctrl . $onInit ( ) ;
10291 expect ( ctrl . path . length ) . toBe ( 0 ) ;
10392 } ) ;
10493
10594 it ( 'should go to the selected element in the tree' , ( ) => {
106- const ctrl = $componentController ( 'inputTags' , locals ) ;
10795 ctrl . $onInit ( ) ;
10896 const pathLength = ctrl . path . length ;
10997 ctrl . next ( 'subLevel' ) ;
11098 expect ( ctrl . path . length ) . toBe ( pathLength + 1 ) ;
11199 } ) ;
112100
113101 it ( 'should back to the previous element in the tree when on the root' , ( ) => {
114- const ctrl = $componentController ( 'inputTags' , locals ) ;
115102 ctrl . $onInit ( ) ;
116103 ctrl . path = [ ] ;
117104 ctrl . previous ( ) ;
118105 expect ( ctrl . path . length ) . toBe ( 0 ) ;
119106 } ) ;
120107
121108 it ( 'should back to the previous element in the tree when in 2 sublevels' , ( ) => {
122- const ctrl = $componentController ( 'inputTags' , locals ) ;
123109 ctrl . $onInit ( ) ;
124110 ctrl . next ( 'subLevel' ) ;
125111 ctrl . next ( 'subSubLevel' ) ;
0 commit comments