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

WIP: Tests on instance

parent d9633875
No related branches found
No related tags found
2 merge requests!29Develop,!17Resolve "Add tests for instance module"
...@@ -10,6 +10,9 @@ import * as authActions from 'src/app/auth/auth.actions'; ...@@ -10,6 +10,9 @@ import * as authActions from 'src/app/auth/auth.actions';
import { Component, EventEmitter, Input, Output } from '@angular/core'; import { Component, EventEmitter, Input, Output } from '@angular/core';
import { Attribute, Instance } from '../metamodel/models'; import { Attribute, Instance } from '../metamodel/models';
import { UserProfile } from '../auth/user-profile.model'; import { UserProfile } from '../auth/user-profile.model';
import * as datasetFamilyActions from '../metamodel/actions/dataset-family.actions';
import * as datasetActions from '../metamodel/actions/dataset.actions';
import * as surveyActions from '../metamodel/actions/survey.actions';
describe('InstanceComponent', () => { describe('InstanceComponent', () => {
@Component({ selector: 'app-navbar', template: '' }) @Component({ selector: 'app-navbar', template: '' })
...@@ -49,15 +52,52 @@ describe('InstanceComponent', () => { ...@@ -49,15 +52,52 @@ describe('InstanceComponent', () => {
expect(component).toBeDefined(); expect(component).toBeDefined();
}); });
// it('should execute ngOnInit lifecycle', (done) => { it('should execute ngOnInit lifecycle', (done) => {
// const spy = jest.spyOn(store, 'dispatch'); const instance: Instance = {
// component.ngOnInit(); name: 'myInstance',
// Promise.resolve(null).then(function() { label: 'My Instance',
// expect(spy).toHaveBeenCalledTimes(1); data_path: 'data/path',
// expect(spy).toHaveBeenCalledWith(instanceActions.loadInstanceList()); config: {
// done(); design: {
// }); design_color: 'green',
// }); design_background_color: 'darker green',
design_logo: 'path/to/logo',
design_favicon: 'path/to/favicon'
},
home: {
home_component: 'HomeComponent',
home_config: {
home_component_text: 'Description',
home_component_logo: 'path/to/logo'
}
},
search: {
search_by_criteria_allowed: true,
search_by_criteria_label: 'Search',
search_multiple_allowed: true,
search_multiple_label: 'Search multiple',
search_multiple_all_datasets_selected: false
},
documentation: {
documentation_allowed: true,
documentation_label: 'Documentation'
}
},
nb_dataset_families: 1,
nb_datasets: 2
};
component.instance = of(instance);
component.title = '<title id="title">Default instance</title>' as HTMLLinkElement;
const spy = jest.spyOn(store, 'dispatch');
component.ngOnInit();
Promise.resolve(null).then(function() {
expect(spy).toHaveBeenCalledTimes(3);
expect(spy).toHaveBeenCalledWith(datasetFamilyActions.loadDatasetFamilyList());
expect(spy).toHaveBeenCalledWith(datasetActions.loadDatasetList());
expect(spy).toHaveBeenCalledWith(surveyActions.loadSurveyList());
done();
});
});
it('#getBaseHref() should return base href config key value', () => { it('#getBaseHref() should return base href config key value', () => {
appConfigServiceStub.baseHref = '/my-project'; appConfigServiceStub.baseHref = '/my-project';
......
...@@ -51,6 +51,7 @@ export class InstanceComponent implements OnInit, OnDestroy { ...@@ -51,6 +51,7 @@ 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