Skip to content

Commit

Permalink
Merged in task/dspace-cris-2023_02_x/DSC-1864_fixes (pull request DSp…
Browse files Browse the repository at this point in the history
…ace#2360)

[DSC-1864] revert treeview changes after alignment with 7.6.2

Approved-by: Andrea Barbasso
  • Loading branch information
atarix83 authored and Andrea Barbasso committed Oct 14, 2024
2 parents 1db5098 + 8373868 commit 2efde9c
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 98 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<ds-alert *ngIf="description" [content]="description" [type]="'alert-info'"></ds-alert>
<div class="treeview-header row mb-1">
<div class="col-12">
<ds-alert *ngIf="description" [content]="description" [type]="AlertType.Info"></ds-alert>
<div class="treeview-header row">
<div class="col-12 d-flex">
<div class="input-group">
<input type="text" class="form-control" [(ngModel)]="searchText" (keyup.enter)="search()"
[placeholder]="'vocabulary-treeview.search.form.search-placeholder' | translate">
<input type="text" class="form-control" [(ngModel)]="searchText" (keyup.enter)="search()">
<div class="input-group-append" id="button-addon4">
<button class="btn btn-outline-primary" type="button" (click)="search()" [disabled]="!isSearchEnabled()">
{{'vocabulary-treeview.search.form.search' | translate}}
</button>
<button class="btn btn-outline-secondary" type="button" (click)="reset()">
{{'vocabulary-treeview.search.form.reset' | translate}}
</button>
<button class="btn btn-outline-primary" type="button" (click)="add()" [disabled]="this.vocabularyOptions.closed">
{{'vocabulary-treeview.search.form.add' | translate}}
<button class="btn btn-primary" type="button" (click)="search()" [disabled]="!isSearchEnabled()">
<span><i class="fas fa-search"></i> {{'vocabulary-treeview.search.form.search' | translate}}</span>
</button>
</div>
</div>
<button class="btn btn-secondary ml-3 flex-shrink-0" type="button" (click)="reset()">
<span><i class="fas fa-eraser"></i> {{'vocabulary-treeview.search.form.reset' | translate}}</span>
</button>
<button *ngIf="showAdd && !this.vocabularyOptions.closed" class="btn btn-secondary ml-3 flex-shrink-0" type="button" (click)="add()">
<span><i class="fas fa-plus"></i> {{'vocabulary-treeview.search.form.add' | translate}}</span>
</button>
</div>
</div>
<div class="treeview-container">
Expand Down Expand Up @@ -59,7 +58,7 @@ <h2 *ngIf="!(loading | async) && dataSource.data.length === 0" class="h4 text-ce
<button type="button" class="btn btn-default px-2 mr-1" cdkTreeNodeToggle
[attr.aria-label]="'toggle ' + node.name"
(click)="loadChildren(node)">
<i class="fas fa-fw {{treeControl.isExpanded(node) ? 'fa-angle-down' : 'fa-angle-right'}}"></i>
<span class="fas fa-fw {{treeControl.isExpanded(node) ? 'fa-angle-down' : 'fa-angle-right'}}"></span>
</button>

<label *ngIf="multiSelect" class="d-flex align-items-center m-0 p-0 form-check"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { ChangeDetectorRef, Component, NO_ERRORS_SCHEMA } from '@angular/core';
import { Component, NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, inject, TestBed, waitForAsync } from '@angular/core/testing';
import { CdkTreeModule } from '@angular/cdk/tree';
import { By } from '@angular/platform-browser';

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

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

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

let comp: VocabularyTreeviewComponent;
let compAsAny: any;
let fixture: ComponentFixture<VocabularyTreeviewComponent>;
let initialState;
let de;

const item = new VocabularyEntryDetail();
item.id = 'node1';
const item2 = new VocabularyEntryDetail();
item2.id = 'node2';
const entryWithAuthority = new VocabularyEntryDetail();
entryWithAuthority.authority = 'entryWithAuthority';
entryWithAuthority.id = 'entryWithAuthority';
entryWithAuthority.value = 'test';
const entryWithoutAuthority = new VocabularyEntryDetail();
entryWithoutAuthority.id = 'entryWithoutAuthority';
entryWithoutAuthority.value = 'test2';
const emptyNodeMap = new Map<string, TreeviewFlatNode>();
const storedNodeMap = new Map<string, TreeviewFlatNode>().set('test', new TreeviewFlatNode(item2));
const nodeMap = new Map<string, TreeviewFlatNode>().set('test', new TreeviewFlatNode(item));
const vocabularyOptions = new VocabularyOptions('vocabularyTest', 'false');
const vocabularyOptions = new VocabularyOptions('vocabularyTest', null, null, false);
const modalStub = jasmine.createSpyObj('modalStub', ['close']);
const vocabularyTreeviewServiceStub = jasmine.createSpyObj('VocabularyTreeviewService', {
initialize: jasmine.createSpy('initialize'),
Expand All @@ -59,25 +60,10 @@ describe('VocabularyTreeviewComponent test suite', () => {
clearSearchTopRequests: jasmine.createSpy('clearSearchTopRequests')
});

initialState = {
core: {
auth: {
authenticated: true,
loaded: true,
blocking: false,
loading: false,
authToken: new AuthTokenInfo('test_token'),
userId: 'testid',
authMethods: []
}
}
};

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [
CdkTreeModule,
StoreModule.forRoot({ auth: authReducer }, storeModuleConfig),
TranslateModule.forRoot()
],
declarations: [
Expand All @@ -88,8 +74,6 @@ describe('VocabularyTreeviewComponent test suite', () => {
{ provide: VocabularyTreeviewService, useValue: vocabularyTreeviewServiceStub },
{ provide: VocabularyService, useValue: vocabularyServiceStub },
{ provide: NgbActiveModal, useValue: modalStub },
provideMockStore({ initialState }),
ChangeDetectorRef,
VocabularyTreeviewComponent
],
schemas: [NO_ERRORS_SCHEMA]
Expand Down Expand Up @@ -144,10 +128,10 @@ describe('VocabularyTreeviewComponent test suite', () => {
currentValue.otherInformation = {
id: 'entryID'
};
comp.selectedItems = [currentValue.value];
comp.selectedItems = [currentValue];
fixture.detectChanges();
expect(comp.dataSource.data).toEqual([]);
expect(vocabularyTreeviewServiceStub.initialize).toHaveBeenCalledWith(comp.vocabularyOptions, new PageInfo(), ['testValue'], null);
expect(vocabularyTreeviewServiceStub.initialize).toHaveBeenCalledWith(comp.vocabularyOptions, new PageInfo(), ['entryID'], 'entryID');
});

it('should should init component properly with init value as VocabularyEntry', () => {
Expand All @@ -156,10 +140,20 @@ describe('VocabularyTreeviewComponent test suite', () => {
currentValue.otherInformation = {
id: 'entryID'
};
comp.selectedItems = [currentValue.value];
comp.selectedItems = [currentValue];
fixture.detectChanges();
expect(comp.dataSource.data).toEqual([]);
expect(vocabularyTreeviewServiceStub.initialize).toHaveBeenCalledWith(comp.vocabularyOptions, new PageInfo(), ['entryID'], 'entryID');
});

it('should should init component properly with init value as VocabularyEntryDetail', () => {
const currentValue = new VocabularyEntryDetail();
currentValue.value = 'testValue';
currentValue.id = 'entryID';
comp.selectedItems = [currentValue];
fixture.detectChanges();
expect(comp.dataSource.data).toEqual([]);
expect(vocabularyTreeviewServiceStub.initialize).toHaveBeenCalledWith(comp.vocabularyOptions, new PageInfo(), ['testValue'], null);
expect(vocabularyTreeviewServiceStub.initialize).toHaveBeenCalledWith(comp.vocabularyOptions, new PageInfo(), ['entryID'], 'entryID');
});

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

it('should emit select event', () => {
spyOn(comp, 'onSelect');
comp.onSelect(item);
it('should emit proper FormFieldMetadataValueObject when VocabularyEntryDetail has authority', () => {
spyOn(compAsAny, 'getSelectedEntryIds').and.returnValue([]);
spyOn(comp.select, 'emit');
comp.onSelect(entryWithAuthority);

const expected = new FormFieldMetadataValueObject(entryWithAuthority.value, null, null, entryWithAuthority.authority);
expect(comp.select.emit).toHaveBeenCalledWith(expected);
});

it('should emit proper FormFieldMetadataValueObject when VocabularyEntryDetail has no authority', () => {
spyOn(compAsAny, 'getSelectedEntryIds').and.returnValue([]);
spyOn(comp.select, 'emit');
comp.onSelect(entryWithoutAuthority);

const expected = new FormFieldMetadataValueObject(entryWithoutAuthority.value);
expect(comp.select.emit).toHaveBeenCalledWith(expected);
});

it('should emit deselect when entry is already present', () => {
spyOn(compAsAny, 'getSelectedEntryIds').and.returnValue([entryWithAuthority.id]);
spyOn(comp.select, 'emit');
spyOn(comp.deselect, 'emit');
comp.onSelect(entryWithAuthority);

expect(comp.onSelect).toHaveBeenCalledWith(item);
expect(comp.deselect.emit).toHaveBeenCalled();
});

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

vocabularyOptions: VocabularyOptions = new VocabularyOptions('vocabularyTest', 'false');
vocabularyOptions: VocabularyOptions = new VocabularyOptions('vocabularyTest', null, null, false);
preloadLevel = 2;

}
Loading

0 comments on commit 2efde9c

Please sign in to comment.