Browse Source

Bug with unique checkbox fixed. (#419)

pull/421/head
Sebastian Stehle 6 years ago
committed by GitHub
parent
commit
07328dfe21
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/Squidex/app/features/schemas/pages/schema/field-wizard.component.ts
  2. 2
      src/Squidex/app/features/schemas/pages/schema/field.component.ts
  3. 2
      src/Squidex/app/features/schemas/pages/schema/types/string-validation.component.html
  4. 6
      src/Squidex/app/shared/services/schemas.service.ts
  5. 179
      src/Squidex/app/shared/services/schemas.types.ts
  6. 86
      src/Squidex/app/shared/state/contents.forms.spec.ts

2
src/Squidex/app/features/schemas/pages/schema/field-wizard.component.ts

@ -94,7 +94,7 @@ export class FieldWizardComponent implements OnInit {
const value = this.editForm.submit();
if (value) {
const properties = createProperties(this.field.properties['fieldType'], value);
const properties = createProperties(this.field.properties.fieldType, value);
this.schemasState.updateField(this.schema, this.field as RootFieldDto, { properties })
.subscribe(() => {

2
src/Squidex/app/features/schemas/pages/schema/field.component.ts

@ -115,7 +115,7 @@ export class FieldComponent implements OnChanges {
const value = this.editForm.submit();
if (value) {
const properties = createProperties(this.field.properties['fieldType'], value);
const properties = createProperties(this.field.properties.fieldType, value);
this.schemasState.updateField(this.schema, this.field, { properties })
.subscribe(() => {

2
src/Squidex/app/features/schemas/pages/schema/types/string-validation.component.html

@ -1,5 +1,5 @@
<div [formGroup]="editForm">
<div class="form-group row" *ngIf="showUnique">
<div class="form-group row" [class.hidden]="!showUnique">
<div class="col-9 offset-3">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="{{field.fieldId}}_fieldUnique" formControlName="isUnique" />

6
src/Squidex/app/shared/services/schemas.service.ts

@ -222,12 +222,8 @@ export class RootFieldDto extends FieldDto {
return this.properties.fieldType === 'Array';
}
public get isString() {
return this.properties.fieldType === 'String';
}
public get isTranslatable() {
return this.isLocalizable && this.isString && (this.properties.editor === 'Input' || this.properties.editor === 'Textarea');
return this.isLocalizable && this.properties.isTranslateable;
}
constructor(links: ResourceLinks, fieldId: number, name: string, properties: FieldPropertiesDto,

179
src/Squidex/app/shared/services/schemas.types.ts

@ -62,42 +62,46 @@ export function createProperties(fieldType: FieldType, values?: any): FieldPrope
switch (fieldType) {
case 'Array':
properties = new ArrayFieldPropertiesDto(values);
properties = new ArrayFieldPropertiesDto();
break;
case 'Assets':
properties = new AssetsFieldPropertiesDto(values);
properties = new AssetsFieldPropertiesDto();
break;
case 'Boolean':
properties = new BooleanFieldPropertiesDto('Checkbox', values);
properties = new BooleanFieldPropertiesDto();
break;
case 'DateTime':
properties = new DateTimeFieldPropertiesDto('DateTime', values);
properties = new DateTimeFieldPropertiesDto();
break;
case 'Geolocation':
properties = new GeolocationFieldPropertiesDto(values);
properties = new GeolocationFieldPropertiesDto();
break;
case 'Json':
properties = new JsonFieldPropertiesDto(values);
properties = new JsonFieldPropertiesDto();
break;
case 'Number':
properties = new NumberFieldPropertiesDto('Input', values);
properties = new NumberFieldPropertiesDto();
break;
case 'References':
properties = new ReferencesFieldPropertiesDto('List', values);
properties = new ReferencesFieldPropertiesDto();
break;
case 'String':
properties = new StringFieldPropertiesDto('Input', values);
properties = new StringFieldPropertiesDto();
break;
case 'Tags':
properties = new TagsFieldPropertiesDto(values);
properties = new TagsFieldPropertiesDto();
break;
case 'UI':
properties = new UIFieldPropertiesDto(values);
properties = new UIFieldPropertiesDto();
break;
default:
throw 'Invalid properties type';
}
if (values) {
Object.assign(properties, values);
}
return properties;
}
@ -129,19 +133,15 @@ export abstract class FieldPropertiesDto {
public abstract fieldType: FieldType;
public readonly editorUrl?: string;
public readonly label?: string;
public readonly hints?: string;
public readonly placeholder?: string;
public readonly isRequired: boolean = false;
public readonly isListField: boolean = false;
public readonly isReferenceField: boolean = false;
public readonly isRequired: boolean = false;
public readonly label?: string;
public readonly placeholder?: string;
constructor(public readonly editor: string,
props?: Partial<FieldPropertiesDto>
) {
if (props) {
Object.assign(this, props);
}
public get isTranslateable() {
return false;
}
public get isComplexUI() {
@ -162,14 +162,8 @@ export abstract class FieldPropertiesDto {
export class ArrayFieldPropertiesDto extends FieldPropertiesDto {
public readonly fieldType = 'Array';
public readonly minItems?: number;
public readonly maxItems?: number;
constructor(
props?: Partial<ArrayFieldPropertiesDto>
) {
super('Default', props);
}
public readonly minItems?: number;
public accept<T>(visitor: FieldPropertiesVisitor<T>): T {
return visitor.visitArray(this);
@ -179,92 +173,78 @@ export class ArrayFieldPropertiesDto extends FieldPropertiesDto {
export class AssetsFieldPropertiesDto extends FieldPropertiesDto {
public readonly fieldType = 'Assets';
public readonly minItems?: number;
public readonly allowDuplicates?: boolean;
public readonly allowedExtensions?: string[];
public readonly aspectHeight?: number;
public readonly aspectWidth?: number;
public readonly maxHeight?: number;
public readonly maxItems?: number;
public readonly minSize?: number;
public readonly maxSize?: number;
public readonly allowedExtensions?: string[];
public readonly mustBeImage?: boolean;
public readonly minWidth?: number;
public readonly maxWidth?: number;
public readonly minHeight?: number;
public readonly maxHeight?: number;
public readonly aspectWidth?: number;
public readonly aspectHeight?: number;
public readonly allowDuplicates?: boolean;
public readonly minItems?: number;
public readonly minSize?: number;
public readonly minWidth?: number;
public readonly mustBeImage?: boolean;
public get isSortable() {
return false;
}
constructor(
props?: Partial<AssetsFieldPropertiesDto>
) {
super('Default', props);
}
public accept<T>(visitor: FieldPropertiesVisitor<T>): T {
return visitor.visitAssets(this);
}
}
export type BooleanFieldEditor = 'Checkbox' | 'Toggle';
export class BooleanFieldPropertiesDto extends FieldPropertiesDto {
public readonly fieldType = 'Boolean';
public readonly inlineEditable: boolean = false;
public readonly defaultValue?: boolean;
public readonly editor: BooleanFieldEditor = 'Checkbox';
public readonly inlineEditable: boolean = false;
public get isComplexUI() {
return false;
}
constructor(editor: string,
props?: Partial<BooleanFieldPropertiesDto>
) {
super(editor, props);
}
public accept<T>(visitor: FieldPropertiesVisitor<T>): T {
return visitor.visitBoolean(this);
}
}
export type DateTimeFieldEditor = 'DateTime' | 'Date';
export class DateTimeFieldPropertiesDto extends FieldPropertiesDto {
public readonly fieldType = 'DateTime';
public readonly calculatedDefaultValue?: string;
public readonly defaultValue?: string;
public readonly editor: DateTimeFieldEditor = 'DateTime';
public readonly maxValue?: string;
public readonly minValue?: string;
public readonly calculatedDefaultValue?: string;
public get isComplexUI() {
return false;
}
constructor(editor: string,
props?: Partial<DateTimeFieldPropertiesDto>
) {
super(editor, props);
}
public accept<T>(visitor: FieldPropertiesVisitor<T>): T {
return visitor.visitDateTime(this);
}
}
export type GeolocationFieldEditor = 'Map';
export class GeolocationFieldPropertiesDto extends FieldPropertiesDto {
public readonly fieldType = 'Geolocation';
public readonly editor: GeolocationFieldEditor = 'Map';
public get isSortable() {
return false;
}
constructor(
props?: Partial<GeolocationFieldPropertiesDto>
) {
super('Map', props);
}
public accept<T>(visitor: FieldPropertiesVisitor<T>): T {
return visitor.visitGeolocation(this);
}
@ -277,87 +257,75 @@ export class JsonFieldPropertiesDto extends FieldPropertiesDto {
return false;
}
constructor(
props?: Partial<JsonFieldPropertiesDto>
) {
super('Default', props);
}
public accept<T>(visitor: FieldPropertiesVisitor<T>): T {
return visitor.visitJson(this);
}
}
export type NumberFieldEditor = 'Input' | 'Radio' | 'Dropdown' | 'Stars';
export class NumberFieldPropertiesDto extends FieldPropertiesDto {
public readonly fieldType = 'Number';
public readonly allowedValues?: number[];
public readonly defaultValue?: number;
public readonly editor: NumberFieldEditor = 'Input';
public readonly inlineEditable: boolean = false;
public readonly isUnique: boolean = false;
public readonly defaultValue?: number;
public readonly maxValue?: number;
public readonly minValue?: number;
public readonly allowedValues?: number[];
public get isComplexUI() {
return false;
}
constructor(editor: string,
props?: Partial<NumberFieldPropertiesDto>
) {
super(editor, props);
}
public accept<T>(visitor: FieldPropertiesVisitor<T>): T {
return visitor.visitNumber(this);
}
}
export type ReferencesFieldEditor = 'List' | 'Dropdown';
export class ReferencesFieldPropertiesDto extends FieldPropertiesDto {
public readonly fieldType = 'References';
public readonly minItems?: number;
public readonly allowDuplicates?: boolean;
public readonly editor: ReferencesFieldEditor = 'List';
public readonly maxItems?: number;
public readonly editor: string;
public readonly schemaId?: string;
public readonly minItems?: number;
public readonly resolveReference?: boolean;
public readonly allowDuplicates?: boolean;
public readonly schemaId?: string;
public get isSortable() {
return false;
}
constructor(editor: string,
props?: Partial<ReferencesFieldPropertiesDto>
) {
super(editor, props);
}
public accept<T>(visitor: FieldPropertiesVisitor<T>): T {
return visitor.visitReferences(this);
}
}
export type StringEditor = 'Color' | 'Dropdown' | 'Html' | 'Input' | 'Markdown' | 'Radio' | 'RichText' | 'Slug' | 'TextArea';
export class StringFieldPropertiesDto extends FieldPropertiesDto {
public readonly fieldType = 'String';
public readonly inlineEditable = false;
public readonly isUnique: boolean = false;
public readonly allowedValues?: string[];
public readonly defaultValue?: string;
public readonly editor: StringEditor = 'Input';
public readonly inlineEditable: boolean = false;
public readonly isUnique: boolean = false;
public readonly maxLength?: number;
public readonly minLength?: number;
public readonly pattern?: string;
public readonly patternMessage?: string;
public readonly minLength?: number;
public readonly maxLength?: number;
public readonly allowedValues?: string[];
public get isComplexUI() {
return this.editor !== 'Input' && this.editor !== 'Color' && this.editor !== 'Radio' && this.editor !== 'Slug' && this.editor !== 'TextArea';
}
constructor(editor: string,
props?: Partial<StringFieldPropertiesDto>
) {
super(editor, props);
public get isTranslateable() {
return this.editor === 'Input' || this.editor === 'TextArea';
}
public accept<T>(visitor: FieldPropertiesVisitor<T>): T {
@ -365,12 +333,15 @@ export class StringFieldPropertiesDto extends FieldPropertiesDto {
}
}
export type TagsFieldEditor = 'Tags' | 'Checkboxes' | 'Dropdown';
export class TagsFieldPropertiesDto extends FieldPropertiesDto {
public readonly fieldType = 'Tags';
public readonly minItems?: number;
public readonly maxItems?: number;
public readonly allowedValues?: string[];
public readonly editor: TagsFieldEditor = 'Tags';
public readonly maxItems?: number;
public readonly minItems?: number;
public get isComplexUI() {
return false;
@ -380,12 +351,6 @@ export class TagsFieldPropertiesDto extends FieldPropertiesDto {
return false;
}
constructor(
props?: Partial<TagsFieldPropertiesDto>
) {
super('Tags', props);
}
public accept<T>(visitor: FieldPropertiesVisitor<T>): T {
return visitor.visitTags(this);
}
@ -394,6 +359,8 @@ export class TagsFieldPropertiesDto extends FieldPropertiesDto {
export class UIFieldPropertiesDto extends FieldPropertiesDto {
public readonly fieldType = 'UI';
public readonly editor = 'Separator';
public get isComplexUI() {
return false;
}
@ -406,12 +373,6 @@ export class UIFieldPropertiesDto extends FieldPropertiesDto {
return false;
}
constructor(
props?: Partial<TagsFieldPropertiesDto>
) {
super('Separator', props);
}
public accept<T>(visitor: FieldPropertiesVisitor<T>): T {
return visitor.visitUI(this);
}

86
src/Squidex/app/shared/state/contents.forms.spec.ts

@ -9,32 +9,22 @@ import { AbstractControl, FormArray } from '@angular/forms';
import {
AppLanguageDto,
ArrayFieldPropertiesDto,
AssetsFieldPropertiesDto,
BooleanFieldPropertiesDto,
createProperties,
DateTime,
DateTimeFieldPropertiesDto,
EditContentForm,
FieldDefaultValue,
FieldFormatter,
FieldPropertiesDto,
FieldsValidators,
GeolocationFieldPropertiesDto,
getContentValue,
HtmlValue,
ImmutableArray,
JsonFieldPropertiesDto,
LanguageDto,
NestedFieldDto,
NumberFieldPropertiesDto,
PartitionConfig,
ReferencesFieldPropertiesDto,
RootFieldDto,
SchemaDetailsDto,
SchemaPropertiesDto,
StringFieldPropertiesDto,
TagsFieldPropertiesDto,
Version
} from '@app/shared/internal';
@ -67,9 +57,9 @@ describe('SchemaDetailsDto', () => {
});
it('should return configured fields as list fields if no schema field are declared', () => {
const field1 = createField({ properties: new ArrayFieldPropertiesDto({ isListField: true }) });
const field2 = createField({ properties: new ArrayFieldPropertiesDto({ isListField: false }), id: 2 });
const field3 = createField({ properties: new ArrayFieldPropertiesDto({ isListField: true }), id: 3 });
const field1 = createField({ properties: createProperties('Array', { isListField: true }) });
const field2 = createField({ properties: createProperties('Array', { isListField: false }), id: 2 });
const field3 = createField({ properties: createProperties('Array', { isListField: true }), id: 3 });
const schema = createSchema({ properties: new SchemaPropertiesDto(''), fields: [field1, field2, field3] });
@ -77,9 +67,9 @@ describe('SchemaDetailsDto', () => {
});
it('should return first fields as list fields if no schema field is declared', () => {
const field1 = createField({ properties: new ArrayFieldPropertiesDto() });
const field2 = createField({ properties: new ArrayFieldPropertiesDto(), id: 2 });
const field3 = createField({ properties: new ArrayFieldPropertiesDto(), id: 3 });
const field1 = createField({ properties: createProperties('Array') });
const field2 = createField({ properties: createProperties('Array'), id: 2 });
const field3 = createField({ properties: createProperties('Array'), id: 3 });
const schema = createSchema({ properties: new SchemaPropertiesDto(''), fields: [field1, field2, field3] });
@ -95,50 +85,50 @@ describe('SchemaDetailsDto', () => {
describe('FieldDto', () => {
it('should return label as display name', () => {
const field = createField({ properties: new AssetsFieldPropertiesDto({ label: 'Label' }) });
const field = createField({ properties: createProperties('Array', { label: 'Label' }) });
expect(field.displayName).toBe('Label');
});
it('should return name as display name if label is null', () => {
const field = createField({ properties: new AssetsFieldPropertiesDto() });
const field = createField({ properties: createProperties('Assets') });
expect(field.displayName).toBe('field1');
});
it('should return name as display name label is empty', () => {
const field = createField({ properties: new AssetsFieldPropertiesDto({ label: '' }) });
const field = createField({ properties: createProperties('Assets', { label: '' }) });
expect(field.displayName).toBe('field1');
});
it('should return placeholder as display placeholder', () => {
const field = createField({ properties: new AssetsFieldPropertiesDto({ placeholder: 'Placeholder' }) });
const field = createField({ properties: createProperties('Assets', { placeholder: 'Placeholder' }) });
expect(field.displayPlaceholder).toBe('Placeholder');
});
it('should return empty as display placeholder if placeholder is null', () => {
const field = createField({ properties: new AssetsFieldPropertiesDto() });
const field = createField({ properties: createProperties('Assets') });
expect(field.displayPlaceholder).toBe('');
});
it('should return localizable if partitioning is language', () => {
const field = createField({ properties: new AssetsFieldPropertiesDto(), partitioning: 'language' });
const field = createField({ properties: createProperties('Assets'), partitioning: 'language' });
expect(field.isLocalizable).toBeTruthy();
});
it('should not return localizable if partitioning is invarient', () => {
const field = createField({ properties: new AssetsFieldPropertiesDto(), partitioning: 'invariant' });
const field = createField({ properties: createProperties('Assets'), partitioning: 'invariant' });
expect(field.isLocalizable).toBeFalsy();
});
});
describe('ArrayField', () => {
const field = createField({ properties: new ArrayFieldPropertiesDto({ isRequired: true, minItems: 1, maxItems: 5 }) });
const field = createField({ properties: createProperties('Array', { isRequired: true, minItems: 1, maxItems: 5 }) });
it('should create validators', () => {
expect(FieldsValidators.create(field, false).length).toBe(2);
@ -162,7 +152,7 @@ describe('ArrayField', () => {
});
describe('AssetsField', () => {
const field = createField({ properties: new AssetsFieldPropertiesDto({ isRequired: true, minItems: 1, maxItems: 5 }) });
const field = createField({ properties: createProperties('Assets', { isRequired: true, minItems: 1, maxItems: 5 }) });
it('should create validators', () => {
expect(FieldsValidators.create(field, false).length).toBe(3);
@ -186,7 +176,7 @@ describe('AssetsField', () => {
});
describe('TagsField', () => {
const field = createField({ properties: new TagsFieldPropertiesDto({ isRequired: true, minItems: 1, maxItems: 5 }) });
const field = createField({ properties: createProperties('Tags', { isRequired: true, minItems: 1, maxItems: 5 }) });
it('should create validators', () => {
expect(FieldsValidators.create(field, false).length).toBe(2);
@ -210,7 +200,7 @@ describe('TagsField', () => {
});
describe('BooleanField', () => {
const field = createField({ properties: new BooleanFieldPropertiesDto('Checkbox', { isRequired: true }) });
const field = createField({ properties: createProperties('Boolean', { editor: 'Checkbox', isRequired: true }) });
it('should create validators', () => {
expect(FieldsValidators.create(field, false).length).toBe(1);
@ -229,7 +219,7 @@ describe('BooleanField', () => {
});
it('should return default value for default properties', () => {
const field2 = createField({ properties: new BooleanFieldPropertiesDto('Checkbox', { defaultValue: true }) });
const field2 = createField({ properties: createProperties('Boolean', { editor: 'Checkbox', defaultValue: true }) });
expect(FieldDefaultValue.get(field2)).toBeTruthy();
});
@ -237,7 +227,7 @@ describe('BooleanField', () => {
describe('DateTimeField', () => {
const now = DateTime.parseISO_UTC('2017-10-12T16:30:10Z');
const field = createField({ properties: new DateTimeFieldPropertiesDto('DateTime', { isRequired: true }) });
const field = createField({ properties: createProperties('DateTime', { editor: 'DateTime', isRequired: true }) });
it('should create validators', () => {
expect(FieldsValidators.create(field, false).length).toBe(1);
@ -252,38 +242,38 @@ describe('DateTimeField', () => {
});
it('should format to date', () => {
const dateField = createField({ properties: new DateTimeFieldPropertiesDto('Date') });
const dateField = createField({ properties: createProperties('DateTime', { editor: 'Date' }) });
expect(FieldFormatter.format(dateField, '2017-12-12T16:00:00Z')).toBe('2017-12-12');
});
it('should format to date time', () => {
const field2 = createField({ properties: new DateTimeFieldPropertiesDto('DateTime') });
const field2 = createField({ properties: createProperties('DateTime', { editor: 'DateTime' }) });
expect(FieldFormatter.format(field2, '2017-12-12T16:00:00Z')).toBe('2017-12-12 16:00:00');
});
it('should return default for DateFieldProperties', () => {
const field2 = createField({ properties: new DateTimeFieldPropertiesDto('DateTime', { defaultValue: '2017-10-12T16:00:00Z' }) });
const field2 = createField({ properties: createProperties('DateTime', { editor: 'DateTime', defaultValue: '2017-10-12T16:00:00Z' }) });
expect(FieldDefaultValue.get(field2)).toEqual('2017-10-12T16:00:00Z');
});
it('should return calculated date when Today for DateFieldProperties', () => {
const field2 = createField({ properties: new DateTimeFieldPropertiesDto('DateTime', { calculatedDefaultValue: 'Today' }) });
const field2 = createField({ properties: createProperties('DateTime', { editor: 'DateTime', calculatedDefaultValue: 'Today' }) });
expect(FieldDefaultValue.get(field2, now)).toEqual('2017-10-12T00:00:00Z');
});
it('should return calculated date when Now for DateFieldProperties', () => {
const field2 = createField({ properties: new DateTimeFieldPropertiesDto('DateTime', { calculatedDefaultValue: 'Now' }) });
const field2 = createField({ properties: createProperties('DateTime', { editor: 'DateTime', calculatedDefaultValue: 'Now' }) });
expect(FieldDefaultValue.get(field2, now)).toEqual('2017-10-12T16:30:10Z');
});
});
describe('GeolocationField', () => {
const field = createField({ properties: new GeolocationFieldPropertiesDto({ isRequired: true }) });
const field = createField({ properties: createProperties('Geolocation', { isRequired: true }) });
it('should create validators', () => {
expect(FieldsValidators.create(field, false).length).toBe(1);
@ -303,7 +293,7 @@ describe('GeolocationField', () => {
});
describe('JsonField', () => {
const field = createField({ properties: new JsonFieldPropertiesDto({ isRequired: true }) });
const field = createField({ properties: createProperties('Json', { isRequired: true }) });
it('should create validators', () => {
expect(FieldsValidators.create(field, false).length).toBe(1);
@ -323,7 +313,7 @@ describe('JsonField', () => {
});
describe('NumberField', () => {
const field = createField({ properties: new NumberFieldPropertiesDto('Input', { isRequired: true, minValue: 1, maxValue: 6, allowedValues: [1, 3] }) });
const field = createField({ properties: createProperties('Number', { isRequired: true, minValue: 1, maxValue: 6, allowedValues: [1, 3] }) });
it('should create validators', () => {
expect(FieldsValidators.create(field, false).length).toBe(3);
@ -338,44 +328,44 @@ describe('NumberField', () => {
});
it('should format to stars if html allowed', () => {
const field2 = createField({ properties: new NumberFieldPropertiesDto('Stars') });
const field2 = createField({ properties: createProperties('Number', { editor: 'Stars' }) });
expect(FieldFormatter.format(field2, 3)).toEqual(new HtmlValue('&#9733; &#9733; &#9733; '));
});
it('should format to short star view for many stars', () => {
const field2 = createField({ properties: new NumberFieldPropertiesDto('Stars') });
const field2 = createField({ properties: createProperties('Number', { editor: 'Stars' }) });
expect(FieldFormatter.format(field2, 42)).toEqual(new HtmlValue('&#9733; 42'));
});
it('should format to short star view for no stars', () => {
const field2 = createField({ properties: new NumberFieldPropertiesDto('Stars') });
const field2 = createField({ properties: createProperties('Number', { editor: 'Stars' }) });
expect(FieldFormatter.format(field2, 0)).toEqual(new HtmlValue('&#9733; 0'));
});
it('should format to short star view for negative stars', () => {
const field2 = createField({ properties: new NumberFieldPropertiesDto('Stars') });
const field2 = createField({ properties: createProperties('Number', { editor: 'Stars' }) });
expect(FieldFormatter.format(field2, -13)).toEqual(new HtmlValue('&#9733; -13'));
});
it('should not format to stars if html not allowed', () => {
const field2 = createField({ properties: new NumberFieldPropertiesDto('Stars') });
const field2 = createField({ properties: createProperties('Number', { editor: 'Stars' }) });
expect(FieldFormatter.format(field2, 3, false)).toEqual('3');
});
it('should return default value for default properties', () => {
const field2 = createField({ properties: new NumberFieldPropertiesDto('Input', { defaultValue: 13 }) });
const field2 = createField({ properties: createProperties('Number', { defaultValue: 13 }) });
expect(FieldDefaultValue.get(field2)).toEqual(13);
});
});
describe('ReferencesField', () => {
const field = createField({ properties: new ReferencesFieldPropertiesDto('List', { isRequired: true, minItems: 1, maxItems: 5 }) });
const field = createField({ properties: createProperties('References', { editor: 'List', isRequired: true, minItems: 1, maxItems: 5 }) });
it('should create validators', () => {
expect(FieldsValidators.create(field, false).length).toBe(3);
@ -399,7 +389,7 @@ describe('ReferencesField', () => {
});
describe('StringField', () => {
const field = createField({ properties: new StringFieldPropertiesDto('Input', { isRequired: true, pattern: 'pattern', minLength: 1, maxLength: 5, allowedValues: ['a', 'b'] }) });
const field = createField({ properties: createProperties('String', { isRequired: true, pattern: 'pattern', minLength: 1, maxLength: 5, allowedValues: ['a', 'b'] }) });
it('should create validators', () => {
expect(FieldsValidators.create(field, false).length).toBe(4);
@ -414,7 +404,7 @@ describe('StringField', () => {
});
it('should return default value for default properties', () => {
const field2 = createField({ properties: new StringFieldPropertiesDto('Input', { defaultValue: 'MyDefault' }) });
const field2 = createField({ properties: createProperties('String', { defaultValue: 'MyDefault' }) });
expect(FieldDefaultValue.get(field2)).toEqual('MyDefault');
});
@ -422,8 +412,8 @@ describe('StringField', () => {
describe('GetContentValue', () => {
const language = new LanguageDto('en', 'English');
const fieldInvariant = createField({ properties: new NumberFieldPropertiesDto('Input'), partitioning: 'invariant' });
const fieldLocalized = createField({ properties: new NumberFieldPropertiesDto('Input') });
const fieldInvariant = createField({ properties: createProperties('Number'), partitioning: 'invariant' });
const fieldLocalized = createField({ properties: createProperties('Number') });
it('should resolve invariant field from references value', () => {
const content: any = {

Loading…
Cancel
Save