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

Tests on containers => DONE

parent c44faa19
No related branches found
No related tags found
2 merge requests!29Develop,!4Resolve "Add tests for instance documentation module"
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 { DatasetListComponent } from './dataset-list.component';
import { AppConfigService } from 'src/app/app-config.service';
import { Attribute, Dataset, DatasetFamily, Survey } from '../../../metamodel/models';
import * as datasetActions from '../../../metamodel/actions/dataset.actions';
describe('DatasetListComponent', () => {
@Component({ selector: 'app-spinner', template: '' })
class SpinnerStubComponent { }
@Component({ selector: '<app-dataset-by-family', template: '' })
class DatasetByFamilyStubComponent {
@Input() datasetList: Dataset[];
@Input() datasetFamilyList: DatasetFamily[];
@Input() surveyList: Survey[];
@Input() instanceSelected: string;
}
let component: DatasetListComponent;
let fixture: ComponentFixture<DatasetListComponent>;
let store: MockStore;
let appConfigServiceStub = new AppConfigService();
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule],
declarations: [
DatasetListComponent,
SpinnerStubComponent,
DatasetByFamilyStubComponent,
],
providers: [
provideMockStore({ }),
{ provide: AppConfigService, useValue: appConfigServiceStub },
]
}).compileComponents();
fixture = TestBed.createComponent(DatasetListComponent);
component = fixture.componentInstance;
store = TestBed.inject(MockStore);
}));
it('should create the component', () => {
expect(component).toBeDefined();
});
it('should execute ngOnInit lifecycle', () => {
const spy = jest.spyOn(store, 'dispatch');
component.ngOnInit();
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith(datasetActions.loadDatasetList());
});
});
......@@ -2,12 +2,10 @@ import { Component, Input } from '@angular/core';
import { TestBed, waitForAsync, ComponentFixture } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { of } from 'rxjs';
import { provideMockStore, MockStore } from '@ngrx/store/testing';
import { DocumentationComponent } from './documentation.component';
import { AppConfigService } from 'src/app/app-config.service';
import * as authActions from 'src/app/auth/auth.actions';
import { Attribute } from '../../../metamodel/models';
import * as attributeActions from '../../../metamodel/actions/attribute.actions';
......@@ -24,7 +22,7 @@ describe('DocumentationComponent', () => {
let component: DocumentationComponent;
let fixture: ComponentFixture<DocumentationComponent>;
let store: MockStore;
let config: AppConfigService
let appConfigServiceStub = new AppConfigService();
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
......@@ -32,17 +30,16 @@ describe('DocumentationComponent', () => {
declarations: [
DocumentationComponent,
SpinnerStubComponent,
OutputListStubComponent
OutputListStubComponent,
],
providers: [
provideMockStore({ }),
AppConfigService
{ provide: AppConfigService, useValue: appConfigServiceStub },
]
}).compileComponents();
fixture = TestBed.createComponent(DocumentationComponent);
component = fixture.componentInstance;
store = TestBed.inject(MockStore);
config = TestBed.inject(AppConfigService);
}));
it('should create the component', () => {
......@@ -57,35 +54,9 @@ describe('DocumentationComponent', () => {
});
it('#getUrlServer() should return server URL address', () => {
// console.log(component.getUrlServer());
expect(component.getUrlServer()).toBeTruthy();
appConfigServiceStub.apiUrl = 'http://test.com';
expect(component.getUrlServer()).toBe('http://test.com');
appConfigServiceStub.apiUrl = '/testing';
expect(component.getUrlServer()).toBe('http://localhost/testing');
});
// it('login() should dispatch login action', () => {
// const spy = jest.spyOn(store, 'dispatch');
// component.login();
// expect(spy).toHaveBeenCalledTimes(1);
// expect(spy).toHaveBeenCalledWith(authActions.login());
// });
//
// it('logout() should dispatch logout action', () => {
// const spy = jest.spyOn(store, 'dispatch');
// component.logout();
// expect(spy).toHaveBeenCalledTimes(1);
// expect(spy).toHaveBeenCalledWith(authActions.logout());
// });
//
// it('openEditProfile() should dispatch open edit profile action', () => {
// const spy = jest.spyOn(store, 'dispatch');
// component.openEditProfile();
// expect(spy).toHaveBeenCalledTimes(1);
// expect(spy).toHaveBeenCalledWith(authActions.openEditProfile());
// });
//
// it('isAnisAdmin() should return observable true if user is authenticated', () => {
// component.userRoles = of(['user']);
// component.isAnisAdmin().subscribe(isAuthenticated => expect(isAuthenticated).toBeFalsy());
// component.userRoles = of(['user', 'anis_admin']);
// component.isAnisAdmin().subscribe(isAuthenticated => expect(isAuthenticated).toBeTruthy());
// });
});
......@@ -55,7 +55,6 @@ export class DocumentationComponent implements OnInit {
* @return string
*/
getUrlServer(): string {
console.log(this.config);
if (!this.config.apiUrl.startsWith('http')) {
const url = window.location;
return url.protocol + '//' + url.host + 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