Commit 073580c4 authored by Tifenn Guillas's avatar Tifenn Guillas
Browse files

Update tests => DONE

parent a36ff123
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { provideMockStore, MockStore } from '@ngrx/store/testing';
import { Dictionary } from '@ngrx/entity';
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';
import { AttributesByDataset } from '../../metamodel/model';
import { ScrollTopService } from '../../shared/service/sroll-top.service';
import { environment } from "../../../environments/environment";
import { environment } from '../../../environments/environment';
import { ATTRIBUTE_LIST } from '../../../settings/test-data';
describe('[Documentation] Component: DocumentationComponent', () => {
let scrollTopServiceStub: Partial<ScrollTopService> = {
......@@ -36,23 +38,22 @@ describe('[Documentation] Component: DocumentationComponent', () => {
expect(component).toBeTruthy();
});
it('should execute ngOnInit lifecycle', () => {
const action = new documentationActions.RetrieveAttributeListsAction();
const spy = spyOn(store, 'dispatch');
component.ngOnInit()
expect(spy).toHaveBeenCalledWith(action);
});
it('#getHost() should return protocol and host', () => {
expect(component.getHost()).toEqual(environment.apiUrl);
});
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('#getAttributeList() should return attributes for selected dataset', () => {
const attributeLists: Dictionary<AttributesByDataset> = {
'toto': { datasetName: 'toto', isLoading: false, isLoaded: true, attributeList: ATTRIBUTE_LIST }
};
expect(component.getAttributeList('toto', attributeLists)).toEqual(ATTRIBUTE_LIST);
});
it('should execute ngOnInit lifecycle', () => {
const action = new documentationActions.RetrieveDatasetList();
const spy = spyOn(store, 'dispatch');
fixture.detectChanges();
expect(spy).toHaveBeenCalledWith(action);
});
});
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 AttributeListsIsLoadingAction action', () => {
const action = new documentationActions.RetrieveAttributeListsAction();
expect(action.type).toEqual(documentationActions.RETRIEVE_ATTRIBUTE_LISTS);
});
it('should create RetrieveDatasetListWip action', () => {
const action = new documentationActions.RetrieveDatasetListWip();
expect(action.type).toEqual(documentationActions.RETRIEVE_DATASET_LIST_WIP);
it('should create AttributeListsIsLoadingAction action', () => {
const action = new documentationActions.AttributeListsIsLoadingAction(true);
expect(action.type).toEqual(documentationActions.ATTRIBUTE_LISTS_IS_LOADING);
expect(action.payload).toBeTruthy();
});
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);
it('should create AttributeListsIsLoadedAction action', () => {
const action = new documentationActions.AttributeListsIsLoadedAction(true);
expect(action.type).toEqual(documentationActions.ATTRIBUTE_LISTS_IS_LOADED);
expect(action.payload).toBeTruthy();
});
});
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', () => {
......@@ -12,132 +10,37 @@ describe('[Documentation] Reducer', () => {
expect(state).toBe(initialState);
});
it('should set datasetListIsLoading to true', () => {
it('should set attributeListsIsLoading to true', () => {
const { initialState } = fromDocumentation;
const action = new documentationActions.RetrieveDatasetListWip();
const action = new documentationActions.AttributeListsIsLoadingAction(true);
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.attributeListsIsLoading).toBeTruthy();
expect(state.attributeListsIsLoaded).toBeFalsy();
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;
it('should set attributeListsIsLoaded to true', () => {
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 action = new documentationActions.AttributeListsIsLoadedAction(true);
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.attributeListsIsLoading).toBeFalsy();
expect(state.attributeListsIsLoaded).toBeTruthy();
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', () => {
it('should get attributeListsIsLoading', () => {
const action = {} as documentationActions.Actions;
const state = fromDocumentation.reducer(undefined, action);
expect(fromDocumentation.getAttributeListIsLoaded(state)).toBeFalsy();
expect(fromDocumentation.getAttributeListsIsLoading(state)).toBeFalsy();
});
it('should get attributeList', () => {
it('should get attributeListsIsLoaded', () => {
const action = {} as documentationActions.Actions;
const state = fromDocumentation.reducer(undefined, action);
expect(fromDocumentation.getAttributeList(state)).toBeNull();
expect(fromDocumentation.getAttributeListsIsLoaded(state)).toBeFalsy();
});
});
......@@ -2,38 +2,13 @@ import * as documentationSelector from './documentation.selector';
import * as fromDocumentation from './documentation.reducer';
describe('[Documentation] Selector', () => {
it('should get datasetIsLoading', () => {
it('should get attributeListsIsLoading', () => {
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', () => {
expect(documentationSelector.getAttributeListsIsLoading(state)).toBeFalsy();
})
it('should get attributeListsIsLoaded', () => {
const state = { documentation: { ...fromDocumentation.initialState }};
expect(documentationSelector.getAttributeList(state)).toBeNull();
expect(documentationSelector.getAttributeListsIsLoaded(state)).toBeFalsy();
});
});
import * as attributeActions from './attribute.action';
import { Attribute } from '../model';
import { Attribute, AttributesByDataset } from '../model';
import { ATTRIBUTE_LIST } from '../../../settings/test-data';
describe('[Metamodel] Attribute action', () => {
......@@ -24,4 +24,25 @@ describe('[Metamodel] Attribute action', () => {
expect(action.type).toEqual(attributeActions.LOAD_ATTRIBUTE_LIST_FAIL);
expect(action.payload).toEqual('toto');
});
it('should create LoadMultipleAttributeListsAction', () => {
const action = new attributeActions.LoadMultipleAttributeListsAction(['toto']);
expect(action.type).toEqual(attributeActions.LOAD_MULTIPLE_ATTRIBUTE_LISTS);
expect(action.payload).toEqual(['toto']);
});
it('should create LoadAttributeListSuccessAction', () => {
const attributeLists: AttributesByDataset[] = [
{ datasetName: 'toto', isLoading: true, isLoaded: false, attributeList: ATTRIBUTE_LIST },
{ datasetName: 'tutu', isLoading: true, isLoaded: false, attributeList: ATTRIBUTE_LIST }
];
const action = new attributeActions.LoadMultipleAttributeListsSuccessAction(attributeLists);
expect(action.type).toEqual(attributeActions.LOAD_MULTIPLE_ATTRIBUTE_LISTS_SUCCESS);
expect(action.payload).toEqual(attributeLists);
});
it('should create LoadMultipleAttributeListsFailAction', () => {
const action = new attributeActions.LoadMultipleAttributeListsFailAction();
expect(action.type).toEqual(attributeActions.LOAD_MULTIPLE_ATTRIBUTE_LISTS_FAIL);
});
});
......@@ -2,7 +2,7 @@ export * from './family.model';
export * from './category.model';
export * from './dataset.model';
export * from './project.model';
export * from './attributesByDataset.model';
export * from './attributes-by-dataset.model';
export * from './attribute.model';
export * from './option.model';
export * from './renderer-config.model';
\ No newline at end of file
import * as fromAttribute from './attribute.reducer';
import * as attributeActions from '../action/attribute.action';
import { Attribute } from '../model';
import { Attribute, AttributesByDataset } from '../model';
import { ATTRIBUTE_LIST } from '../../../settings/test-data';
describe('[Metamodel] Attribute reducer', () => {
......@@ -48,4 +48,16 @@ describe('[Metamodel] Attribute reducer', () => {
expect(state.entities).toEqual({ 'toto': { datasetName: 'toto', isLoading: false, isLoaded: false, attributeList: [] }});
expect(state).not.toEqual(initialState);
});
it('should update or insert the given entities', () => {
const toto: AttributesByDataset = { datasetName: 'toto', isLoading: false, isLoaded: false, attributeList: ATTRIBUTE_LIST };
const tutu: AttributesByDataset = { datasetName: 'tutu', isLoading: false, isLoaded: false, attributeList: ATTRIBUTE_LIST };
const { initialState } = fromAttribute;
const action = new attributeActions.LoadMultipleAttributeListsSuccessAction([toto, tutu]);
const state = fromAttribute.reducer(initialState, action);
expect(state.ids).toEqual(['toto', 'tutu']);
expect(state.entities).toEqual({ 'toto': toto, 'tutu': tutu});
expect(state).not.toEqual(initialState);
});
});
......@@ -4,19 +4,19 @@ import { ATTRIBUTE_LIST } from '../../../settings/test-data';
describe('[Metamodel] Attribute selector', () => {
it('should get all attributeList by dataset', () => {
const state = { metamodel: { att: { ...fromAttribute.initialState }}};
const state = { metamodel: { attribute: { ...fromAttribute.initialState }}};
expect(attributeSelector.getAllAttributeList(state)).toEqual({});
});
it('should get datasets with attributeList', () => {
const state = { metamodel: { att: { ...fromAttribute.initialState }}};
const state = { metamodel: { attribute: { ...fromAttribute.initialState }}};
expect(attributeSelector.getDatasetsWithAttributeList(state)).toEqual([]);
});
it('should get attributeListIsLoading for the given dataset', () => {
let state = { metamodel: { att: { ...fromAttribute.initialState }}};
let state = { metamodel: { attribute: { ...fromAttribute.initialState }}};
expect(attributeSelector.getAttributeListIsLoading(state, { dname: 'toto' })).toBeFalsy();
state = { metamodel: { att: {
state = { metamodel: { attribute: {
...fromAttribute.initialState,
ids: ['toto'],
entities: { 'toto': { datasetName: 'toto', isLoading: true, isLoaded: false, attributeList: [] }}
......@@ -25,9 +25,9 @@ describe('[Metamodel] Attribute selector', () => {
});
it('should get attributeListIsLoaded for the given dataset', () => {
let state = { metamodel: { att: { ...fromAttribute.initialState }}};
let state = { metamodel: { attribute: { ...fromAttribute.initialState }}};
expect(attributeSelector.getAttributeListIsLoaded(state, { dname: 'toto' })).toBeFalsy();
state = { metamodel: { att: {
state = { metamodel: { attribute: {
...fromAttribute.initialState,
ids: ['toto'],
entities: { 'toto': { datasetName: 'toto', isLoading: false, isLoaded: true, attributeList: [] }}
......@@ -36,9 +36,9 @@ describe('[Metamodel] Attribute selector', () => {
});
it('should get attributeList for the given dataset', () => {
let state = { metamodel: { att: { ...fromAttribute.initialState }}};
let state = { metamodel: { attribute: { ...fromAttribute.initialState }}};
expect(attributeSelector.getAttributeList(state, { dname: 'toto' })).toEqual([]);
state = { metamodel: { att: {
state = { metamodel: { attribute: {
...fromAttribute.initialState,
ids: ['toto'],
entities: { 'toto': { datasetName: 'toto', isLoading: false, isLoaded: false, attributeList: ATTRIBUTE_LIST }}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment