@@ -3,7 +3,7 @@ import { async } from '@angular/core/testing';
3
3
import { Shallow } from 'shallow-render' ;
4
4
import { Observable , of } from 'rxjs' ;
5
5
6
- import { ItemVO , TagVOData , RecordVO } from '@models' ;
6
+ import { ItemVO , TagVOData , RecordVO , FolderVO } from '@models' ;
7
7
import { ApiService } from '@shared/services/api/api.service' ;
8
8
import { DataService } from '@shared/services/data/data.service' ;
9
9
import { TagsService } from '@core/services/tags/tags.service' ;
@@ -38,12 +38,35 @@ const defaultTagList: TagVOData[] = [
38
38
type : 'type.tag.metadata.customField' ,
39
39
} ,
40
40
] ;
41
- const defaultItem : ItemVO = new RecordVO ( { TagVOs : defaultTagList } ) ;
41
+ const defaultRecord = new RecordVO ( {
42
+ tags : defaultTagList ,
43
+ isRecord : true ,
44
+ } ) ;
45
+
46
+ const defaultFolder = new FolderVO ( {
47
+ TagVOs : defaultTagList ,
48
+ isFolder : true ,
49
+ } ) ;
42
50
43
51
describe ( 'EditTagsComponent' , ( ) => {
44
52
let shallow : Shallow < EditTagsComponent > ;
45
- async function defaultRender (
46
- item : ItemVO = defaultItem ,
53
+ async function defaultRenderRecord (
54
+ item : ItemVO = defaultRecord ,
55
+ tagType : TagType = 'keyword' ,
56
+ ) {
57
+ return await shallow . render (
58
+ `<pr-edit-tags [item]="item" [tagType]="tagType"></pr-edit-tags>` ,
59
+ {
60
+ bind : {
61
+ item : item ,
62
+ tagType : tagType ,
63
+ } ,
64
+ } ,
65
+ ) ;
66
+ }
67
+
68
+ async function defaultRenderFolder (
69
+ item : ItemVO = defaultFolder ,
47
70
tagType : TagType = 'keyword' ,
48
71
) {
49
72
return await shallow . render (
@@ -81,14 +104,32 @@ describe('EditTagsComponent', () => {
81
104
) ;
82
105
} ) ) ;
83
106
84
- it ( 'should create' , async ( ) => {
85
- const { element } = await defaultRender ( ) ;
107
+ it ( 'should create record tags ' , async ( ) => {
108
+ const { element } = await defaultRenderRecord ( ) ;
86
109
87
110
expect ( element ) . not . toBeNull ( ) ;
88
111
} ) ;
89
112
90
- it ( 'should only show keywords in keyword mode' , async ( ) => {
91
- const { element } = await defaultRender ( ) ;
113
+ it ( 'should create folder tags' , async ( ) => {
114
+ const { element } = await defaultRenderFolder ( ) ;
115
+
116
+ expect ( element ) . not . toBeNull ( ) ;
117
+ } ) ;
118
+
119
+ it ( 'should only show keywords in keyword mode for records' , async ( ) => {
120
+ const { element, fixture } = await defaultRenderRecord ( ) ;
121
+
122
+ element . componentInstance . itemTags = [
123
+ { name : 'tagOne' } ,
124
+ { name : 'tagTwo' } ,
125
+ ] ;
126
+
127
+ element . componentInstance . matchingTags = [
128
+ { name : 'tagOne' } ,
129
+ { name : 'tagTwo' } ,
130
+ ] ;
131
+
132
+ fixture . detectChanges ( ) ;
92
133
93
134
expect (
94
135
element . componentInstance . itemTags . find ( ( tag ) => tag . name === 'tagOne' ) ,
@@ -135,65 +176,20 @@ describe('EditTagsComponent', () => {
135
176
) . not . toBeTruthy ( ) ;
136
177
} ) ;
137
178
138
- it ( 'should only show custom metadata in custom metadata mode' , async ( ) => {
139
- const { element } = await defaultRender ( defaultItem , 'customMetadata' ) ;
140
-
141
- expect (
142
- element . componentInstance . itemTags . find ( ( tag ) => tag . name === 'tagOne' ) ,
143
- ) . not . toBeTruthy ( ) ;
144
-
145
- expect (
146
- element . componentInstance . itemTags . find ( ( tag ) => tag . name === 'tagTwo' ) ,
147
- ) . not . toBeTruthy ( ) ;
148
-
149
- expect (
150
- element . componentInstance . itemTags . find (
151
- ( tag ) => tag . name === 'customField:customValueOne' ,
152
- ) ,
153
- ) . toBeTruthy ( ) ;
154
-
155
- expect (
156
- element . componentInstance . itemTags . find (
157
- ( tag ) => tag . name === 'customField:customValueTwo' ,
158
- ) ,
159
- ) . toBeTruthy ( ) ;
160
-
161
- expect (
162
- element . componentInstance . matchingTags . find (
163
- ( tag ) => tag . name === 'tagOne' ,
164
- ) ,
165
- ) . not . toBeTruthy ( ) ;
166
-
167
- expect (
168
- element . componentInstance . matchingTags . find (
169
- ( tag ) => tag . name === 'tagTwo' ,
170
- ) ,
171
- ) . not . toBeTruthy ( ) ;
172
-
173
- expect (
174
- element . componentInstance . matchingTags . find (
175
- ( tag ) => tag . name === 'customField:customValueOne' ,
176
- ) ,
177
- ) . toBeTruthy ( ) ;
178
-
179
- expect (
180
- element . componentInstance . matchingTags . find (
181
- ( tag ) => tag . name === 'customField:customValueTwo' ,
182
- ) ,
183
- ) . toBeTruthy ( ) ;
184
- } ) ;
185
-
186
- it ( 'should not create custom metadata in keyword mode' , async ( ) => {
187
- const { element } = await defaultRender ( ) ;
179
+ it ( 'should not create custom metadata in keyword mode for records' , async ( ) => {
180
+ const { element } = await defaultRenderRecord ( ) ;
188
181
const tagCreateSpy = spyOn ( element . componentInstance . api . tag , 'create' ) ;
189
182
await element . componentInstance . onInputEnter ( 'key:value' ) ;
190
183
191
184
expect ( element . componentInstance . newTagInputError ) . toBeTruthy ( ) ;
192
185
expect ( tagCreateSpy ) . not . toHaveBeenCalled ( ) ;
193
186
} ) ;
194
187
195
- it ( 'should not create keyword in custom metadata mode' , async ( ) => {
196
- const { element } = await defaultRender ( defaultItem , 'customMetadata' ) ;
188
+ it ( 'should not create keyword in custom metadata mode for records' , async ( ) => {
189
+ const { element } = await defaultRenderRecord (
190
+ defaultRecord ,
191
+ 'customMetadata' ,
192
+ ) ;
197
193
const tagCreateSpy = spyOn ( element . componentInstance . api . tag , 'create' ) ;
198
194
await element . componentInstance . onInputEnter ( 'keyword' ) ;
199
195
@@ -202,7 +198,25 @@ describe('EditTagsComponent', () => {
202
198
} ) ;
203
199
204
200
it ( 'should highlight the correct tag on key down' , async ( ) => {
205
- const { fixture, element } = await defaultRender ( ) ;
201
+ const { fixture, element } = await defaultRenderFolder ( ) ;
202
+
203
+ element . componentInstance . isEditing = true ;
204
+
205
+ fixture . detectChanges ( ) ;
206
+ const tags = fixture . debugElement . queryAll ( By . css ( '.edit-tag' ) ) ;
207
+
208
+ const arrowKeyDown = new KeyboardEvent ( 'keydown' , { key : 'ArrowDown' } ) ;
209
+ tags [ 0 ] . nativeElement . dispatchEvent ( arrowKeyDown ) ;
210
+
211
+ fixture . detectChanges ( ) ;
212
+
213
+ const focusedElement = document . activeElement as HTMLElement ;
214
+
215
+ expect ( focusedElement ) . toBe ( tags [ 1 ] . nativeElement ) ;
216
+ } ) ;
217
+
218
+ it ( 'should highlight the correct tag for folders on key down' , async ( ) => {
219
+ const { fixture, element } = await defaultRenderFolder ( ) ;
206
220
207
221
element . componentInstance . isEditing = true ;
208
222
@@ -220,7 +234,7 @@ describe('EditTagsComponent', () => {
220
234
} ) ;
221
235
222
236
it ( 'should highlight the correct tag on key up' , async ( ) => {
223
- const { fixture, element } = await defaultRender ( ) ;
237
+ const { fixture, element } = await defaultRenderRecord ( ) ;
224
238
225
239
element . componentInstance . isEditing = true ;
226
240
@@ -238,7 +252,7 @@ describe('EditTagsComponent', () => {
238
252
} ) ;
239
253
240
254
it ( 'should highlight the input on key up' , async ( ) => {
241
- const { fixture, element } = await defaultRender ( ) ;
255
+ const { fixture, element } = await defaultRenderRecord ( ) ;
242
256
243
257
element . componentInstance . isEditing = true ;
244
258
@@ -258,7 +272,7 @@ describe('EditTagsComponent', () => {
258
272
} ) ;
259
273
260
274
it ( 'should open dialog when manage link is clicked' , async ( ) => {
261
- const { element, find, inject, fixture } = await defaultRender ( ) ;
275
+ const { element, find, inject, fixture } = await defaultRenderRecord ( ) ;
262
276
const dialogOpenSpy = inject ( DialogCdkService ) ;
263
277
264
278
element . componentInstance . isEditing = true ;
0 commit comments