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

WIP: tests on containers

parent afed17c1
No related branches found
No related tags found
2 merge requests!113Develop,!101Resolve "Fix SQ issues + add tests"
This commit is part of merge request !101. Comments created here will be created in the context of that merge request.
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { provideMockStore, MockStore } from '@ngrx/store/testing';
import { Component, Input } from '@angular/core';
import { ResultComponent } from './result.component';
import * as fromMetamodel from '../../metamodel/reducers';
import * as fromSearch from '../store/search.reducer';
import * as searchActions from '../store/search.action';
import { Dataset, Attribute } from 'src/app/metamodel/model';
import { Criterion, SearchQueryParams } from '../store/model';
import { ScrollTopService } from '../../shared/service/sroll-top.service';
import { RouterLinkDirectiveStub } from '../../../settings/test-data/router-link-directive-stub';
fdescribe('[Search] Container: ResultComponent', () => {
@Component({ selector: 'app-result-download', template: '' })
class DownloadSectionStubComponent {
@Input() datasetName: string;
@Input() datasetList: Dataset[];
@Input() dataLength: number;
@Input() apiPath: string;
@Input() criteriaList: Criterion[];
@Input() outputList: number[];
}
@Component({ selector: 'app-result-summary', template: '' })
class SummarySectionStubComponent {
@Input() datasetAttributeList: Attribute[];
@Input() criteriaList: Criterion[];
@Input() outputList: number[];
}
@Component({ selector: 'app-result-url-display', template: '' })
class UrlDisplaySectionStubComponent {
@Input() apiPath: string;
@Input() datasetName: string;
@Input() criteriaList: Criterion[];
@Input() outputList: number[];
}
@Component({ selector: 'app-result-datatable', template: '' })
class DatatableSectionStubComponent {
@Input() apiPath: string;
@Input() datasetName: string;
@Input() datasetList: Dataset[];
@Input() queryParams: SearchQueryParams;
@Input() datasetAttributeList: Attribute[];
@Input() outputList: number[];
@Input() searchData: any[];
@Input() dataLength: number;
@Input() selectedData: any[];
@Input() processWip: boolean;
@Input() processDone: boolean;
@Input() processId: string;
}
let scrollTopServiceStub: Partial<ScrollTopService> = {
setScrollTop() {}
};
let component: ResultComponent;
let fixture: ComponentFixture<ResultComponent>;
let store: MockStore;
const initialState = {
search: { ...fromSearch.initialState },
metamodel: { ...fromMetamodel }
};
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
ResultComponent,
DownloadSectionStubComponent,
SummarySectionStubComponent,
UrlDisplaySectionStubComponent,
DatatableSectionStubComponent,
RouterLinkDirectiveStub
],
providers: [
provideMockStore({ initialState }),
{ provide: ScrollTopService, useValue: scrollTopServiceStub }
]
});
fixture = TestBed.createComponent(ResultComponent);
component = fixture.componentInstance;
store = TestBed.inject(MockStore);
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('should execute ngOnInit lifecycle', () => {
const action = new searchActions.ChangeStepAction('result');
const spy = spyOn(store, 'dispatch');
fixture.detectChanges();
expect(spy).toHaveBeenCalledWith(action);
});
});
// Promise.resolve(null).then(() => this.store.dispatch(new searchActions.ChangeStepAction('result')));
// Promise.resolve(null).then(() => this.store.dispatch(new searchActions.ResultChecked()));
// Promise.resolve(null).then(() => this.store.dispatch(new searchActions.InitSearchByUrl()));
// this.store.dispatch(new datasetActions.LoadDatasetSearchMetaAction());
// this.scrollTopService.setScrollTop();
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { provideMockStore, MockStore } from '@ngrx/store/testing';
import { Component, Input } from '@angular/core';
import { SearchComponent } from './search.component';
import * as fromSearch from '../store/search.reducer';
import { SearchQueryParams } from '../store/model';
describe('[Search] Container: SearchComponent', () => {
@Component({ selector: 'app-progress-bar', template: '' })
class ProgressBarStubComponent {
@Input() currentStep: string;
@Input() datasetName: string;
@Input() criteriaStepChecked: boolean;
@Input() outputStepChecked: boolean;
@Input() resultStepChecked: boolean;
@Input() queryParams: SearchQueryParams;
@Input() outputListEmpty: boolean;
}
@Component({ selector: 'router-outlet', template: '' })
class RouterOutletStubComponent { }
let component: SearchComponent;
let fixture: ComponentFixture<SearchComponent>;
let store: MockStore;
const initialState = { documentation: { ...fromSearch.initialState } };;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
SearchComponent,
ProgressBarStubComponent,
RouterOutletStubComponent
],
providers: [provideMockStore({ initialState })]
});
fixture = TestBed.createComponent(SearchComponent);
component = fixture.componentInstance;
store = TestBed.inject(MockStore);
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
});
import { Input, Directive } from '@angular/core';
@Directive({
selector: '[routerLink]'
})
export class RouterLinkDirectiveStub {
@Input('routerLink') linkParams: any;
@Input('queryParams') queryParams: any;
navigatedTo: any = null;
}
\ No newline at end of file
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