Skip to content

Commit 9ee4984

Browse files
committed
[DSC-714] Set authority value only when is provided by the VocabularyEntryDetail object
1 parent 8ca41ba commit 9ee4984

5 files changed

Lines changed: 33 additions & 19 deletions

File tree

src/app/core/json-patch/builder/json-patch-operations-builder.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export class JsonPatchOperationsBuilder {
157157
operationValue = new FormFieldMetadataValueObject(dateToISOFormat(value));
158158
}
159159
} else if (value instanceof VocabularyEntry) {
160-
operationValue = this.prepareAuthorityValue(value);
160+
operationValue = new FormFieldMetadataValueObject(value.value, null, value.securityLevel, value.authority);
161161
} else if (value instanceof FormFieldLanguageValueObject) {
162162
operationValue = new FormFieldMetadataValueObject(value.value, value.language, securityLevel);
163163
} else if (value.hasOwnProperty('authority')) {
@@ -184,14 +184,4 @@ export class JsonPatchOperationsBuilder {
184184
return operationValue;
185185
}
186186

187-
protected prepareAuthorityValue(value: any): FormFieldMetadataValueObject {
188-
let operationValue: FormFieldMetadataValueObject;
189-
if (isNotEmpty(value.authority)) {
190-
operationValue = new FormFieldMetadataValueObject(value.value, value.language, value.securityLevel, value.authority);
191-
} else {
192-
operationValue = new FormFieldMetadataValueObject(value.value, value.language, value.securityLevel,);
193-
}
194-
return operationValue;
195-
}
196-
197187
}

src/app/core/submission/vocabularies/models/vocabulary-entry.model.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ export class VocabularyEntry extends ListableObject {
5050
@autoserialize
5151
securityLevel: number;
5252

53-
54-
5553
/**
5654
* A string representing the kind of vocabulary entry
5755
*/

src/app/shared/form/builder/ds-dynamic-form-ui/models/onebox/dynamic-onebox.component.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
[disabled]="model.readOnly"
8080
[type]="model.inputType"
8181
[value]="currentValue?.display"
82-
[disabled]="model.readOnly"
8382
(focus)="onFocus($event)"
8483
(change)="onChange($event)"
8584
(click)="openTree($event)"

src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.spec.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ describe('VocabularyTreeviewComponent test suite', () => {
2929
item.id = 'node1';
3030
const item2 = new VocabularyEntryDetail();
3131
item2.id = 'node2';
32+
const entryWithAuthority = new VocabularyEntryDetail();
33+
entryWithAuthority.authority = 'entryWithAuthority';
34+
entryWithAuthority.id = 'entryWithAuthority';
35+
entryWithAuthority.value = 'test';
36+
const entryWithoutAuthority = new VocabularyEntryDetail();
37+
entryWithoutAuthority.id = 'entryWithoutAuthority';
38+
entryWithoutAuthority.value = 'test2';
3239
const emptyNodeMap = new Map<string, TreeviewFlatNode>();
3340
const storedNodeMap = new Map<string, TreeviewFlatNode>().set('test', new TreeviewFlatNode(item2));
3441
const nodeMap = new Map<string, TreeviewFlatNode>().set('test', new TreeviewFlatNode(item));
@@ -169,11 +176,31 @@ describe('VocabularyTreeviewComponent test suite', () => {
169176
expect(vocabularyTreeviewServiceStub.loadMore).toHaveBeenCalledWith(node.item, [], true);
170177
});
171178

172-
it('should emit select event', () => {
173-
spyOn(comp, 'onSelect');
174-
comp.onSelect(item);
179+
it('should emit proper FormFieldMetadataValueObject when VocabularyEntryDetail has authority', () => {
180+
spyOn(compAsAny, 'getSelectedEntryIds').and.returnValue([]);
181+
spyOn(comp.select, 'emit');
182+
comp.onSelect(entryWithAuthority);
175183

176-
expect(comp.onSelect).toHaveBeenCalledWith(item);
184+
const expected = new FormFieldMetadataValueObject(entryWithAuthority.value, null, null, entryWithAuthority.authority);
185+
expect(comp.select.emit).toHaveBeenCalledWith(expected);
186+
});
187+
188+
it('should emit proper FormFieldMetadataValueObject when VocabularyEntryDetail has no authority', () => {
189+
spyOn(compAsAny, 'getSelectedEntryIds').and.returnValue([]);
190+
spyOn(comp.select, 'emit');
191+
comp.onSelect(entryWithoutAuthority);
192+
193+
const expected = new FormFieldMetadataValueObject(entryWithoutAuthority.value);
194+
expect(comp.select.emit).toHaveBeenCalledWith(expected);
195+
});
196+
197+
it('should emit deselect when entry is already present', () => {
198+
spyOn(compAsAny, 'getSelectedEntryIds').and.returnValue([entryWithAuthority.id]);
199+
spyOn(comp.select, 'emit');
200+
spyOn(comp.deselect, 'emit');
201+
comp.onSelect(entryWithAuthority);
202+
203+
expect(comp.deselect.emit).toHaveBeenCalled();
177204
});
178205

179206
it('should call searchByQuery function and set storedNodeMap properly', () => {

src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export class VocabularyTreeviewComponent implements OnDestroy, OnInit, OnChanges
248248
onSelect(item: VocabularyEntryDetail) {
249249
if (!this.getSelectedEntryIds().includes(this.getEntryId(item))) {
250250
this.selectedItems.push(item);
251-
this.select.emit(item);
251+
this.select.emit(new FormFieldMetadataValueObject(item.value, null, item.securityLevel, item.authority, item.display));
252252
} else {
253253
this.selectedItems = this.selectedItems.filter((detail: VocabularyTreeItemType) => this.getEntryId(detail) !== this.getEntryId(item));
254254
this.deselect.emit(item);

0 commit comments

Comments
 (0)