Skip to content
Snippets Groups Projects
Commit 2987e333 authored by Tifenn Guillas's avatar Tifenn Guillas
Browse files

WIP: Tests with dom

parent 9e535a9b
No related branches found
No related tags found
2 merge requests!29Develop,!17Resolve "Add tests for instance module"
...@@ -46,6 +46,9 @@ describe('InstanceComponent', () => { ...@@ -46,6 +46,9 @@ describe('InstanceComponent', () => {
fixture = TestBed.createComponent(InstanceComponent); fixture = TestBed.createComponent(InstanceComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
store = TestBed.inject(MockStore); store = TestBed.inject(MockStore);
document.body.innerHTML =
'<title id="title">Default title</title>' +
'<link id="favicon" href="">';
})); }));
it('should create the component', () => { it('should create the component', () => {
...@@ -87,14 +90,22 @@ describe('InstanceComponent', () => { ...@@ -87,14 +90,22 @@ describe('InstanceComponent', () => {
nb_datasets: 2 nb_datasets: 2
}; };
component.instance = of(instance); component.instance = of(instance);
component.title = '<title id="title">Default instance</title>' as HTMLLinkElement;
const spy = jest.spyOn(store, 'dispatch'); const spy = jest.spyOn(store, 'dispatch');
const expectedLinks = [
{ label: 'Home', icon: 'fas fa-home', routerLink: 'home' },
{ label: 'Search', icon: 'fas fa-search', routerLink: 'search' },
{ label: 'Search multiple', icon: 'fas fa-search-plus', routerLink: 'search-multiple' },
{ label: 'Documentation', icon: 'fas fa-question', routerLink: 'documentation' }
];
component.ngOnInit(); component.ngOnInit();
Promise.resolve(null).then(function() { Promise.resolve(null).then(function() {
expect(spy).toHaveBeenCalledTimes(3); expect(spy).toHaveBeenCalledTimes(3);
expect(spy).toHaveBeenCalledWith(datasetFamilyActions.loadDatasetFamilyList()); expect(spy).toHaveBeenCalledWith(datasetFamilyActions.loadDatasetFamilyList());
expect(spy).toHaveBeenCalledWith(datasetActions.loadDatasetList()); expect(spy).toHaveBeenCalledWith(datasetActions.loadDatasetList());
expect(spy).toHaveBeenCalledWith(surveyActions.loadSurveyList()); expect(spy).toHaveBeenCalledWith(surveyActions.loadSurveyList());
expect(component.links).toEqual(expectedLinks);
expect(component.favIcon.href).toEqual('http://localhost/undefined/download-instance-file/myInstance/path/to/favicon');
expect(component.title.textContent).toEqual('My Instance');
done(); done();
}); });
}); });
......
...@@ -51,7 +51,6 @@ export class InstanceComponent implements OnInit, OnDestroy { ...@@ -51,7 +51,6 @@ export class InstanceComponent implements OnInit, OnDestroy {
} }
ngOnInit() { ngOnInit() {
console.log(this.title);
// Create a micro task that is processed after the current synchronous code // Create a micro task that is processed after the current synchronous code
// This micro task prevent the expression has changed after view init error // This micro task prevent the expression has changed after view init error
Promise.resolve(null).then(() => this.store.dispatch(datasetFamilyActions.loadDatasetFamilyList())); Promise.resolve(null).then(() => this.store.dispatch(datasetFamilyActions.loadDatasetFamilyList()));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment