Skip to content

Commit 2efde9c

Browse files
atarix83Andrea Barbasso
authored andcommitted
Merged in task/dspace-cris-2023_02_x/DSC-1864_fixes (pull request DSpace#2360)
[DSC-1864] revert treeview changes after alignment with 7.6.2 Approved-by: Andrea Barbasso
2 parents 1db5098 + 8373868 commit 2efde9c

3 files changed

Lines changed: 118 additions & 98 deletions

File tree

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
<ds-alert *ngIf="description" [content]="description" [type]="'alert-info'"></ds-alert>
2-
<div class="treeview-header row mb-1">
3-
<div class="col-12">
1+
<ds-alert *ngIf="description" [content]="description" [type]="AlertType.Info"></ds-alert>
2+
<div class="treeview-header row">
3+
<div class="col-12 d-flex">
44
<div class="input-group">
5-
<input type="text" class="form-control" [(ngModel)]="searchText" (keyup.enter)="search()"
6-
[placeholder]="'vocabulary-treeview.search.form.search-placeholder' | translate">
5+
<input type="text" class="form-control" [(ngModel)]="searchText" (keyup.enter)="search()">
76
<div class="input-group-append" id="button-addon4">
8-
<button class="btn btn-outline-primary" type="button" (click)="search()" [disabled]="!isSearchEnabled()">
9-
{{'vocabulary-treeview.search.form.search' | translate}}
10-
</button>
11-
<button class="btn btn-outline-secondary" type="button" (click)="reset()">
12-
{{'vocabulary-treeview.search.form.reset' | translate}}
13-
</button>
14-
<button class="btn btn-outline-primary" type="button" (click)="add()" [disabled]="this.vocabularyOptions.closed">
15-
{{'vocabulary-treeview.search.form.add' | translate}}
7+
<button class="btn btn-primary" type="button" (click)="search()" [disabled]="!isSearchEnabled()">
8+
<span><i class="fas fa-search"></i> {{'vocabulary-treeview.search.form.search' | translate}}</span>
169
</button>
1710
</div>
1811
</div>
12+
<button class="btn btn-secondary ml-3 flex-shrink-0" type="button" (click)="reset()">
13+
<span><i class="fas fa-eraser"></i> {{'vocabulary-treeview.search.form.reset' | translate}}</span>
14+
</button>
15+
<button *ngIf="showAdd && !this.vocabularyOptions.closed" class="btn btn-secondary ml-3 flex-shrink-0" type="button" (click)="add()">
16+
<span><i class="fas fa-plus"></i> {{'vocabulary-treeview.search.form.add' | translate}}</span>
17+
</button>
1918
</div>
2019
</div>
2120
<div class="treeview-container">
@@ -59,7 +58,7 @@ <h2 *ngIf="!(loading | async) && dataSource.data.length === 0" class="h4 text-ce
5958
<button type="button" class="btn btn-default px-2 mr-1" cdkTreeNodeToggle
6059
[attr.aria-label]="'toggle ' + node.name"
6160
(click)="loadChildren(node)">
62-
<i class="fas fa-fw {{treeControl.isExpanded(node) ? 'fa-angle-down' : 'fa-angle-right'}}"></i>
61+
<span class="fas fa-fw {{treeControl.isExpanded(node) ? 'fa-angle-down' : 'fa-angle-right'}}"></span>
6362
</button>
6463

6564
<label *ngIf="multiSelect" class="d-flex align-items-center m-0 p-0 form-check"

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

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { ChangeDetectorRef, Component, NO_ERRORS_SCHEMA } from '@angular/core';
1+
import { Component, NO_ERRORS_SCHEMA } from '@angular/core';
22
import { ComponentFixture, inject, TestBed, waitForAsync } from '@angular/core/testing';
33
import { CdkTreeModule } from '@angular/cdk/tree';
4+
import { By } from '@angular/platform-browser';
45

56
import { of as observableOf } from 'rxjs';
6-
import { StoreModule } from '@ngrx/store';
77
import { TranslateModule } from '@ngx-translate/core';
88
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
9-
import { provideMockStore } from '@ngrx/store/testing';
109

1110
import { createTestComponent } from '../../testing/utils.test';
1211
import { VocabularyTreeviewComponent } from './vocabulary-treeview.component';
@@ -16,29 +15,31 @@ import { TreeviewFlatNode, TreeviewNode } from './vocabulary-treeview-node.model
1615
import { FormFieldMetadataValueObject } from '../builder/models/form-field-metadata-value.model';
1716
import { VocabularyOptions } from '../../../core/submission/vocabularies/models/vocabulary-options.model';
1817
import { PageInfo } from '../../../core/shared/page-info.model';
19-
import { VocabularyEntry } from '../../../core/submission/vocabularies/models/vocabulary-entry.model';
20-
import { AuthTokenInfo } from '../../../core/auth/models/auth-token-info.model';
21-
import { authReducer } from '../../../core/auth/auth.reducer';
22-
import { storeModuleConfig } from '../../../app.reducer';
23-
import { By } from '@angular/platform-browser';
2418
import { VocabularyService } from '../../../core/submission/vocabularies/vocabulary.service';
19+
import { VocabularyEntry } from '../../../core/submission/vocabularies/models/vocabulary-entry.model';
2520

2621
describe('VocabularyTreeviewComponent test suite', () => {
2722

2823
let comp: VocabularyTreeviewComponent;
2924
let compAsAny: any;
3025
let fixture: ComponentFixture<VocabularyTreeviewComponent>;
31-
let initialState;
3226
let de;
3327

3428
const item = new VocabularyEntryDetail();
3529
item.id = 'node1';
3630
const item2 = new VocabularyEntryDetail();
3731
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';
3839
const emptyNodeMap = new Map<string, TreeviewFlatNode>();
3940
const storedNodeMap = new Map<string, TreeviewFlatNode>().set('test', new TreeviewFlatNode(item2));
4041
const nodeMap = new Map<string, TreeviewFlatNode>().set('test', new TreeviewFlatNode(item));
41-
const vocabularyOptions = new VocabularyOptions('vocabularyTest', 'false');
42+
const vocabularyOptions = new VocabularyOptions('vocabularyTest', null, null, false);
4243
const modalStub = jasmine.createSpyObj('modalStub', ['close']);
4344
const vocabularyTreeviewServiceStub = jasmine.createSpyObj('VocabularyTreeviewService', {
4445
initialize: jasmine.createSpy('initialize'),
@@ -59,25 +60,10 @@ describe('VocabularyTreeviewComponent test suite', () => {
5960
clearSearchTopRequests: jasmine.createSpy('clearSearchTopRequests')
6061
});
6162

62-
initialState = {
63-
core: {
64-
auth: {
65-
authenticated: true,
66-
loaded: true,
67-
blocking: false,
68-
loading: false,
69-
authToken: new AuthTokenInfo('test_token'),
70-
userId: 'testid',
71-
authMethods: []
72-
}
73-
}
74-
};
75-
7663
beforeEach(waitForAsync(() => {
7764
TestBed.configureTestingModule({
7865
imports: [
7966
CdkTreeModule,
80-
StoreModule.forRoot({ auth: authReducer }, storeModuleConfig),
8167
TranslateModule.forRoot()
8268
],
8369
declarations: [
@@ -88,8 +74,6 @@ describe('VocabularyTreeviewComponent test suite', () => {
8874
{ provide: VocabularyTreeviewService, useValue: vocabularyTreeviewServiceStub },
8975
{ provide: VocabularyService, useValue: vocabularyServiceStub },
9076
{ provide: NgbActiveModal, useValue: modalStub },
91-
provideMockStore({ initialState }),
92-
ChangeDetectorRef,
9377
VocabularyTreeviewComponent
9478
],
9579
schemas: [NO_ERRORS_SCHEMA]
@@ -144,10 +128,10 @@ describe('VocabularyTreeviewComponent test suite', () => {
144128
currentValue.otherInformation = {
145129
id: 'entryID'
146130
};
147-
comp.selectedItems = [currentValue.value];
131+
comp.selectedItems = [currentValue];
148132
fixture.detectChanges();
149133
expect(comp.dataSource.data).toEqual([]);
150-
expect(vocabularyTreeviewServiceStub.initialize).toHaveBeenCalledWith(comp.vocabularyOptions, new PageInfo(), ['testValue'], null);
134+
expect(vocabularyTreeviewServiceStub.initialize).toHaveBeenCalledWith(comp.vocabularyOptions, new PageInfo(), ['entryID'], 'entryID');
151135
});
152136

153137
it('should should init component properly with init value as VocabularyEntry', () => {
@@ -156,10 +140,20 @@ describe('VocabularyTreeviewComponent test suite', () => {
156140
currentValue.otherInformation = {
157141
id: 'entryID'
158142
};
159-
comp.selectedItems = [currentValue.value];
143+
comp.selectedItems = [currentValue];
144+
fixture.detectChanges();
145+
expect(comp.dataSource.data).toEqual([]);
146+
expect(vocabularyTreeviewServiceStub.initialize).toHaveBeenCalledWith(comp.vocabularyOptions, new PageInfo(), ['entryID'], 'entryID');
147+
});
148+
149+
it('should should init component properly with init value as VocabularyEntryDetail', () => {
150+
const currentValue = new VocabularyEntryDetail();
151+
currentValue.value = 'testValue';
152+
currentValue.id = 'entryID';
153+
comp.selectedItems = [currentValue];
160154
fixture.detectChanges();
161155
expect(comp.dataSource.data).toEqual([]);
162-
expect(vocabularyTreeviewServiceStub.initialize).toHaveBeenCalledWith(comp.vocabularyOptions, new PageInfo(), ['testValue'], null);
156+
expect(vocabularyTreeviewServiceStub.initialize).toHaveBeenCalledWith(comp.vocabularyOptions, new PageInfo(), ['entryID'], 'entryID');
163157
});
164158

165159
it('should call loadMore function', () => {
@@ -182,11 +176,31 @@ describe('VocabularyTreeviewComponent test suite', () => {
182176
expect(vocabularyTreeviewServiceStub.loadMore).toHaveBeenCalledWith(node.item, [], true);
183177
});
184178

185-
it('should emit select event', () => {
186-
spyOn(comp, 'onSelect');
187-
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);
183+
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);
188202

189-
expect(comp.onSelect).toHaveBeenCalledWith(item);
203+
expect(comp.deselect.emit).toHaveBeenCalled();
190204
});
191205

192206
it('should call searchByQuery function and set storedNodeMap properly', () => {
@@ -288,7 +302,7 @@ describe('VocabularyTreeviewComponent test suite', () => {
288302
})
289303
class TestComponent {
290304

291-
vocabularyOptions: VocabularyOptions = new VocabularyOptions('vocabularyTest', 'false');
305+
vocabularyOptions: VocabularyOptions = new VocabularyOptions('vocabularyTest', null, null, false);
292306
preloadLevel = 2;
293307

294308
}

0 commit comments

Comments
 (0)