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

Tests => DONE, Comments => DONE

parent 60df09f5
No related branches found
No related tags found
2 merge requests!29Develop,!12Resolve "Add tests for instance home module"
<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>
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');
});
});
......@@ -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}`;
}
}
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');
});
});
......@@ -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;
}
}
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