mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
added tests
This commit is contained in:
@@ -10,9 +10,8 @@ module.exports = {
|
|||||||
// The REST API server settings.
|
// The REST API server settings.
|
||||||
rest: {
|
rest: {
|
||||||
ssl: true,
|
ssl: true,
|
||||||
host: 'dspace7.4science.cloud',
|
host: 'dspace7-entities.atmire.com',
|
||||||
port: 443,
|
port: 443,
|
||||||
// NOTE: Space is capitalized because 'namespace' is a reserved string in TypeScript
|
|
||||||
nameSpace: '/server/api'
|
nameSpace: '/server/api'
|
||||||
},
|
},
|
||||||
// Caching settings
|
// Caching settings
|
||||||
|
@@ -14,7 +14,6 @@ export class DynamicDisabledModel extends DsDynamicInputModel {
|
|||||||
|
|
||||||
constructor(config: DsDynamicDisabledModelConfig, layout?: DynamicFormControlLayout) {
|
constructor(config: DsDynamicDisabledModelConfig, layout?: DynamicFormControlLayout) {
|
||||||
super(config, layout);
|
super(config, layout);
|
||||||
|
|
||||||
this.readOnly = true;
|
this.readOnly = true;
|
||||||
this.disabled = true;
|
this.disabled = true;
|
||||||
this.valueUpdates.next(config.value);
|
this.valueUpdates.next(config.value);
|
||||||
|
@@ -0,0 +1,66 @@
|
|||||||
|
import { FormFieldModel } from '../models/form-field.model';
|
||||||
|
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
||||||
|
import { ParserOptions } from './parser-options';
|
||||||
|
import { DisabledFieldParser } from './disabled-field-parser';
|
||||||
|
import { DynamicDisabledModel } from '../ds-dynamic-form-ui/models/disabled/dynamic-disabled.model';
|
||||||
|
|
||||||
|
describe('DisabledFieldParser test suite', () => {
|
||||||
|
let field: FormFieldModel;
|
||||||
|
let initFormValues: any = {};
|
||||||
|
|
||||||
|
const submissionId = '1234';
|
||||||
|
const parserOptions: ParserOptions = {
|
||||||
|
readOnly: false,
|
||||||
|
submissionScope: null,
|
||||||
|
authorityUuid: null
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
field = {
|
||||||
|
input: {
|
||||||
|
type: ''
|
||||||
|
},
|
||||||
|
label: 'Description',
|
||||||
|
mandatory: 'false',
|
||||||
|
repeatable: false,
|
||||||
|
hints: 'Enter a description.',
|
||||||
|
selectableMetadata: [
|
||||||
|
{
|
||||||
|
metadata: 'description'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
languageCodes: []
|
||||||
|
} as FormFieldModel;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should init parser properly', () => {
|
||||||
|
const parser = new DisabledFieldParser(submissionId, field, initFormValues, parserOptions);
|
||||||
|
|
||||||
|
expect(parser instanceof DisabledFieldParser).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a DynamicDisabledModel object when repeatable option is false', () => {
|
||||||
|
const parser = new DisabledFieldParser(submissionId, field, initFormValues, parserOptions);
|
||||||
|
|
||||||
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
|
expect(fieldModel instanceof DynamicDisabledModel).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set init value properly', () => {
|
||||||
|
initFormValues = {
|
||||||
|
description: [
|
||||||
|
new FormFieldMetadataValueObject('test description'),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
const expectedValue ='test description';
|
||||||
|
|
||||||
|
const parser = new DisabledFieldParser(submissionId, field, initFormValues, parserOptions);
|
||||||
|
|
||||||
|
const fieldModel = parser.parse();
|
||||||
|
console.log(fieldModel);
|
||||||
|
expect(fieldModel.value).toEqual(expectedValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
@@ -5,7 +5,9 @@ import { DsDynamicDisabledModelConfig, DynamicDisabledModel } from '../ds-dynami
|
|||||||
export class DisabledFieldParser extends FieldParser {
|
export class DisabledFieldParser extends FieldParser {
|
||||||
|
|
||||||
public modelFactory(fieldValue?: FormFieldMetadataValueObject | any, label?: boolean): any {
|
public modelFactory(fieldValue?: FormFieldMetadataValueObject | any, label?: boolean): any {
|
||||||
|
console.log(fieldValue);
|
||||||
const emptyModelConfig: DsDynamicDisabledModelConfig = this.initModel(null, label);
|
const emptyModelConfig: DsDynamicDisabledModelConfig = this.initModel(null, label);
|
||||||
|
this.setValues(emptyModelConfig, fieldValue);
|
||||||
return new DynamicDisabledModel(emptyModelConfig)
|
return new DynamicDisabledModel(emptyModelConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,112 @@
|
|||||||
|
import {
|
||||||
|
SelectableListAction,
|
||||||
|
SelectableListDeselectAction, SelectableListDeselectAllAction,
|
||||||
|
SelectableListDeselectSingleAction,
|
||||||
|
SelectableListSelectAction,
|
||||||
|
SelectableListSelectSingleAction,
|
||||||
|
SelectableListSetSelectionAction
|
||||||
|
} from './selectable-list.actions';
|
||||||
|
import { selectableListReducer } from './selectable-list.reducer';
|
||||||
|
import { ListableObject } from '../../object-collection/shared/listable-object.model';
|
||||||
|
import { hasValue } from '../../empty.util';
|
||||||
|
|
||||||
|
// tslint:disable:max-classes-per-file
|
||||||
|
class SelectableObject extends ListableObject {
|
||||||
|
constructor(private value: string) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
equals(other: SelectableObject): boolean {
|
||||||
|
return hasValue(this.value) && hasValue(other.value) && this.value === other.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
getRenderTypes() {
|
||||||
|
return ['selectable'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class NullAction extends SelectableListAction {
|
||||||
|
type = null;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super(undefined, undefined);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// tslint:enable:max-classes-per-file
|
||||||
|
const listID1 = 'id1';
|
||||||
|
const listID2 = 'id2';
|
||||||
|
const value1 = 'Selected object';
|
||||||
|
const value2 = 'Another selected object';
|
||||||
|
const value3 = 'Selection';
|
||||||
|
const value4 = 'Selected object numero 4';
|
||||||
|
|
||||||
|
const selected1 = new SelectableObject(value1);
|
||||||
|
const selected2 = new SelectableObject(value2);
|
||||||
|
const selected3 = new SelectableObject(value3);
|
||||||
|
const selected4 = new SelectableObject(value4);
|
||||||
|
const testState = { [listID1]: { id: listID1, selection: [selected1, selected2] } };
|
||||||
|
|
||||||
|
describe('selectableListReducer', () => {
|
||||||
|
|
||||||
|
it('should return the current state when no valid actions have been made', () => {
|
||||||
|
const state = {};
|
||||||
|
state[listID1] = {};
|
||||||
|
state[listID1] = { id: listID1, selection: [selected1, selected2] };
|
||||||
|
const action = new NullAction();
|
||||||
|
const newState = selectableListReducer(state, action);
|
||||||
|
|
||||||
|
expect(newState).toEqual(state);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should start with an empty object', () => {
|
||||||
|
const state = {};
|
||||||
|
const action = new NullAction();
|
||||||
|
const newState = selectableListReducer(undefined, action);
|
||||||
|
|
||||||
|
expect(newState).toEqual(state);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add the payload to the existing list in response to the SELECT action for the given id', () => {
|
||||||
|
const action = new SelectableListSelectAction(listID1, [selected3, selected4]);
|
||||||
|
const newState = selectableListReducer(testState, action);
|
||||||
|
|
||||||
|
expect(newState[listID1].selection).toEqual([selected1, selected2, selected3, selected4]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add the payload to the existing list in response to the SELECT_SINGLE action for the given id', () => {
|
||||||
|
const action = new SelectableListSelectSingleAction(listID1, selected4);
|
||||||
|
const newState = selectableListReducer(testState, action);
|
||||||
|
|
||||||
|
expect(newState[listID1].selection).toEqual([selected1, selected2, selected4]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove the payload from the existing list in response to the DESELECT action for the given id', () => {
|
||||||
|
const action = new SelectableListDeselectAction(listID1, [selected1, selected2]);
|
||||||
|
const newState = selectableListReducer(testState, action);
|
||||||
|
|
||||||
|
expect(newState[listID1].selection).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove the payload from the existing list in response to the DESELECT_SINGLE action for the given id', () => {
|
||||||
|
const action = new SelectableListDeselectSingleAction(listID1, selected2);
|
||||||
|
const newState = selectableListReducer(testState, action);
|
||||||
|
|
||||||
|
expect(newState[listID1].selection).toEqual([selected1]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set the list to the payload in response to the SET_SELECTION action for the given id', () => {
|
||||||
|
const action = new SelectableListSetSelectionAction(listID2, [selected2, selected4]);
|
||||||
|
const newState = selectableListReducer(testState, action);
|
||||||
|
|
||||||
|
expect(newState[listID1].selection).toEqual(testState[listID1].selection);
|
||||||
|
expect(newState[listID2].selection).toEqual([selected2, selected4]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove the payload from the existing list in response to the DESELECT action for the given id', () => {
|
||||||
|
const action = new SelectableListDeselectAllAction(listID1);
|
||||||
|
const newState = selectableListReducer(testState, action);
|
||||||
|
|
||||||
|
expect(newState[listID1].selection).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
@@ -0,0 +1,98 @@
|
|||||||
|
import { Store } from '@ngrx/store';
|
||||||
|
import { async, TestBed } from '@angular/core/testing';
|
||||||
|
import { SelectableListService } from './selectable-list.service';
|
||||||
|
import { SelectableListsState } from './selectable-list.reducer';
|
||||||
|
import { ListableObject } from '../../object-collection/shared/listable-object.model';
|
||||||
|
import { hasValue } from '../../empty.util';
|
||||||
|
import { SelectableListDeselectAction, SelectableListDeselectSingleAction, SelectableListSelectAction, SelectableListSelectSingleAction } from './selectable-list.actions';
|
||||||
|
|
||||||
|
class SelectableObject extends ListableObject {
|
||||||
|
constructor(private value: string) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
equals(other: SelectableObject): boolean {
|
||||||
|
return hasValue(this.value) && hasValue(other.value) && this.value === other.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
getRenderTypes() {
|
||||||
|
return ['selectable'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('SelectableListService', () => {
|
||||||
|
const listID1 = 'id1';
|
||||||
|
const value1 = 'Selected object';
|
||||||
|
const value2 = 'Another selected object';
|
||||||
|
const value3 = 'Selection';
|
||||||
|
const value4 = 'Selected object numero 4';
|
||||||
|
|
||||||
|
const selected1 = new SelectableObject(value1);
|
||||||
|
const selected2 = new SelectableObject(value2);
|
||||||
|
const selected3 = new SelectableObject(value3);
|
||||||
|
const selected4 = new SelectableObject(value4);
|
||||||
|
|
||||||
|
let service: SelectableListService;
|
||||||
|
const store: Store<SelectableListsState> = jasmine.createSpyObj('store', {
|
||||||
|
/* tslint:disable:no-empty */
|
||||||
|
dispatch: {},
|
||||||
|
/* tslint:enable:no-empty */
|
||||||
|
});
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: Store, useValue: store
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
service = new SelectableListService(store);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the selectSingle method is triggered', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
service.selectSingle(listID1, selected3);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('SelectableListSelectSingleAction should be dispatched to the store', () => {
|
||||||
|
expect(store.dispatch).toHaveBeenCalledWith(new SelectableListSelectSingleAction(listID1, selected3));
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the select method is triggered', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
service.select(listID1, [selected1, selected4]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('SelectableListSelectAction should be dispatched to the store', () => {
|
||||||
|
expect(store.dispatch).toHaveBeenCalledWith(new SelectableListSelectAction(listID1, [selected1, selected4]));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the deselectSingle method is triggered', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
service.deselectSingle(listID1, selected4);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('SelectableListDeselectSingleAction should be dispatched to the store', () => {
|
||||||
|
expect(store.dispatch).toHaveBeenCalledWith(new SelectableListDeselectSingleAction(listID1, selected4));
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the deselect method is triggered', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
service.deselect(listID1, [selected2, selected4]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('SelectableListDeselectAction should be dispatched to the store', () => {
|
||||||
|
expect(store.dispatch).toHaveBeenCalledWith(new SelectableListDeselectAction(listID1, [selected2, selected4]));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Reference in New Issue
Block a user