Browse Source

Use DateTime class.

Add tests around default values
pull/198/head
Derek Begnoche 8 years ago
parent
commit
eeef4c69f4
  1. 33
      src/Squidex/app/shared/services/schemas.service.spec.ts
  2. 6
      src/Squidex/app/shared/services/schemas.service.ts

33
src/Squidex/app/shared/services/schemas.service.spec.ts

@ -12,15 +12,18 @@ import {
AddFieldDto, AddFieldDto,
AnalyticsService, AnalyticsService,
ApiUrlConfig, ApiUrlConfig,
AssetsFieldPropertiesDto,
CreateSchemaDto, CreateSchemaDto,
createProperties, createProperties,
DateTime, DateTime,
DateTimeFieldPropertiesDto,
FieldDto, FieldDto,
LocalCacheService, LocalCacheService,
SchemaDetailsDto, SchemaDetailsDto,
SchemaDto, SchemaDto,
SchemaPropertiesDto, SchemaPropertiesDto,
SchemasService, SchemasService,
StringFieldPropertiesDto,
UpdateFieldDto, UpdateFieldDto,
UpdateSchemaDto, UpdateSchemaDto,
UpdateSchemaScriptsDto, UpdateSchemaScriptsDto,
@ -682,4 +685,34 @@ describe('SchemasService', () => {
req.flush({}); req.flush({});
})); }));
});
describe('FieldPropertiesDto', () => {
it('should return default value for StringFieldProperties', () => {
const dto = new StringFieldPropertiesDto(null, null, null, false, false, 'Input', 'Default Value');
expect(dto.getDefaultValue()).toEqual('Default Value');
});
it('should return default for DateFieldProperties', () => {
const now = DateTime.now();
const dto = new DateTimeFieldPropertiesDto(null, null, null, false, false, 'Input', now.toISOString());
expect(dto.getDefaultValue()).toEqual(now.toISOString());
});
it('should return calculated date when Today for DateFieldProperties', () => {
const now = DateTime.now().date;
const dto = new DateTimeFieldPropertiesDto(null, null, null, false, false, 'Input', null, null, null, 'Today');
expect(dto.getDefaultValue()).toEqual(now.toUTCStringFormat('ddd, DD MMM YYYY hh:mm:ss Z'));
});
it('should return calculated date when Now for DateFieldProperties', () => {
const now = DateTime.now();
const dto = new DateTimeFieldPropertiesDto(null, null, null, false, false, 'Input', null, null, null, 'Now');
expect(dto.getDefaultValue()).toEqual(now.toUTCStringFormat('ddd, DD MMM YYYY hh:mm:ss Z'));
});
it('should return null for default properties', () => {
const dto = new AssetsFieldPropertiesDto(null, null, null, false, false);
expect(dto.getDefaultValue()).toEqual(null);
});
}); });

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

@ -496,11 +496,11 @@ export class DateTimeFieldPropertiesDto extends FieldPropertiesDto {
public getDefaultValue(): any { public getDefaultValue(): any {
if (this.calculatedDefaultValue != null) { if (this.calculatedDefaultValue != null) {
let now = new Date(); let now = DateTime.now();
if (this.calculatedDefaultValue === 'Today') { if (this.calculatedDefaultValue === 'Today') {
now = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()); now = now.date;
} }
return now.toUTCString(); return now.toUTCStringFormat('ddd, DD MMM YYYY hh:mm:ss Z');
} }
return this.defaultValue; return this.defaultValue;
} }

Loading…
Cancel
Save