mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
101127: Fix all tests related to VocabularyTreeview
This commit is contained in:
@@ -1,14 +1,22 @@
|
|||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
import { VocabularyTreeviewModalComponent } from './vocabulary-treeview-modal.component';
|
import { VocabularyTreeviewModalComponent } from './vocabulary-treeview-modal.component';
|
||||||
|
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
|
||||||
describe('VocabularyTreeviewModalComponent', () => {
|
describe('VocabularyTreeviewModalComponent', () => {
|
||||||
let component: VocabularyTreeviewModalComponent;
|
let component: VocabularyTreeviewModalComponent;
|
||||||
let fixture: ComponentFixture<VocabularyTreeviewModalComponent>;
|
let fixture: ComponentFixture<VocabularyTreeviewModalComponent>;
|
||||||
|
|
||||||
|
const modalStub = jasmine.createSpyObj('modalStub', ['close']);
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
declarations: [ VocabularyTreeviewModalComponent ]
|
imports: [ TranslateModule.forRoot() ],
|
||||||
|
declarations: [ VocabularyTreeviewModalComponent ],
|
||||||
|
providers: [
|
||||||
|
{ provide: NgbActiveModal, useValue: modalStub },
|
||||||
|
],
|
||||||
})
|
})
|
||||||
.compileComponents();
|
.compileComponents();
|
||||||
});
|
});
|
||||||
|
@@ -117,7 +117,7 @@ describe('VocabularyTreeviewComponent test suite', () => {
|
|||||||
comp = fixture.componentInstance;
|
comp = fixture.componentInstance;
|
||||||
compAsAny = comp;
|
compAsAny = comp;
|
||||||
comp.vocabularyOptions = vocabularyOptions;
|
comp.vocabularyOptions = vocabularyOptions;
|
||||||
comp.selectedItem = null;
|
comp.selectedItems = [];
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -138,10 +138,10 @@ describe('VocabularyTreeviewComponent test suite', () => {
|
|||||||
currentValue.otherInformation = {
|
currentValue.otherInformation = {
|
||||||
id: 'entryID'
|
id: 'entryID'
|
||||||
};
|
};
|
||||||
comp.selectedItem = currentValue;
|
comp.selectedItems = [currentValue.value];
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(comp.dataSource.data).toEqual([]);
|
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', () => {
|
it('should should init component properly with init value as VocabularyEntry', () => {
|
||||||
@@ -150,30 +150,30 @@ describe('VocabularyTreeviewComponent test suite', () => {
|
|||||||
currentValue.otherInformation = {
|
currentValue.otherInformation = {
|
||||||
id: 'entryID'
|
id: 'entryID'
|
||||||
};
|
};
|
||||||
comp.selectedItem = currentValue;
|
comp.selectedItems = [currentValue.value];
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(comp.dataSource.data).toEqual([]);
|
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', () => {
|
it('should call loadMore function', () => {
|
||||||
comp.loadMore(item);
|
comp.loadMore(item);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(vocabularyTreeviewServiceStub.loadMore).toHaveBeenCalledWith(item);
|
expect(vocabularyTreeviewServiceStub.loadMore).toHaveBeenCalledWith(item, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call loadMoreRoot function', () => {
|
it('should call loadMoreRoot function', () => {
|
||||||
const node = new TreeviewFlatNode(item);
|
const node = new TreeviewFlatNode(item);
|
||||||
comp.loadMoreRoot(node);
|
comp.loadMoreRoot(node);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(vocabularyTreeviewServiceStub.loadMoreRoot).toHaveBeenCalledWith(node);
|
expect(vocabularyTreeviewServiceStub.loadMoreRoot).toHaveBeenCalledWith(node, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call loadChildren function', () => {
|
it('should call loadChildren function', () => {
|
||||||
const node = new TreeviewFlatNode(item);
|
const node = new TreeviewFlatNode(item);
|
||||||
comp.loadChildren(node);
|
comp.loadChildren(node);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(vocabularyTreeviewServiceStub.loadMore).toHaveBeenCalledWith(node.item, true);
|
expect(vocabularyTreeviewServiceStub.loadMore).toHaveBeenCalledWith(node.item, [], true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit select event', () => {
|
it('should emit select event', () => {
|
||||||
@@ -188,7 +188,7 @@ describe('VocabularyTreeviewComponent test suite', () => {
|
|||||||
comp.nodeMap.set('test', new TreeviewFlatNode(item));
|
comp.nodeMap.set('test', new TreeviewFlatNode(item));
|
||||||
comp.search();
|
comp.search();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(vocabularyTreeviewServiceStub.searchByQuery).toHaveBeenCalledWith('test search');
|
expect(vocabularyTreeviewServiceStub.searchByQuery).toHaveBeenCalledWith('test search', []);
|
||||||
expect(comp.storedNodeMap).toEqual(nodeMap);
|
expect(comp.storedNodeMap).toEqual(nodeMap);
|
||||||
expect(comp.nodeMap).toEqual(emptyNodeMap);
|
expect(comp.nodeMap).toEqual(emptyNodeMap);
|
||||||
});
|
});
|
||||||
@@ -199,7 +199,7 @@ describe('VocabularyTreeviewComponent test suite', () => {
|
|||||||
comp.storedNodeMap.set('test', new TreeviewFlatNode(item2));
|
comp.storedNodeMap.set('test', new TreeviewFlatNode(item2));
|
||||||
comp.search();
|
comp.search();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(vocabularyTreeviewServiceStub.searchByQuery).toHaveBeenCalledWith('test search');
|
expect(vocabularyTreeviewServiceStub.searchByQuery).toHaveBeenCalledWith('test search', []);
|
||||||
expect(comp.storedNodeMap).toEqual(storedNodeMap);
|
expect(comp.storedNodeMap).toEqual(storedNodeMap);
|
||||||
expect(comp.nodeMap).toEqual(emptyNodeMap);
|
expect(comp.nodeMap).toEqual(emptyNodeMap);
|
||||||
});
|
});
|
||||||
|
@@ -192,7 +192,7 @@ describe('VocabularyTreeviewService test suite', () => {
|
|||||||
a: createSuccessfulRemoteDataObject(buildPaginatedList(pageInfo, [item, item2, item3]))
|
a: createSuccessfulRemoteDataObject(buildPaginatedList(pageInfo, [item, item2, item3]))
|
||||||
}));
|
}));
|
||||||
|
|
||||||
scheduler.schedule(() => service.initialize(vocabularyOptions, pageInfo));
|
scheduler.schedule(() => service.initialize(vocabularyOptions, pageInfo, []));
|
||||||
scheduler.flush();
|
scheduler.flush();
|
||||||
|
|
||||||
expect(serviceAsAny.vocabularyName).toEqual(vocabularyOptions.name);
|
expect(serviceAsAny.vocabularyName).toEqual(vocabularyOptions.name);
|
||||||
@@ -214,7 +214,7 @@ describe('VocabularyTreeviewService test suite', () => {
|
|||||||
b: createSuccessfulRemoteDataObject(item)
|
b: createSuccessfulRemoteDataObject(item)
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
scheduler.schedule(() => service.initialize(vocabularyOptions, pageInfo, 'root2'));
|
scheduler.schedule(() => service.initialize(vocabularyOptions, pageInfo, [], 'root2'));
|
||||||
scheduler.flush();
|
scheduler.flush();
|
||||||
|
|
||||||
expect(serviceAsAny.vocabularyName).toEqual(vocabularyOptions.name);
|
expect(serviceAsAny.vocabularyName).toEqual(vocabularyOptions.name);
|
||||||
@@ -233,11 +233,11 @@ describe('VocabularyTreeviewService test suite', () => {
|
|||||||
describe('loadMoreRoot', () => {
|
describe('loadMoreRoot', () => {
|
||||||
it('should call retrieveTopNodes properly', () => {
|
it('should call retrieveTopNodes properly', () => {
|
||||||
spyOn(serviceAsAny, 'retrieveTopNodes');
|
spyOn(serviceAsAny, 'retrieveTopNodes');
|
||||||
service.initialize(vocabularyOptions, new PageInfo());
|
service.initialize(vocabularyOptions, new PageInfo(), []);
|
||||||
serviceAsAny.dataChange.next(treeNodeListWithLoadMoreRoot);
|
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;
|
serviceAsAny.nodeMap = nodeMapWithChildren;
|
||||||
treeNodeListWithChildren.push(new TreeviewNode(child2, false, new PageInfo(), item));
|
treeNodeListWithChildren.push(new TreeviewNode(child2, false, new PageInfo(), item));
|
||||||
|
|
||||||
scheduler.schedule(() => service.loadMore(item));
|
scheduler.schedule(() => service.loadMore(item, []));
|
||||||
scheduler.flush();
|
scheduler.flush();
|
||||||
|
|
||||||
expect(serviceAsAny.dataChange.value).toEqual(treeNodeListWithChildren);
|
expect(serviceAsAny.dataChange.value).toEqual(treeNodeListWithChildren);
|
||||||
@@ -285,7 +285,7 @@ describe('VocabularyTreeviewService test suite', () => {
|
|||||||
treeNodeListWithChildren.push(childNode2);
|
treeNodeListWithChildren.push(childNode2);
|
||||||
treeNodeListWithChildren.push(loadMoreNode);
|
treeNodeListWithChildren.push(loadMoreNode);
|
||||||
|
|
||||||
scheduler.schedule(() => service.loadMore(item));
|
scheduler.schedule(() => service.loadMore(item, []));
|
||||||
scheduler.flush();
|
scheduler.flush();
|
||||||
|
|
||||||
expect(serviceAsAny.dataChange.value).toEqual(treeNodeListWithChildren);
|
expect(serviceAsAny.dataChange.value).toEqual(treeNodeListWithChildren);
|
||||||
@@ -319,7 +319,7 @@ describe('VocabularyTreeviewService test suite', () => {
|
|||||||
);
|
);
|
||||||
vocabularyOptions.query = 'root1-child1-child1';
|
vocabularyOptions.query = 'root1-child1-child1';
|
||||||
|
|
||||||
scheduler.schedule(() => service.searchByQuery(vocabularyOptions));
|
scheduler.schedule(() => service.searchByQuery(vocabularyOptions, []));
|
||||||
scheduler.flush();
|
scheduler.flush();
|
||||||
|
|
||||||
// We can't check the tree by comparing root TreeviewNodes directly in this particular test;
|
// We can't check the tree by comparing root TreeviewNodes directly in this particular test;
|
||||||
|
Reference in New Issue
Block a user