From 642845587386af39d367eb687acd3f7162202e17 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Thu, 2 Jul 2020 16:05:57 -0700 Subject: [PATCH] add more to tests - need help though --- .../field_formats_registry.test.ts | 18 ++++++++++++++ .../field_formats_service.test.ts | 24 +++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/plugins/data/common/field_formats/field_formats_registry.test.ts b/src/plugins/data/common/field_formats/field_formats_registry.test.ts index f04524505a711b..162c9eefe00438 100644 --- a/src/plugins/data/common/field_formats/field_formats_registry.test.ts +++ b/src/plugins/data/common/field_formats/field_formats_registry.test.ts @@ -163,4 +163,22 @@ describe('FieldFormatsRegistry', () => { expect(params).toHaveProperty('parsedUrl'); }); }); + + describe('setCustomParams', () => { + test('should provide custom setting to formatters: timezone', () => { + fieldFormatsRegistry = new FieldFormatsRegistry(); + fieldFormatsRegistry.init( + getConfig, + { + parsedUrl: { + origin: '', + pathname: '', + basePath: '', + }, + }, + [] + ); + fieldFormatsRegistry.setCustomParams({ timezone: 'America/New_York' }); + }); + }); }); diff --git a/src/plugins/data/server/field_formats/field_formats_service.test.ts b/src/plugins/data/server/field_formats/field_formats_service.test.ts index 2e7ce0fa435a76..4124d81f885b56 100644 --- a/src/plugins/data/server/field_formats/field_formats_service.test.ts +++ b/src/plugins/data/server/field_formats/field_formats_service.test.ts @@ -17,9 +17,10 @@ * under the License. */ -import { FieldFormatsService } from './field_formats_service'; -import { DateFormat } from './converters/date_server'; import { coreMock } from '../../../../core/server/mocks'; +import { FIELD_FORMAT_IDS } from '../../common'; +import { DateFormat } from './converters/date_server'; +import { FieldFormatsService } from './field_formats_service'; describe('FieldFormatService', () => { test('DateFormat is server version', async () => { @@ -32,3 +33,22 @@ describe('FieldFormatService', () => { expect(DateFormatFromRegsitry).toEqual(DateFormat); }); }); + +describe('DateFormat with custom timezone', () => { + test('should provide custom setting to formatters: timezone', async () => { + const service = new FieldFormatsService(); + const fieldFormatsService = await service.start(); + const uiSettings = coreMock.createStart().uiSettings.asScopedToClient({} as any); + const fieldFormatsRegistry = await fieldFormatsService.fieldFormatServiceFactory(uiSettings); + + fieldFormatsRegistry.setCustomParams({ timezone: 'America/Phoenix' }); // set the timezone into the registry + + const fieldFormats = fieldFormatsRegistry.getByFieldType(FIELD_FORMAT_IDS.DATE as any); + const DateFormatInstance = fieldFormats.find((F) => F.id === 'date'); + expect(DateFormatInstance).toBeDefined(); + if (DateFormatInstance) { + const formatter = new DateFormatInstance(); + // how to call the formatter? + } + }); +});