|
1 | | -describe('input-tags', () => { |
| 1 | +describe('Module: angularjs-input-tags -', () => { |
2 | 2 | let $componentController; |
3 | 3 |
|
4 | 4 | beforeEach(angular.mock.module('angularjs-input-tags')); |
5 | 5 | beforeEach(angular.mock.inject(_$componentController_ => { |
6 | 6 | $componentController = _$componentController_; |
7 | 7 | })); |
8 | 8 |
|
9 | | - describe('addTag', () => { |
10 | | - it('should emit `onTagAdding` callback', () => { |
11 | | - const onTagAddingSpy = jasmine.createSpy('onTagAdding'); |
12 | | - const bindings = {onTagAdding: onTagAddingSpy}; |
13 | | - const ctrl = $componentController('inputTags', undefined, bindings); |
| 9 | + describe('Component: inputTags -', () => { |
| 10 | + describe('Event: onTagAdding', () => { |
| 11 | + it('should be emit', () => { |
| 12 | + const onTagAddingSpy = jasmine.createSpy('onTagAdding'); |
| 13 | + const bindings = {onTagAdding: onTagAddingSpy}; |
| 14 | + const ctrl = $componentController('inputTags', undefined, bindings); |
| 15 | + ctrl.$onInit(); |
| 16 | + ctrl.addTag({code: 1, text: '1'}); |
| 17 | + expect(onTagAddingSpy).toHaveBeenCalled(); |
| 18 | + }); |
| 19 | + |
| 20 | + 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 | + ctrl.$onInit(); |
| 25 | + ctrl.addTag({code: 1, text: '1'}); |
| 26 | + expect(onTagAddingSpy).toHaveBeenCalledWith({code: 1, text: '1'}); |
| 27 | + }); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should add tag on list', () => { |
| 31 | + const ctrl = $componentController('inputTags'); |
14 | 32 | ctrl.$onInit(); |
15 | 33 | ctrl.addTag({code: 1, text: '1'}); |
16 | | - expect(onTagAddingSpy).toHaveBeenCalledWith({code: 1, text: '1'}); |
| 34 | + expect(ctrl.tags).toContain({code: 1, text: '1'}); |
17 | 35 | }); |
18 | 36 |
|
19 | 37 | it('should update tag list', () => { |
20 | 38 | const ctrl = $componentController('inputTags'); |
21 | 39 | ctrl.$onInit(); |
22 | 40 | ctrl.addTag({code: 1, text: '1'}); |
23 | | - expect(ctrl.tags).toContain({code: 1, text: '1'}); |
| 41 | + ctrl.addTag({code: 1, text: '1'}); |
| 42 | + ctrl.addTag({code: 1, text: '1'}); |
| 43 | + expect(ctrl.tags.length).toBe(1); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should ', () => { |
| 47 | + const ctrl = $componentController('inputTags'); |
| 48 | + ctrl.$onInit(); |
| 49 | + ctrl.triggerFocus(); |
| 50 | + expect(ctrl.autocompleteVisible).toBe(true); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should ', () => { |
| 54 | + const ctrl = $componentController('inputTags'); |
| 55 | + ctrl.$onInit(); |
| 56 | + ctrl.triggerBlur(); |
| 57 | + expect(ctrl.autocompleteVisible).toBe(false); |
| 58 | + }); |
| 59 | + |
| 60 | + it('should ', () => { |
| 61 | + const ctrl = $componentController('inputTags'); |
| 62 | + ctrl.$onInit(); |
| 63 | + ctrl.getTagText({text: 'test'}); |
| 64 | + expect(ctrl.autocompleteVisible).toBe(false); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should ', () => { |
| 68 | + const ctrl = $componentController('inputTags'); |
| 69 | + ctrl.$onInit(); |
| 70 | + const result = ctrl.track({text: '1'}); |
| 71 | + expect(result).toBe('1'); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should emit `onTagRemoving` event', () => { |
| 75 | + const onTagRemovingSpy = jasmine.createSpy('onTagRemoving'); |
| 76 | + const bindings = { |
| 77 | + onTagRemoving: onTagRemovingSpy, |
| 78 | + tags: ['Demo'] |
| 79 | + }; |
| 80 | + const ctrl = $componentController('inputTags', undefined, bindings); |
| 81 | + ctrl.$onInit(); |
| 82 | + ctrl.removeTag({code: 1, text: '1'}); |
| 83 | + expect(onTagRemovingSpy).toHaveBeenCalled(); |
| 84 | + expect(onTagRemovingSpy).toHaveBeenCalledWith({code: 1, text: '1'}); |
| 85 | + }); |
| 86 | + |
| 87 | + it('should remove matching element by code', () => { |
| 88 | + const ctrl = $componentController('inputTags'); |
| 89 | + ctrl.$onInit(); |
| 90 | + ctrl.tags = []; |
| 91 | + ctrl.addTag({code: 1, text: '1'}); |
| 92 | + ctrl.removeTag({code: 1}); |
| 93 | + expect(ctrl.tags.length).toBe(0); |
| 94 | + }); |
| 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 | + }); |
| 124 | + |
| 125 | + it('should reset the tag list', () => { |
| 126 | + const ctrl = $componentController('inputTagsAutoComplete'); |
| 127 | + ctrl.$onInit(); |
| 128 | + expect(ctrl.path.length).toBe(0); |
| 129 | + }); |
| 130 | + |
| 131 | + it('should go to the selected element in the tree', () => { |
| 132 | + const ctrl = $componentController('inputTagsAutoComplete'); |
| 133 | + ctrl.$onInit(); |
| 134 | + const pathLength = ctrl.path.length; |
| 135 | + ctrl.next('subLevel'); |
| 136 | + expect(ctrl.path.length).toBe(pathLength + 1); |
| 137 | + }); |
| 138 | + |
| 139 | + it('should back to the previous element in the tree when on the root', () => { |
| 140 | + const ctrl = $componentController('inputTagsAutoComplete'); |
| 141 | + ctrl.$onInit(); |
| 142 | + ctrl.path = []; |
| 143 | + ctrl.previous(); |
| 144 | + expect(ctrl.path.length).toBe(0); |
| 145 | + }); |
| 146 | + |
| 147 | + it('should back to the previous element in the tree when in 2 sublevels', () => { |
| 148 | + const ctrl = $componentController('inputTagsAutoComplete'); |
| 149 | + ctrl.$onInit(); |
| 150 | + ctrl.next('subLevel'); |
| 151 | + ctrl.next('subSubLevel'); |
| 152 | + ctrl.previous(); |
| 153 | + expect(ctrl.path.length).toBe(1); |
24 | 154 | }); |
25 | 155 | }); |
26 | 156 | }); |
0 commit comments