11describe ( 'Module: angularjs-input-tags -' , ( ) => {
22 let $componentController ;
3+ const locals = {
4+ $element : angular . element ( '<div></div>' )
5+ } ;
36
47 beforeEach ( angular . mock . module ( 'angularjs-input-tags' ) ) ;
58 beforeEach ( angular . mock . inject ( _$componentController_ => {
@@ -9,33 +12,33 @@ describe('Module: angularjs-input-tags -', () => {
912 describe ( 'Component: inputTags -' , ( ) => {
1013 describe ( 'Event: onTagAdding' , ( ) => {
1114 it ( 'should be emit' , ( ) => {
12- const onTagAddingSpy = jasmine . createSpy ( 'onTagAdding' ) ;
13- const bindings = { onTagAdding : onTagAddingSpy } ;
14- const ctrl = $componentController ( 'inputTags' , undefined , bindings ) ;
15+ const onTagAdding = jasmine . createSpy ( 'onTagAdding' ) ;
16+ const bindings = { onTagAdding} ;
17+ const ctrl = $componentController ( 'inputTags' , locals , bindings ) ;
1518 ctrl . $onInit ( ) ;
1619 ctrl . addTag ( { code : 1 , text : '1' } ) ;
17- expect ( onTagAddingSpy ) . toHaveBeenCalled ( ) ;
20+ expect ( onTagAdding ) . toHaveBeenCalled ( ) ;
1821 } ) ;
1922
2023 it ( 'should be emit with formatted tag value' , ( ) => {
21- const onTagAddingSpy = jasmine . createSpy ( 'onTagAdding' ) ;
22- const bindings = { onTagAdding : onTagAddingSpy } ;
23- const ctrl = $componentController ( 'inputTags' , undefined , bindings ) ;
24+ const onTagAdding = jasmine . createSpy ( 'onTagAdding' ) ;
25+ const bindings = { onTagAdding} ;
26+ const ctrl = $componentController ( 'inputTags' , locals , bindings ) ;
2427 ctrl . $onInit ( ) ;
2528 ctrl . addTag ( { code : 1 , text : '1' } ) ;
26- expect ( onTagAddingSpy ) . toHaveBeenCalledWith ( { code : 1 , text : '1' } ) ;
29+ expect ( onTagAdding ) . toHaveBeenCalledWith ( { code : 1 , text : '1' } ) ;
2730 } ) ;
2831 } ) ;
2932
3033 it ( 'should add tag on list' , ( ) => {
31- const ctrl = $componentController ( 'inputTags' ) ;
34+ const ctrl = $componentController ( 'inputTags' , locals ) ;
3235 ctrl . $onInit ( ) ;
3336 ctrl . addTag ( { code : 1 , text : '1' } ) ;
3437 expect ( ctrl . tags ) . toContain ( { code : 1 , text : '1' } ) ;
3538 } ) ;
3639
3740 it ( 'should update tag list' , ( ) => {
38- const ctrl = $componentController ( 'inputTags' ) ;
41+ const ctrl = $componentController ( 'inputTags' , locals ) ;
3942 ctrl . $onInit ( ) ;
4043 ctrl . addTag ( { code : 1 , text : '1' } ) ;
4144 ctrl . addTag ( { code : 1 , text : '1' } ) ;
@@ -44,108 +47,79 @@ describe('Module: angularjs-input-tags -', () => {
4447 } ) ;
4548
4649 it ( 'should ' , ( ) => {
47- const ctrl = $componentController ( 'inputTags' ) ;
50+ const ctrl = $componentController ( 'inputTags' , locals ) ;
4851 ctrl . $onInit ( ) ;
4952 ctrl . triggerFocus ( ) ;
5053 expect ( ctrl . autocompleteVisible ) . toBe ( true ) ;
5154 } ) ;
5255
5356 it ( 'should ' , ( ) => {
54- const ctrl = $componentController ( 'inputTags' ) ;
57+ const ctrl = $componentController ( 'inputTags' , locals ) ;
5558 ctrl . $onInit ( ) ;
5659 ctrl . triggerBlur ( ) ;
5760 expect ( ctrl . autocompleteVisible ) . toBe ( false ) ;
5861 } ) ;
5962
6063 it ( 'should ' , ( ) => {
61- const ctrl = $componentController ( 'inputTags' ) ;
64+ const ctrl = $componentController ( 'inputTags' , locals ) ;
6265 ctrl . $onInit ( ) ;
6366 ctrl . getTagText ( { text : 'test' } ) ;
6467 expect ( ctrl . autocompleteVisible ) . toBe ( false ) ;
6568 } ) ;
6669
6770 it ( 'should ' , ( ) => {
68- const ctrl = $componentController ( 'inputTags' ) ;
71+ const ctrl = $componentController ( 'inputTags' , locals ) ;
6972 ctrl . $onInit ( ) ;
7073 const result = ctrl . track ( { text : '1' } ) ;
7174 expect ( result ) . toBe ( '1' ) ;
7275 } ) ;
7376
7477 it ( 'should emit `onTagRemoving` event' , ( ) => {
75- const onTagRemovingSpy = jasmine . createSpy ( 'onTagRemoving' ) ;
78+ const onTagRemoving = jasmine . createSpy ( 'onTagRemoving' ) ;
7679 const bindings = {
77- onTagRemoving : onTagRemovingSpy ,
80+ onTagRemoving,
7881 tags : [ 'Demo' ]
7982 } ;
80- const ctrl = $componentController ( 'inputTags' , undefined , bindings ) ;
83+ const ctrl = $componentController ( 'inputTags' , locals , bindings ) ;
8184 ctrl . $onInit ( ) ;
8285 ctrl . removeTag ( { code : 1 , text : '1' } ) ;
83- expect ( onTagRemovingSpy ) . toHaveBeenCalled ( ) ;
84- expect ( onTagRemovingSpy ) . toHaveBeenCalledWith ( { code : 1 , text : '1' } ) ;
86+ expect ( onTagRemoving ) . toHaveBeenCalled ( ) ;
87+ expect ( onTagRemoving ) . toHaveBeenCalledWith ( { code : 1 , text : '1' } ) ;
8588 } ) ;
8689
8790 it ( 'should remove matching element by code' , ( ) => {
88- const ctrl = $componentController ( 'inputTags' ) ;
91+ const ctrl = $componentController ( 'inputTags' , locals ) ;
8992 ctrl . $onInit ( ) ;
9093 ctrl . tags = [ ] ;
9194 ctrl . addTag ( { code : 1 , text : '1' } ) ;
9295 ctrl . removeTag ( { code : 1 } ) ;
9396 expect ( ctrl . tags . length ) . toBe ( 0 ) ;
9497 } ) ;
95- } ) ;
96-
97- describe ( 'Component: inputTagsAutoComplete' , ( ) => {
98- it ( 'should emit `onTagAdd` event' , ( ) => {
99- const onTagAddSpy = jasmine . createSpy ( 'onTagAdd' ) ;
100- const bindings = { onTagAdd : onTagAddSpy } ;
101- const ctrl = $componentController ( 'inputTagsAutoComplete' , undefined , bindings ) ;
102- ctrl . $onInit ( ) ;
103- ctrl . addTag ( { code : 1 , text : '0' } ) ;
104- expect ( onTagAddSpy ) . toHaveBeenCalled ( ) ;
105- } ) ;
106-
107- it ( 'should not emit `onTagAdd` event' , ( ) => {
108- const onTagAddSpy = jasmine . createSpy ( 'onTagAdd' ) ;
109- const bindings = { onTagAdd : onTagAddSpy } ;
110- const ctrl = $componentController ( 'inputTagsAutoComplete' , undefined , bindings ) ;
111- ctrl . $onInit ( ) ;
112- ctrl . addTag ( ) ;
113- expect ( onTagAddSpy ) . toHaveBeenCalledTimes ( 1 ) ;
114- } ) ;
115-
116- it ( 'should emit `onTagAdd` event with formatted tag value' , ( ) => {
117- const onTagAddSpy = jasmine . createSpy ( 'onTagAdd' ) ;
118- const bindings = { onTagAdd : onTagAddSpy } ;
119- const ctrl = $componentController ( 'inputTagsAutoComplete' , undefined , bindings ) ;
120- ctrl . $onInit ( ) ;
121- ctrl . addTag ( { code : 1 , text : '1' } ) ;
122- expect ( onTagAddSpy ) . toHaveBeenCalledWith ( { tag : { code : 1 , text : '1' } } ) ;
123- } ) ;
12498
12599 it ( 'should reset the tag list' , ( ) => {
126- const ctrl = $componentController ( 'inputTagsAutoComplete' ) ;
100+ const ctrl = $componentController ( 'inputTags' , locals ) ;
127101 ctrl . $onInit ( ) ;
128102 expect ( ctrl . path . length ) . toBe ( 0 ) ;
129103 } ) ;
130104
131105 it ( 'should go to the selected element in the tree' , ( ) => {
132- const ctrl = $componentController ( 'inputTagsAutoComplete' ) ;
106+ const ctrl = $componentController ( 'inputTags' , locals ) ;
133107 ctrl . $onInit ( ) ;
134108 const pathLength = ctrl . path . length ;
135109 ctrl . next ( 'subLevel' ) ;
136110 expect ( ctrl . path . length ) . toBe ( pathLength + 1 ) ;
137111 } ) ;
138112
139113 it ( 'should back to the previous element in the tree when on the root' , ( ) => {
140- const ctrl = $componentController ( 'inputTagsAutoComplete' ) ;
114+ const ctrl = $componentController ( 'inputTags' , locals ) ;
141115 ctrl . $onInit ( ) ;
142116 ctrl . path = [ ] ;
143117 ctrl . previous ( ) ;
144118 expect ( ctrl . path . length ) . toBe ( 0 ) ;
145119 } ) ;
146120
147121 it ( 'should back to the previous element in the tree when in 2 sublevels' , ( ) => {
148- const ctrl = $componentController ( 'inputTagsAutoComplete' ) ;
122+ const ctrl = $componentController ( 'inputTags' , locals ) ;
149123 ctrl . $onInit ( ) ;
150124 ctrl . next ( 'subLevel' ) ;
151125 ctrl . next ( 'subSubLevel' ) ;
0 commit comments