101127: Fix all tests related to VocabularyTreeview

This commit is contained in:
Nona Luypaert
2023-04-17 16:27:58 +02:00
parent 7a876c0276
commit f0d0cb5930
3 changed files with 27 additions and 19 deletions

View File

@@ -1,14 +1,22 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { VocabularyTreeviewModalComponent } from './vocabulary-treeview-modal.component';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule } from '@ngx-translate/core';
describe('VocabularyTreeviewModalComponent', () => {
let component: VocabularyTreeviewModalComponent;
let fixture: ComponentFixture<VocabularyTreeviewModalComponent>;
const modalStub = jasmine.createSpyObj('modalStub', ['close']);
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ VocabularyTreeviewModalComponent ]
imports: [ TranslateModule.forRoot() ],
declarations: [ VocabularyTreeviewModalComponent ],
providers: [
{ provide: NgbActiveModal, useValue: modalStub },
],
})
.compileComponents();
});

View File

@@ -117,7 +117,7 @@ describe('VocabularyTreeviewComponent test suite', () => {
comp = fixture.componentInstance;
compAsAny = comp;
comp.vocabularyOptions = vocabularyOptions;
comp.selectedItem = null;
comp.selectedItems = [];
});
afterEach(() => {
@@ -138,10 +138,10 @@ describe('VocabularyTreeviewComponent test suite', () => {
currentValue.otherInformation = {
id: 'entryID'
};
comp.selectedItem = currentValue;
comp.selectedItems = [currentValue.value];
fixture.detectChanges();
expect(comp.dataSource.data).toEqual([]);
expect(vocabularyTreeviewServiceStub.initialize).toHaveBeenCalledWith(comp.vocabularyOptions, new PageInfo(), null);
expect(vocabularyTreeviewServiceStub.initialize).toHaveBeenCalledWith(comp.vocabularyOptions, new PageInfo(), ['testValue'], null);
});
it('should should init component properly with init value as VocabularyEntry', () => {
@@ -150,30 +150,30 @@ describe('VocabularyTreeviewComponent test suite', () => {
currentValue.otherInformation = {
id: 'entryID'
};
comp.selectedItem = currentValue;
comp.selectedItems = [currentValue.value];
fixture.detectChanges();
expect(comp.dataSource.data).toEqual([]);
expect(vocabularyTreeviewServiceStub.initialize).toHaveBeenCalledWith(comp.vocabularyOptions, new PageInfo(), null);
expect(vocabularyTreeviewServiceStub.initialize).toHaveBeenCalledWith(comp.vocabularyOptions, new PageInfo(), ['testValue'], null);
});
it('should call loadMore function', () => {
comp.loadMore(item);
fixture.detectChanges();
expect(vocabularyTreeviewServiceStub.loadMore).toHaveBeenCalledWith(item);
expect(vocabularyTreeviewServiceStub.loadMore).toHaveBeenCalledWith(item, []);
});
it('should call loadMoreRoot function', () => {
const node = new TreeviewFlatNode(item);
comp.loadMoreRoot(node);
fixture.detectChanges();
expect(vocabularyTreeviewServiceStub.loadMoreRoot).toHaveBeenCalledWith(node);
expect(vocabularyTreeviewServiceStub.loadMoreRoot).toHaveBeenCalledWith(node, []);
});
it('should call loadChildren function', () => {
const node = new TreeviewFlatNode(item);
comp.loadChildren(node);
fixture.detectChanges();
expect(vocabularyTreeviewServiceStub.loadMore).toHaveBeenCalledWith(node.item, true);
expect(vocabularyTreeviewServiceStub.loadMore).toHaveBeenCalledWith(node.item, [], true);
});
it('should emit select event', () => {
@@ -188,7 +188,7 @@ describe('VocabularyTreeviewComponent test suite', () => {
comp.nodeMap.set('test', new TreeviewFlatNode(item));
comp.search();
fixture.detectChanges();
expect(vocabularyTreeviewServiceStub.searchByQuery).toHaveBeenCalledWith('test search');
expect(vocabularyTreeviewServiceStub.searchByQuery).toHaveBeenCalledWith('test search', []);
expect(comp.storedNodeMap).toEqual(nodeMap);
expect(comp.nodeMap).toEqual(emptyNodeMap);
});
@@ -199,7 +199,7 @@ describe('VocabularyTreeviewComponent test suite', () => {
comp.storedNodeMap.set('test', new TreeviewFlatNode(item2));
comp.search();
fixture.detectChanges();
expect(vocabularyTreeviewServiceStub.searchByQuery).toHaveBeenCalledWith('test search');
expect(vocabularyTreeviewServiceStub.searchByQuery).toHaveBeenCalledWith('test search', []);
expect(comp.storedNodeMap).toEqual(storedNodeMap);
expect(comp.nodeMap).toEqual(emptyNodeMap);
});

View File

@@ -192,7 +192,7 @@ describe('VocabularyTreeviewService test suite', () => {
a: createSuccessfulRemoteDataObject(buildPaginatedList(pageInfo, [item, item2, item3]))
}));
scheduler.schedule(() => service.initialize(vocabularyOptions, pageInfo));
scheduler.schedule(() => service.initialize(vocabularyOptions, pageInfo, []));
scheduler.flush();
expect(serviceAsAny.vocabularyName).toEqual(vocabularyOptions.name);
@@ -214,7 +214,7 @@ describe('VocabularyTreeviewService test suite', () => {
b: createSuccessfulRemoteDataObject(item)
})
);
scheduler.schedule(() => service.initialize(vocabularyOptions, pageInfo, 'root2'));
scheduler.schedule(() => service.initialize(vocabularyOptions, pageInfo, [], 'root2'));
scheduler.flush();
expect(serviceAsAny.vocabularyName).toEqual(vocabularyOptions.name);
@@ -233,11 +233,11 @@ describe('VocabularyTreeviewService test suite', () => {
describe('loadMoreRoot', () => {
it('should call retrieveTopNodes properly', () => {
spyOn(serviceAsAny, 'retrieveTopNodes');
service.initialize(vocabularyOptions, new PageInfo());
service.initialize(vocabularyOptions, new PageInfo(), []);
serviceAsAny.dataChange.next(treeNodeListWithLoadMoreRoot);
service.loadMoreRoot(loadMoreRootFlatNode);
service.loadMoreRoot(loadMoreRootFlatNode, []);
expect(serviceAsAny.retrieveTopNodes).toHaveBeenCalledWith(loadMoreRootFlatNode.pageInfo, treeNodeList);
expect(serviceAsAny.retrieveTopNodes).toHaveBeenCalledWith(loadMoreRootFlatNode.pageInfo, treeNodeList, []);
});
});
@@ -263,7 +263,7 @@ describe('VocabularyTreeviewService test suite', () => {
serviceAsAny.nodeMap = nodeMapWithChildren;
treeNodeListWithChildren.push(new TreeviewNode(child2, false, new PageInfo(), item));
scheduler.schedule(() => service.loadMore(item));
scheduler.schedule(() => service.loadMore(item, []));
scheduler.flush();
expect(serviceAsAny.dataChange.value).toEqual(treeNodeListWithChildren);
@@ -285,7 +285,7 @@ describe('VocabularyTreeviewService test suite', () => {
treeNodeListWithChildren.push(childNode2);
treeNodeListWithChildren.push(loadMoreNode);
scheduler.schedule(() => service.loadMore(item));
scheduler.schedule(() => service.loadMore(item, []));
scheduler.flush();
expect(serviceAsAny.dataChange.value).toEqual(treeNodeListWithChildren);
@@ -319,7 +319,7 @@ describe('VocabularyTreeviewService test suite', () => {
);
vocabularyOptions.query = 'root1-child1-child1';
scheduler.schedule(() => service.searchByQuery(vocabularyOptions));
scheduler.schedule(() => service.searchByQuery(vocabularyOptions, []));
scheduler.flush();
// We can't check the tree by comparing root TreeviewNodes directly in this particular test;