Browse Source

State for nested fields.

pull/297/head
Sebastian 8 years ago
parent
commit
e9aa4be8eb
  1. 113
      src/Squidex/app/shared/state/schemas.state.spec.ts
  2. 2
      src/Squidex/app/shared/state/schemas.state.ts

113
src/Squidex/app/shared/state/schemas.state.spec.ts

@ -45,11 +45,11 @@ describe('SchemasState', () => {
new SchemaDto('id2', 'name2', 'category2', {}, true , creation, creator, creation, creator, version)
];
const nested1 = new NestedFieldDto(3, '3', createProperties('Number'), 2);
const nested2 = new NestedFieldDto(4, '4', createProperties('String'), 2, true, true);
const field1 = new RootFieldDto(1, '1', createProperties('String'), 'invariant');
const field2 = new RootFieldDto(2, '2', createProperties('Array'), 'invariant', false, false, false, [
new NestedFieldDto(3, '3', createProperties('Number'), 2),
new NestedFieldDto(4, '4', createProperties('String'), 2)
]);
const field2 = new RootFieldDto(2, '2', createProperties('Array'), 'invariant', true, true, true, [nested1, nested2]);
const schema =
new SchemaDetailsDto('id2', 'name2', 'category2', {}, true,
@ -230,7 +230,6 @@ describe('SchemasState', () => {
expectToBeModified(schema_1);
});
it('should change category and update user info when category of selected schema changed', () => {
const category = 'my-new-category';
@ -318,6 +317,22 @@ describe('SchemasState', () => {
expectToBeModified(schema_1);
});
it('should add field and update user info when nested field added', () => {
const request = new AddFieldDto(field1.name, field1.partitioning, field1.properties);
const newField = new NestedFieldDto(3, '3', createProperties('String'), 2);
schemasService.setup(x => x.postField(app, schema.name, It.isAny(), 2, version))
.returns(() => Observable.of(new Versioned<NestedFieldDto>(newVersion, newField)));
schemasState.addField(schema, request, field2, modified).subscribe();
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1);
expect(schema_1.fields[1].nested).toEqual([nested1, nested2, newField]);
expectToBeModified(schema_1);
});
it('should remove field and update user info when field removed', () => {
schemasService.setup(x => x.deleteField(app, schema.name, field1.fieldId, undefined, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {})));
@ -330,6 +345,18 @@ describe('SchemasState', () => {
expectToBeModified(schema_1);
});
it('should remove field and update user info when nested field removed', () => {
schemasService.setup(x => x.deleteField(app, schema.name, nested1.fieldId, 2, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {})));
schemasState.deleteField(schema, nested1, modified).subscribe();
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1);
expect(schema_1.fields[1].nested).toEqual([nested2]);
expectToBeModified(schema_1);
});
it('should sort fields and update user info when fields sorted', () => {
schemasService.setup(x => x.putFieldOrdering(app, schema.name, [field2.fieldId, field1.fieldId], undefined, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {})));
@ -342,6 +369,18 @@ describe('SchemasState', () => {
expectToBeModified(schema_1);
});
it('should sort fields and update user info when nested fields sorted', () => {
schemasService.setup(x => x.putFieldOrdering(app, schema.name, [nested2.fieldId, nested1.fieldId], 2, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {})));
schemasState.sortFields(schema, [nested2, nested1], field2, modified).subscribe();
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1);
expect(schema_1.fields[1].nested).toEqual([nested2, nested1]);
expectToBeModified(schema_1);
});
it('should update field properties and update user info when field updated', () => {
const request = new UpdateFieldDto(createProperties('String'));
@ -356,11 +395,25 @@ describe('SchemasState', () => {
expectToBeModified(schema_1);
});
it('should update field properties and update user info when nested field updated', () => {
const request = new UpdateFieldDto(createProperties('String'));
schemasService.setup(x => x.putField(app, schema.name, nested1.fieldId, request, 2, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {})));
schemasState.updateField(schema, nested1, request, modified).subscribe();
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1);
expect(schema_1.fields[1].nested[0].properties).toBe(request.properties);
expectToBeModified(schema_1);
});
it('should mark field hidden and update user info when field hidden', () => {
schemasService.setup(x => x.hideField(app, schema.name, field1.fieldId, undefined, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {})));
schemasState.hideField(schema, field1, undefined, modified).subscribe();
schemasState.hideField(schema, field1, modified).subscribe();
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1);
@ -368,6 +421,18 @@ describe('SchemasState', () => {
expectToBeModified(schema_1);
});
it('should mark field hidden and update user info when nested field hidden', () => {
schemasService.setup(x => x.hideField(app, schema.name, nested1.fieldId, 2, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {})));
schemasState.hideField(schema, nested1, modified).subscribe();
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1);
expect(schema_1.fields[1].nested[0].isHidden).toBeTruthy();
expectToBeModified(schema_1);
});
it('should mark field disabled and update user info when field disabled', () => {
schemasService.setup(x => x.disableField(app, schema.name, field1.fieldId, undefined, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {})));
@ -380,6 +445,18 @@ describe('SchemasState', () => {
expectToBeModified(schema_1);
});
it('should mark field disabled and update user info when nested disabled', () => {
schemasService.setup(x => x.disableField(app, schema.name, nested1.fieldId, 2, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {})));
schemasState.disableField(schema, nested1, modified).subscribe();
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1);
expect(schema_1.fields[1].nested[0].isDisabled).toBeTruthy();
expectToBeModified(schema_1);
});
it('should mark field locked and update user info when field locked', () => {
schemasService.setup(x => x.lockField(app, schema.name, field1.fieldId, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {})));
@ -404,6 +481,18 @@ describe('SchemasState', () => {
expectToBeModified(schema_1);
});
it('should unmark field hidden and update user info when nested field shown', () => {
schemasService.setup(x => x.showField(app, schema.name, nested2.fieldId, 2, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {})));
schemasState.showField(schema, nested2, modified).subscribe();
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1);
expect(schema_1.fields[1].nested[1].isHidden).toBeFalsy();
expectToBeModified(schema_1);
});
it('should unmark field disabled and update user info when field enabled', () => {
schemasService.setup(x => x.enableField(app, schema.name, field2.fieldId, undefined, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {})));
@ -415,6 +504,18 @@ describe('SchemasState', () => {
expect(schema_1.fields[1].isDisabled).toBeFalsy();
expectToBeModified(schema_1);
});
it('should unmark field disabled and update user info when nested field enabled', () => {
schemasService.setup(x => x.enableField(app, schema.name, nested2.fieldId, 2, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {})));
schemasState.enableField(schema, nested2, modified).subscribe();
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1);
expect(schema_1.fields[1].nested[1].isDisabled).toBeFalsy();
expectToBeModified(schema_1);
});
});
function expectToBeModified(schema_1: SchemaDto) {

2
src/Squidex/app/shared/state/schemas.state.ts

@ -380,7 +380,7 @@ export class SchemasState extends State<Snapshot> {
.notify(this.dialogs);
}
public hideField(schema: SchemaDetailsDto, field: AnyFieldDto, parent?: RootFieldDto, now?: DateTime): Observable<any> {
public hideField(schema: SchemaDetailsDto, field: AnyFieldDto, now?: DateTime): Observable<any> {
return this.schemasService.hideField(this.appName, schema.name, field.fieldId, pidof(field), schema.version)
.do(dto => {
this.replaceField(schema, setHidden(field, true), dto.version, now);

Loading…
Cancel
Save