diff --git a/client/src/app/instance/instance.component.spec.ts b/client/src/app/instance/instance.component.spec.ts index 67713f0bddf0e877358a64e2af4622f23fff7bae..87d3560771d6621aadef7c0136611386ea9f95f3 100644 --- a/client/src/app/instance/instance.component.spec.ts +++ b/client/src/app/instance/instance.component.spec.ts @@ -10,6 +10,9 @@ import * as authActions from 'src/app/auth/auth.actions'; import { Component, EventEmitter, Input, Output } from '@angular/core'; import { Attribute, Instance } from '../metamodel/models'; 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', () => { @Component({ selector: 'app-navbar', template: '' }) @@ -49,15 +52,52 @@ describe('InstanceComponent', () => { expect(component).toBeDefined(); }); - // it('should execute ngOnInit lifecycle', (done) => { - // const spy = jest.spyOn(store, 'dispatch'); - // component.ngOnInit(); - // Promise.resolve(null).then(function() { - // expect(spy).toHaveBeenCalledTimes(1); - // expect(spy).toHaveBeenCalledWith(instanceActions.loadInstanceList()); - // done(); - // }); - // }); + it('should execute ngOnInit lifecycle', (done) => { + const instance: Instance = { + name: 'myInstance', + label: 'My Instance', + data_path: 'data/path', + config: { + 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', () => { appConfigServiceStub.baseHref = '/my-project'; diff --git a/client/src/app/instance/instance.component.ts b/client/src/app/instance/instance.component.ts index bb78d58ce124b33a795c7e5f88dc0fee2a80bc7a..e6466548b7b630885d3aa833d3da19c6f26f2c8f 100644 --- a/client/src/app/instance/instance.component.ts +++ b/client/src/app/instance/instance.component.ts @@ -51,6 +51,7 @@ export class InstanceComponent implements OnInit, OnDestroy { } ngOnInit() { + console.log(this.title); // Create a micro task that is processed after the current synchronous code // This micro task prevent the expression has changed after view init error Promise.resolve(null).then(() => this.store.dispatch(datasetFamilyActions.loadDatasetFamilyList()));