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

Tests on detail store => DONE

parent 00deecb7
No related branches found
No related tags found
2 merge requests!147Develop,!137Resolve "[Module Multiple] : ajouter le nouveau module"
// import * as detailActions from './detail.action';
// import { ATTRIBUTE_LIST } from 'src/settings/test-data';
// import { Attribute } from 'src/app/metamodel/model';
//
// describe('[Detail] Action', () => {
// it('should InitDetailAction', () => {
// const action = new detailActions.InitDetailAction();
// expect(action.type).toEqual(detailActions.INIT_DETAIL);
// });
//
// it('should SetSearchIsPristineAction', () => {
// const action = new detailActions.SetSearchIsPristineAction(true);
// expect(action.type).toEqual(detailActions.SET_SEARCH_IS_PRISTINE);
// expect(action.payload).toBeTruthy();
// });
//
// it('should SetDatsetNameAction', () => {
// const action = new detailActions.SetDatasetNameAction('toto');
// expect(action.type).toEqual(detailActions.SET_DATASET_NAME);
// expect(action.payload).toEqual('toto');
// });
//
// it('should LoadAttributeListAction', () => {
// const action = new detailActions.LoadAttributeListAction();
// expect(action.type).toEqual(detailActions.LOAD_ATTRIBUTE_LIST);
// });
//
// it('should LoadAttributeListSuccessAction', () => {
// const attributeList: Attribute[] = ATTRIBUTE_LIST;
// const action = new detailActions.LoadAttributeListSuccessAction(attributeList);
// expect(action.type).toEqual(detailActions.LOAD_ATTRIBUTE_LIST_SUCCESS);
// expect(action.payload).toEqual(attributeList);
// });
//
// it('should LoadAttributeListFailAction', () => {
// const action = new detailActions.LoadAttributeListFailAction();
// expect(action.type).toEqual(detailActions.LOAD_ATTRIBUTE_LIST_FAIL);
// });
//
// it('should CopyAttributeListAction', () => {
// const action = new detailActions.CopyAttributeListAction();
// expect(action.type).toEqual(detailActions.COPY_ATTRIBUTE_LIST);
// });
//
// it('should RetrieveObjectAction', () => {
// const payload: { datasetName: string, idAttribute: number, id: string } = {
// datasetName: 'toto',
// idAttribute: 1,
// id: 'one'
// };
// const action = new detailActions.RetrieveObjectAction(payload);
// expect(action.type).toEqual(detailActions.RETRIEVE_OBJECT);
// expect(action.payload).toEqual(payload);
// });
//
// it('should RetrieveObjectSuccessAction', () => {
// const action = new detailActions.RetrieveObjectSuccessAction('toto');
// expect(action.type).toEqual(detailActions.RETRIEVE_OBJECT_SUCCESS);
// expect(action.payload).toEqual('toto');
// });
//
// it('should RetrieveObjectFailAction', () => {
// const action = new detailActions.RetrieveObjectFailAction();
// expect(action.type).toEqual(detailActions.RETRIEVE_OBJECT_FAIL);
// });
//
// it('should RetrieveSpectraAction', () => {
// const action = new detailActions.RetrieveSpectraAction('toto');
// expect(action.type).toEqual(detailActions.RETRIEVE_SPECTRA);
// expect(action.payload).toEqual('toto');
// });
//
// it('should RetrieveSpectraSuccessAction', () => {
// const action = new detailActions.RetrieveSpectraSuccessAction('toto');
// expect(action.type).toEqual(detailActions.RETRIEVE_SPECTRA_SUCCESS);
// expect(action.payload).toEqual('toto');
// });
//
// it('should RetrieveSpectraFailAction', () => {
// const action = new detailActions.RetrieveSpectraFailAction();
// expect(action.type).toEqual(detailActions.RETRIEVE_SPECTRA_FAIL);
// });
//
// it('should DestroyDetailAction', () => {
// const action = new detailActions.DestroyDetailAction();
// expect(action.type).toEqual(detailActions.DESTROY_DETAIL);
// });
// });
import * as detailActions from './detail.action';
describe('[Detail] Action', () => {
it('should InitDetailAction', () => {
const action = new detailActions.InitDetailAction();
expect(action.type).toEqual(detailActions.INIT_DETAIL);
});
it('should SetSearchIsPristineAction', () => {
const action = new detailActions.SetSearchIsPristineAction(true);
expect(action.type).toEqual(detailActions.SET_SEARCH_IS_PRISTINE);
expect(action.payload).toBeTruthy();
});
it('should SetDatsetNameAction', () => {
const action = new detailActions.SetDatasetNameAction('toto');
expect(action.type).toEqual(detailActions.SET_DATASET_NAME);
expect(action.payload).toEqual('toto');
});
it('should RetrieveObjectAction', () => {
const payload: { datasetName: string, idAttribute: number, id: string } = {
datasetName: 'toto',
idAttribute: 1,
id: 'one'
};
const action = new detailActions.RetrieveObjectAction(payload);
expect(action.type).toEqual(detailActions.RETRIEVE_OBJECT);
expect(action.payload).toEqual(payload);
});
it('should RetrieveObjectSuccessAction', () => {
const action = new detailActions.RetrieveObjectSuccessAction('toto');
expect(action.type).toEqual(detailActions.RETRIEVE_OBJECT_SUCCESS);
expect(action.payload).toEqual('toto');
});
it('should RetrieveObjectFailAction', () => {
const action = new detailActions.RetrieveObjectFailAction();
expect(action.type).toEqual(detailActions.RETRIEVE_OBJECT_FAIL);
});
it('should RetrieveSpectraAction', () => {
const action = new detailActions.RetrieveSpectraAction('toto');
expect(action.type).toEqual(detailActions.RETRIEVE_SPECTRA);
expect(action.payload).toEqual('toto');
});
it('should RetrieveSpectraSuccessAction', () => {
const action = new detailActions.RetrieveSpectraSuccessAction('toto');
expect(action.type).toEqual(detailActions.RETRIEVE_SPECTRA_SUCCESS);
expect(action.payload).toEqual('toto');
});
it('should RetrieveSpectraFailAction', () => {
const action = new detailActions.RetrieveSpectraFailAction();
expect(action.type).toEqual(detailActions.RETRIEVE_SPECTRA_FAIL);
});
it('should DestroyDetailAction', () => {
const action = new detailActions.DestroyDetailAction();
expect(action.type).toEqual(detailActions.DESTROY_DETAIL);
});
});
import { Action } from '@ngrx/store';
import { Attribute } from '../../metamodel/model'
export const INIT_DETAIL = '[Detail] Init Detail';
export const SET_SEARCH_IS_PRISTINE = '[Detail] Set Search Is Pristine';
export const SET_DATASET_NAME = '[Detail] Set Dataset Name';
// export const LOAD_ATTRIBUTE_LIST = '[Detail] Load Attribute List';
// export const LOAD_ATTRIBUTE_LIST_SUCCESS = '[Detail] Load Attribute List Success';
// export const LOAD_ATTRIBUTE_LIST_FAIL = '[Detail] Load Attribute List Fail';
// export const COPY_ATTRIBUTE_LIST = '[Detail] Copy Attribute List';
export const RETRIEVE_OBJECT = '[Detail] Retrieve Object';
export const RETRIEVE_OBJECT_SUCCESS = '[Detail] Retrieve Object Success';
export const RETRIEVE_OBJECT_FAIL = '[Detail] Retrieve Object Fail';
......@@ -34,30 +29,6 @@ export class SetSearchIsPristineAction implements Action {
constructor(public payload: boolean) { }
}
// export class LoadAttributeListAction implements Action {
// readonly type = LOAD_ATTRIBUTE_LIST;
//
// constructor(public payload: {} = null) { }
// }
//
// export class LoadAttributeListSuccessAction implements Action {
// readonly type = LOAD_ATTRIBUTE_LIST_SUCCESS;
//
// constructor(public payload: Attribute[]) { }
// }
//
// export class LoadAttributeListFailAction implements Action {
// readonly type = LOAD_ATTRIBUTE_LIST_FAIL;
//
// constructor(public payload: {} = null) { }
// }
//
// export class CopyAttributeListAction implements Action {
// readonly type = COPY_ATTRIBUTE_LIST;
//
// constructor(public payload: {} = null) { }
// }
export class RetrieveObjectAction implements Action {
readonly type = RETRIEVE_OBJECT;
......@@ -104,10 +75,6 @@ export type Actions
= InitDetailAction
| SetSearchIsPristineAction
| SetDatasetNameAction
// | LoadAttributeListAction
// | LoadAttributeListSuccessAction
// | LoadAttributeListFailAction
// | CopyAttributeListAction
| RetrieveObjectAction
| RetrieveObjectSuccessAction
| RetrieveObjectFailAction
......
......@@ -11,16 +11,10 @@ import * as fromDetail from './detail.reducer';
import * as detailActions from './detail.action';
import { DetailService } from './detail.service';
import * as fromMetamodel from '../../metamodel/reducers';
import * as attActions from '../../metamodel/action/att.action';
import * as attributeActions from '../../metamodel/action/att.action';
import * as outputActions from '../../metamodel/action/output.action';
import { AttributeService } from '../../metamodel/services/attribute.service';
import { AttService } from '../../metamodel/services/att.service';
import { Attribute } from '../../metamodel/model';
import * as fromSearch from '../../search/store/search.reducer';
import * as utils from '../../shared/utils';
import * as attributeActions from "../../metamodel/action/att.action";
import {Pagination, PaginationOrder} from "../../shared/datatable/model";
import * as searchMultipleActions from "../../search-multiple/store/search-multiple.action";
interface State {
router: fromRouter.RouterReducerState<utils.RouterStateUrl>;
......@@ -34,8 +28,6 @@ export class DetailEffects {
constructor(
private actions$: Actions,
private detailService: DetailService,
private attributeService: AttributeService,
private attService: AttService,
private toastr: ToastrService,
private store$: Store<State>
) { }
......@@ -49,12 +41,10 @@ export class DetailEffects {
let actions: Action[] = [new detailActions.SetDatasetNameAction(datasetName)];
if (!state.search || state.search.pristine) {
// actions.push(new detailActions.LoadAttributeListAction());
actions.push(new attActions.LoadAttributeListAction(datasetName));
actions.push(new attributeActions.LoadAttributeListAction(datasetName));
actions.push(new outputActions.LoadOutputSearchMetaAction(datasetName));
actions.push(new detailActions.SetSearchIsPristineAction(true));
} else {
// actions.push(new detailActions.CopyAttributeListAction());
actions.push(new detailActions.RetrieveObjectAction());
actions.push(new detailActions.SetSearchIsPristineAction(false));
}
......@@ -63,29 +53,12 @@ export class DetailEffects {
})
);
// @Effect()
// loadAttributeAction$ = this.actions$.pipe(
// ofType(detailActions.LOAD_ATTRIBUTE_LIST),
// withLatestFrom(this.store$),
// switchMap(([action, state]) => {
// const datasetName = state.router.state.params.dname;
// return this.attributeService.retrieveAttributeList(datasetName).pipe(
// map((attributeList: Attribute[]) => new detailActions.LoadAttributeListSuccessAction(attributeList)),
// catchError(() => of(new detailActions.LoadAttributeListFailAction()))
// );
// })
// );
@Effect()
loadAttributeSuccessAction$ = this.actions$.pipe(
ofType(attActions.LOAD_ATTRIBUTE_LIST_SUCCESS),
ofType(attributeActions.LOAD_ATTRIBUTE_LIST_SUCCESS),
withLatestFrom(this.store$),
switchMap(([action, state]) => {
if (state.router.state.url.includes('/detail/')) {
// const loadAttributeListSuccessAction = action as attributeActions.LoadAttributeListSuccessAction;
// const dname: string = loadAttributeListSuccessAction.payload.datasetName;
// const sortedCol: number = loadAttributeListSuccessAction.payload.attributeList.find(a => a.search_flag === 'ID').id;
// const pagination: Pagination = { dname: dname, nbItems: 10, page: 1, sortedCol: sortedCol, order: PaginationOrder.a };
return of(new detailActions.RetrieveObjectAction());
} else {
return of({ type: '[No Action] ' + attributeActions.LOAD_ATTRIBUTE_LIST_SUCCESS });
......@@ -93,22 +66,6 @@ export class DetailEffects {
})
);
// @Effect({ dispatch: false })
// loadAttributeFailAction$ = this.actions$.pipe(
// ofType(detailActions.LOAD_ATTRIBUTE_LIST_FAIL),
// tap(_ => this.toastr.error('Loading Failed!', 'The attribute list loading failed'))
// );
// @Effect()
// copyAttributeAction$ = this.actions$.pipe(
// ofType(detailActions.COPY_ATTRIBUTE_LIST),
// withLatestFrom(this.store$),
// switchMap(([action, state]) => {
// const attributeList = state.metamodel.attribute.datasetAttributeList;
// return of(new detailActions.LoadAttributeListSuccessAction(attributeList));
// })
// );
@Effect()
retrieveObjectAction$ = this.actions$.pipe(
ofType(detailActions.RETRIEVE_OBJECT),
......@@ -116,7 +73,6 @@ export class DetailEffects {
switchMap(([action, state]) => {
const datasetName = state.router.state.params.dname;
const objectSelected = state.router.state.params.objectSelected;
// const attributes = state.detail.attributeList;
const attributes = state.metamodel.att.entities[datasetName].attributeList;
const attributeCriterionId = attributes.find(a => a.search_flag === 'ID');
const attributesOutputList = attributes.filter(a => a.detail).map(a => a.id);
......
This diff is collapsed.
import * as actions from './detail.action';
import { Attribute } from '../../metamodel/model';
export interface State {
searchIsPristine: boolean
datasetName: string;
// attributeList: Attribute[];
objectIsLoading: boolean;
objectIsLoaded: boolean;
object: any;
......@@ -17,7 +14,6 @@ export interface State {
export const initialState: State = {
searchIsPristine: null,
datasetName: null,
// attributeList: null,
objectIsLoading: false,
objectIsLoaded: false,
object: null,
......@@ -35,40 +31,25 @@ export function reducer(state: State = initialState, action: actions.Actions): S
};
case actions.SET_SEARCH_IS_PRISTINE:
const searchIsPristine: boolean = action.payload;
return {
...state,
searchIsPristine
searchIsPristine: action.payload
};
case actions.SET_DATASET_NAME:
const datasetName: string = action.payload;
return {
...state,
datasetName
datasetName: action.payload
};
// case actions.LOAD_ATTRIBUTE_LIST_SUCCESS:
// const attributeList: Attribute[] = action.payload;
//
// return {
// ...state,
// attributeList
// };
case actions.RETRIEVE_OBJECT_SUCCESS:
const object = action.payload;
return {
...state,
objectIsLoading: false,
objectIsLoaded: true,
object
object: action.payload
};
// case actions.LOAD_ATTRIBUTE_LIST_FAIL:
case actions.RETRIEVE_OBJECT_FAIL:
return {
...state,
......@@ -106,7 +87,6 @@ export function reducer(state: State = initialState, action: actions.Actions): S
export const getSearchIsPristine = (state: State) => state.searchIsPristine;
export const getDatasetName = (state: State) => state.datasetName;
// export const getAttributeList = (state: State) => state.attributeList;
export const getObjectIsLoading = (state: State) => state.objectIsLoading;
export const getObjectIsLoaded = (state: State) => state.objectIsLoaded;
export const getObject = (state: State) => state.object;
......
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