Skip to content

Commit 251975d

Browse files
committed
[DSC-1864] revert treeview changes after alignment with 7.6.2
1 parent 88ca250 commit 251975d

2 files changed

Lines changed: 105 additions & 87 deletions

File tree

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)