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

Add tests

parent 641e1026
No related branches found
No related tags found
2 merge requests!113Develop,!99Resolve "Documentation construction url serveur"
This commit is part of merge request !99. Comments created here will be created in the context of that merge request.
// import { ProgressBarComponent } from './progress-bar.component';
export const dummiesComponents = [
// ProgressBarComponent,
];
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { provideMockStore, MockStore } from '@ngrx/store/testing';
import { DocumentationComponent } from './documentation.component';
import * as fromDocumentation from '../store/documentation.reducer';
import * as documentationActions from '../store/documentation.action';
import { DATASET, ATTRIBUTE_LIST } from 'src/settings/test-data';
import { Dataset, Attribute } from 'src/app/metamodel/model';
describe('[Documentation] Component: DocumentationComponent', () => {
let component: DocumentationComponent;
let fixture: ComponentFixture<DocumentationComponent>;
let store: MockStore;
const initialState = { documentation: { ...fromDocumentation.initialState }};;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ DocumentationComponent ],
providers: [ provideMockStore({ initialState }) ]
});
fixture = TestBed.createComponent(DocumentationComponent);
component = fixture.componentInstance;
store = TestBed.inject(MockStore);
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('#getDatasetAttributes() should return attributes for selected dataset', () => {
const dataset: Dataset = DATASET;
const attributeList: Attribute[] = ATTRIBUTE_LIST;
const expectedAttributeList = attributeList.filter(a => a.table_name === dataset.table_ref);
expect(component.getDatasetAttributes(dataset, attributeList)).toEqual(expectedAttributeList);
});
it('should execute ngOnInit lifecycle', () => {
const action = new documentationActions.RetrieveDatasetList();
const spy = spyOn(store, 'dispatch');
fixture.detectChanges();
expect(spy).toHaveBeenCalledWith(action);
});
});
...@@ -5,7 +5,6 @@ import { EffectsModule } from '@ngrx/effects'; ...@@ -5,7 +5,6 @@ import { EffectsModule } from '@ngrx/effects';
import { SharedModule } from '../shared/shared.module'; import { SharedModule } from '../shared/shared.module';
import { DocumentationRoutingModule, routedComponents } from './documentation.routing'; import { DocumentationRoutingModule, routedComponents } from './documentation.routing';
import { dummiesComponents } from './components';
import { reducer } from './store/documentation.reducer'; import { reducer } from './store/documentation.reducer';
import { DocumentationEffects } from './store/documentation.effects'; import { DocumentationEffects } from './store/documentation.effects';
import { DocumentationService } from './store/documentation.service'; import { DocumentationService } from './store/documentation.service';
...@@ -18,8 +17,7 @@ import { DocumentationService } from './store/documentation.service'; ...@@ -18,8 +17,7 @@ import { DocumentationService } from './store/documentation.service';
EffectsModule.forFeature([ DocumentationEffects ]) EffectsModule.forFeature([ DocumentationEffects ])
], ],
declarations: [ declarations: [
routedComponents, routedComponents
dummiesComponents
], ],
providers: [ providers: [
DocumentationService DocumentationService
......
import * as documentationActions from './documentation.action';
import { Dataset, Attribute } from 'src/app/metamodel/model';
import { DATASET_LIST, ATTRIBUTE_LIST } from 'src/settings/test-data';
describe('[Documentation] Action', () => {
it('should create RetrieveDatasetList action', () => {
const action = new documentationActions.RetrieveDatasetList();
expect(action.type).toEqual(documentationActions.RETRIEVE_DATASET_LIST);
});
it('should create RetrieveDatasetListWip action', () => {
const action = new documentationActions.RetrieveDatasetListWip();
expect(action.type).toEqual(documentationActions.RETRIEVE_DATASET_LIST_WIP);
});
it('should create RetrieveDatasetListSuccess action', () => {
const datasetList: Dataset[] = DATASET_LIST;
const action = new documentationActions.RetrieveDatasetListSuccess(datasetList);
expect(action.type).toEqual(documentationActions.RETRIEVE_DATASET_LIST_SUCCESS);
expect(action.payload).toEqual(datasetList);
});
it('should create RetrieveDatasetListFail action', () => {
const action = new documentationActions.RetrieveDatasetListFail();
expect(action.type).toEqual(documentationActions.RETRIEVE_DATASET_LIST_FAIL);
});
it('should create RetrieveAttributeList action', () => {
const action = new documentationActions.RetrieveAttributeList(['toto']);
expect(action.type).toEqual(documentationActions.RETRIEVE_ATTRIBUTE_LIST);
expect(action.payload).toEqual(['toto']);
});
it('should create RetrieveAttributeListSuccess action', () => {
const attributeList: Attribute[] = ATTRIBUTE_LIST;
const action = new documentationActions.RetrieveAttributeListSuccess(attributeList);
expect(action.type).toEqual(documentationActions.RETRIEVE_ATTRIBUTE_LIST_SUCCESS);
expect(action.payload).toEqual(attributeList);
});
it('should create RetrieveAttributeListFail action', () => {
const action = new documentationActions.RetrieveAttributeListFail();
expect(action.type).toEqual(documentationActions.RETRIEVE_ATTRIBUTE_LIST_FAIL);
});
});
...@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; ...@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { Effect, Actions, ofType } from '@ngrx/effects'; import { Effect, Actions, ofType } from '@ngrx/effects';
import { Store, Action } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { of, Observable, forkJoin } from 'rxjs'; import { of, Observable, forkJoin } from 'rxjs';
import { map, tap, switchMap, withLatestFrom, catchError } from 'rxjs/operators'; import { map, tap, switchMap, withLatestFrom, catchError } from 'rxjs/operators';
......
import * as fromDocumentation from './documentation.reducer';
import * as documentationActions from './documentation.action';
import { Dataset, Attribute } from 'src/app/metamodel/model';
import { DATASET_LIST, DATASET, ATTRIBUTE_LIST } from 'src/settings/test-data';
describe('[Documentation] Reducer', () => {
it('should return init state', () => {
const { initialState } = fromDocumentation;
const action = {} as documentationActions.Actions;
const state = fromDocumentation.reducer(undefined, action);
expect(state).toBe(initialState);
});
it('should set datasetListIsLoading to true', () => {
const { initialState } = fromDocumentation;
const action = new documentationActions.RetrieveDatasetListWip();
const state = fromDocumentation.reducer(initialState, action);
expect(state.datasetListIsLoading).toBeTruthy();
expect(state.datasetListIsLoaded).toBeFalsy();
expect(state.datasetList).toBeNull();
expect(state.attributeListIsLoading).toBeFalsy();
expect(state.attributeListIsLoaded).toBeFalsy();
expect(state.attributeList).toBeNull();
expect(state).not.toEqual(initialState);
});
it('should set datasetList, datasetListIsLoaded to true and datasetListIsLoading to false', () => {
const datasetList: Dataset[] = DATASET_LIST;
const initialState = { ...fromDocumentation.initialState, datasetListIsLoading: true };
const action = new documentationActions.RetrieveDatasetListSuccess(datasetList);
const state = fromDocumentation.reducer(initialState, action);
expect(state.datasetListIsLoading).toBeFalsy();
expect(state.datasetListIsLoaded).toBeTruthy();
expect(state.datasetList).toEqual(datasetList);
expect(state.attributeListIsLoading).toBeFalsy();
expect(state.attributeListIsLoaded).toBeFalsy();
expect(state.attributeList).toBeNull();
expect(state).not.toEqual(initialState);
});
it('should set datasetListIsLoading to false', () => {
const initialState = { ...fromDocumentation.initialState, datasetListIsLoading: true };
const action = new documentationActions.RetrieveDatasetListFail();
const state = fromDocumentation.reducer(initialState, action);
expect(state.datasetListIsLoading).toBeFalsy();
expect(state.datasetListIsLoaded).toBeFalsy();
expect(state.datasetList).toBeNull();
expect(state.attributeListIsLoading).toBeFalsy();
expect(state.attributeListIsLoaded).toBeFalsy();
expect(state.attributeList).toBeNull();
expect(state).not.toEqual(initialState);
});
it('should set attributeListIsLoading to true', () => {
const dataset: Dataset = DATASET;
const { initialState } = fromDocumentation;
const action = new documentationActions.RetrieveAttributeList([dataset.name]);
const state = fromDocumentation.reducer(initialState, action);
expect(state.datasetListIsLoading).toBeFalsy();
expect(state.datasetListIsLoaded).toBeFalsy();
expect(state.datasetList).toBeNull();
expect(state.attributeListIsLoading).toBeTruthy();
expect(state.attributeListIsLoaded).toBeFalsy();
expect(state.attributeList).toBeNull();
expect(state).not.toEqual(initialState);
});
it('should set datasetList, attributeListIsLoaded to true and attributeListIsLoading to false', () => {
const attributeList: Attribute[] = ATTRIBUTE_LIST;
const initialState = { ...fromDocumentation.initialState, attributeListIsLoading: true };
const action = new documentationActions.RetrieveAttributeListSuccess(attributeList);
const state = fromDocumentation.reducer(initialState, action);
expect(state.datasetListIsLoading).toBeFalsy();
expect(state.datasetListIsLoaded).toBeFalsy();
expect(state.datasetList).toBeNull();
expect(state.attributeListIsLoading).toBeFalsy();
expect(state.attributeListIsLoaded).toBeTruthy();
expect(state.attributeList).toEqual(attributeList);
expect(state).not.toEqual(initialState);
});
it('should set attributeListIsLoading to false', () => {
const initialState = { ...fromDocumentation.initialState, attributeListIsLoading: true };
const action = new documentationActions.RetrieveAttributeListFail();
const state = fromDocumentation.reducer(initialState, action);
expect(state.datasetListIsLoading).toBeFalsy();
expect(state.datasetListIsLoaded).toBeFalsy();
expect(state.datasetList).toBeNull();
expect(state.attributeListIsLoading).toBeFalsy();
expect(state.attributeListIsLoaded).toBeFalsy();
expect(state.attributeList).toBeNull();
expect(state).not.toEqual(initialState);
});
it('should get datasetListIsLoading', () => {
const action = {} as documentationActions.Actions;
const state = fromDocumentation.reducer(undefined, action);
expect(fromDocumentation.getDatasetListIsLoading(state)).toBeFalsy();
});
it('should get datasetListIsLoaded', () => {
const action = {} as documentationActions.Actions;
const state = fromDocumentation.reducer(undefined, action);
expect(fromDocumentation.getDatasetListIsLoaded(state)).toBeFalsy();
});
it('should get datasetList', () => {
const action = {} as documentationActions.Actions;
const state = fromDocumentation.reducer(undefined, action);
expect(fromDocumentation.getDatasetList(state)).toBeNull();
});
it('should get attributeListIsLoading', () => {
const action = {} as documentationActions.Actions;
const state = fromDocumentation.reducer(undefined, action);
expect(fromDocumentation.getAttributeListIsLoading(state)).toBeFalsy();
});
it('should get attributeListIsLoaded', () => {
const action = {} as documentationActions.Actions;
const state = fromDocumentation.reducer(undefined, action);
expect(fromDocumentation.getAttributeListIsLoaded(state)).toBeFalsy();
});
it('should get attributeList', () => {
const action = {} as documentationActions.Actions;
const state = fromDocumentation.reducer(undefined, action);
expect(fromDocumentation.getAttributeList(state)).toBeNull();
});
});
import * as documentationSelector from './documentation.selector';
import * as fromDocumentation from './documentation.reducer';
describe('[Documentation] Selector', () => {
it('should get datasetIsLoading', () => {
const state = { documentation: { ...fromDocumentation.initialState }};
expect(documentationSelector.getDatasetListIsLoading(state)).toBeFalsy();
});
it('should get datasetListIsLoaded', () => {
const state = { documentation: { ...fromDocumentation.initialState }};
expect(documentationSelector.getDatasetListIsLoaded(state)).toBeFalsy();
});
it('should get datasetListIsLoaded', () => {
const state = { documentation: { ...fromDocumentation.initialState }};
expect(documentationSelector.getDatasetListIsLoaded(state)).toBeFalsy();
});
it('should get datasetList', () => {
const state = { documentation: { ...fromDocumentation.initialState }};
expect(documentationSelector.getDatasetList(state)).toBeNull();
});
it('should get attributeListIsLoading', () => {
const state = { documentation: { ...fromDocumentation.initialState }};
expect(documentationSelector.getAttributeListIsLoading(state)).toBeFalsy();
});
it('should get attributeListIsLoaded', () => {
const state = { documentation: { ...fromDocumentation.initialState }};
expect(documentationSelector.getAttributeListIsLoaded(state)).toBeFalsy();
});
it('should get attributeList', () => {
const state = { documentation: { ...fromDocumentation.initialState }};
expect(documentationSelector.getAttributeList(state)).toBeNull();
});
});
...@@ -4,7 +4,7 @@ export const ATTRIBUTE_LIST: Attribute[] = [ ...@@ -4,7 +4,7 @@ export const ATTRIBUTE_LIST: Attribute[] = [
{ {
id: 1, id: 1,
name: 'name_one', name: 'name_one',
table_name: 'table_one', table_name: 'table_1',
label: 'label_one', label: 'label_one',
form_label: 'form_label_one', form_label: 'form_label_one',
description: 'description_one', description: 'description_one',
...@@ -43,7 +43,7 @@ export const ATTRIBUTE_LIST: Attribute[] = [ ...@@ -43,7 +43,7 @@ export const ATTRIBUTE_LIST: Attribute[] = [
{ {
id: 2, id: 2,
name: 'name_two', name: 'name_two',
table_name: 'table_two', table_name: 'table_2',
label: 'label_two', label: 'label_two',
form_label: 'form_label_two', form_label: 'form_label_two',
description: 'description_two', description: 'description_two',
......
...@@ -2,7 +2,7 @@ import { Dataset } from 'src/app/metamodel/model'; ...@@ -2,7 +2,7 @@ import { Dataset } from 'src/app/metamodel/model';
export const DATASET: Dataset = { export const DATASET: Dataset = {
name: 'cat_1', name: 'cat_1',
table_ref: '', table_ref: 'table_1',
label: 'Cat 1', label: 'Cat 1',
description: 'Description of cat 1', description: 'Description of cat 1',
display: 10, display: 10,
......
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