From 0cd825dd1a48190a19bbb1228424ddc620e1b027 Mon Sep 17 00:00:00 2001 From: Tifenn Guillas <tifenn.guillas@lam.fr> Date: Thu, 23 Sep 2021 10:21:07 +0200 Subject: [PATCH] Tests => DONE, Comments => DONE --- .../home/components/welcome.component.html | 4 +- .../home/components/welcome.component.spec.ts | 64 +++++++++++++++++++ .../home/components/welcome.component.ts | 9 ++- .../app/instance/home/home.component.spec.ts | 48 ++++++++++++++ .../src/app/instance/home/home.component.ts | 9 ++- 5 files changed, 128 insertions(+), 6 deletions(-) create mode 100644 client/src/app/instance/home/components/welcome.component.spec.ts create mode 100644 client/src/app/instance/home/home.component.spec.ts diff --git a/client/src/app/instance/home/components/welcome.component.html b/client/src/app/instance/home/components/welcome.component.html index 0a1998a5..b4132609 100644 --- a/client/src/app/instance/home/components/welcome.component.html +++ b/client/src/app/instance/home/components/welcome.component.html @@ -1,6 +1,6 @@ <div class="row align-items-center jumbotron"> <div class="col-6 col-md-4 order-md-2 mx-auto text-center"> - <img class="img-fluid mb-3 mb-md-0" src="{{ getLogoSrc() }}" alt=""> + <img class="img-fluid mb-3 mb-md-0" src="{{ getLogoSrc() }}" alt="Instance logo"> </div> <div class="col-md-8 order-md-1 text-justify pr-md-5" [innerHtml]="instance.config.home.home_config.home_component_text"></div> -</div> \ No newline at end of file +</div> diff --git a/client/src/app/instance/home/components/welcome.component.spec.ts b/client/src/app/instance/home/components/welcome.component.spec.ts new file mode 100644 index 00000000..fdc25938 --- /dev/null +++ b/client/src/app/instance/home/components/welcome.component.spec.ts @@ -0,0 +1,64 @@ +import { Component, Input } from '@angular/core'; +import { TestBed, waitForAsync, ComponentFixture } from '@angular/core/testing'; +import { RouterTestingModule } from '@angular/router/testing'; + +import { provideMockStore, MockStore } from '@ngrx/store/testing'; + +import { WelcomeComponent } from './welcome.component'; +import { AppConfigService } from 'src/app/app-config.service'; + +describe('WelcomeComponent', () => { + let component: WelcomeComponent; + let fixture: ComponentFixture<WelcomeComponent>; + + beforeEach(waitForAsync(() => { + TestBed.configureTestingModule({ + imports: [RouterTestingModule], + declarations: [WelcomeComponent] + }).compileComponents(); + fixture = TestBed.createComponent(WelcomeComponent); + component = fixture.componentInstance; + })); + + it('should create the component', () => { + expect(component).toBeDefined(); + }); + + it('#getLogoSrc() should return logo URL address', () => { + component.apiUrl = 'http://test.com'; + component.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: true + }, + documentation: { + documentation_allowed: true, + documentation_label: 'Documentation' + } + }, + nb_dataset_families: 1, + nb_datasets: 2 + }; + expect(component.getLogoSrc()).toBe('http://test.com/download-instance-file/myInstance/path/to/logo'); + }); +}); diff --git a/client/src/app/instance/home/components/welcome.component.ts b/client/src/app/instance/home/components/welcome.component.ts index 96095b04..8f54362d 100644 --- a/client/src/app/instance/home/components/welcome.component.ts +++ b/client/src/app/instance/home/components/welcome.component.ts @@ -13,7 +13,7 @@ import { Instance } from 'src/app/metamodel/models'; /** * @class - * @classdesc Home container. + * @classdesc Welcome component. */ @Component({ selector: 'app-welcome', @@ -24,7 +24,12 @@ export class WelcomeComponent { @Input() instance: Instance; @Input() apiUrl: string; - getLogoSrc() { + /** + * Returns the logo url. + * + * @return string + */ + getLogoSrc(): string { return `${this.apiUrl}/download-instance-file/${this.instance.name}/${this.instance.config.home.home_config.home_component_logo}`; } } diff --git a/client/src/app/instance/home/home.component.spec.ts b/client/src/app/instance/home/home.component.spec.ts new file mode 100644 index 00000000..80a1b213 --- /dev/null +++ b/client/src/app/instance/home/home.component.spec.ts @@ -0,0 +1,48 @@ +import { Component, Input } from '@angular/core'; +import { TestBed, waitForAsync, ComponentFixture } from '@angular/core/testing'; +import { RouterTestingModule } from '@angular/router/testing'; + +import { provideMockStore, MockStore } from '@ngrx/store/testing'; + +import { HomeComponent } from './home.component'; +import { AppConfigService } from 'src/app/app-config.service'; +import { Instance } from '../../metamodel/models'; + +describe('HomeComponent', () => { + @Component({ selector: '<app-welcome', template: '' }) + class WelcomeStubComponent { + @Input() instance: Instance; + @Input() apiUrl: string; + } + + let component: HomeComponent; + let fixture: ComponentFixture<HomeComponent>; + let store: MockStore; + let appConfigServiceStub = new AppConfigService(); + + beforeEach(waitForAsync(() => { + TestBed.configureTestingModule({ + imports: [RouterTestingModule], + declarations: [ + HomeComponent, + WelcomeStubComponent + ], + providers: [ + provideMockStore({ }), + { provide: AppConfigService, useValue: appConfigServiceStub }, + ] + }).compileComponents(); + fixture = TestBed.createComponent(HomeComponent); + component = fixture.componentInstance; + store = TestBed.inject(MockStore); + })); + + it('should create the component', () => { + expect(component).toBeDefined(); + }); + + it('#getApiUrl() should return API URL address', () => { + appConfigServiceStub.apiUrl = 'http://test.com'; + expect(component.getApiUrl()).toBe('http://test.com'); + }); +}); diff --git a/client/src/app/instance/home/home.component.ts b/client/src/app/instance/home/home.component.ts index e120190f..48dbbd6f 100644 --- a/client/src/app/instance/home/home.component.ts +++ b/client/src/app/instance/home/home.component.ts @@ -18,7 +18,7 @@ import { AppConfigService } from 'src/app/app-config.service'; /** * @class - * @classdesc Home container. + * @classdesc Home component. */ @Component({ selector: 'app-home', @@ -31,7 +31,12 @@ export class HomeComponent { this.instance = this.store.select(instanceSelector.selectInstanceByRouteName); } - getApiUrl() { + /** + * Returns API url. + * + * @return string + */ + getApiUrl(): string { return this.config.apiUrl; } } -- GitLab